plugin-document-understanding 1.1.14 → 1.1.16

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.
Files changed (132) hide show
  1. package/README.md +29 -29
  2. package/client-v2.d.ts +2 -2
  3. package/client-v2.js +1 -1
  4. package/dist/client/{345.e6e484fb1974c3d3.js → 345.277fbb2b97424db5.js} +1 -1
  5. package/dist/client/index.js +1 -1
  6. package/dist/client-v2/{345.a8f28526ac21e02a.js → 345.2fa9834b46dd4531.js} +1 -1
  7. package/dist/client-v2/index.js +1 -1
  8. package/dist/externalVersion.js +8 -7
  9. package/dist/locale/en-US.json +3 -1
  10. package/dist/locale/zh-CN.json +3 -1
  11. package/dist/node_modules/form-data/lib/form_data.js +2 -2
  12. package/dist/node_modules/form-data/node_modules/es-define-property/.eslintrc +13 -0
  13. package/dist/node_modules/form-data/node_modules/es-define-property/.github/FUNDING.yml +12 -0
  14. package/dist/node_modules/form-data/node_modules/es-define-property/.nycrc +9 -0
  15. package/dist/node_modules/form-data/node_modules/es-define-property/index.d.ts +3 -0
  16. package/dist/node_modules/form-data/node_modules/es-define-property/index.js +14 -0
  17. package/dist/node_modules/form-data/node_modules/es-define-property/package.json +81 -0
  18. package/dist/node_modules/form-data/node_modules/es-define-property/test/index.js +56 -0
  19. package/dist/node_modules/form-data/node_modules/es-object-atoms/.eslintrc +16 -0
  20. package/dist/node_modules/form-data/node_modules/es-object-atoms/.github/FUNDING.yml +12 -0
  21. package/dist/node_modules/form-data/node_modules/es-object-atoms/RequireObjectCoercible.d.ts +3 -0
  22. package/dist/node_modules/form-data/node_modules/es-object-atoms/RequireObjectCoercible.js +11 -0
  23. package/dist/node_modules/form-data/node_modules/es-object-atoms/ToObject.d.ts +7 -0
  24. package/dist/node_modules/form-data/node_modules/es-object-atoms/ToObject.js +10 -0
  25. package/dist/node_modules/form-data/node_modules/es-object-atoms/index.d.ts +3 -0
  26. package/dist/node_modules/form-data/node_modules/es-object-atoms/index.js +4 -0
  27. package/dist/node_modules/form-data/node_modules/es-object-atoms/isObject.d.ts +3 -0
  28. package/dist/node_modules/form-data/node_modules/es-object-atoms/isObject.js +6 -0
  29. package/dist/node_modules/form-data/node_modules/es-object-atoms/package.json +80 -0
  30. package/dist/node_modules/form-data/node_modules/es-object-atoms/test/index.js +38 -0
  31. package/dist/node_modules/form-data/node_modules/es-set-tostringtag/.eslintrc +13 -0
  32. package/dist/node_modules/form-data/node_modules/es-set-tostringtag/.nycrc +9 -0
  33. package/dist/node_modules/form-data/node_modules/es-set-tostringtag/index.d.ts +10 -0
  34. package/dist/node_modules/form-data/node_modules/es-set-tostringtag/index.js +35 -0
  35. package/dist/node_modules/form-data/node_modules/es-set-tostringtag/node_modules/hasown/.eslintrc +5 -0
  36. package/dist/node_modules/form-data/node_modules/es-set-tostringtag/node_modules/hasown/.github/FUNDING.yml +12 -0
  37. package/dist/node_modules/form-data/node_modules/es-set-tostringtag/node_modules/hasown/.nycrc +13 -0
  38. package/dist/node_modules/form-data/node_modules/es-set-tostringtag/node_modules/hasown/index.d.ts +3 -0
  39. package/dist/node_modules/form-data/node_modules/es-set-tostringtag/node_modules/hasown/index.js +8 -0
  40. package/dist/node_modules/form-data/node_modules/es-set-tostringtag/node_modules/hasown/package.json +92 -0
  41. package/dist/node_modules/form-data/node_modules/es-set-tostringtag/package.json +78 -0
  42. package/dist/node_modules/form-data/node_modules/es-set-tostringtag/test/index.js +85 -0
  43. package/dist/node_modules/form-data/node_modules/get-intrinsic/.eslintrc +42 -0
  44. package/dist/node_modules/form-data/node_modules/get-intrinsic/.github/FUNDING.yml +12 -0
  45. package/dist/node_modules/form-data/node_modules/get-intrinsic/.nycrc +9 -0
  46. package/dist/node_modules/form-data/node_modules/get-intrinsic/index.js +378 -0
  47. package/dist/node_modules/form-data/node_modules/get-intrinsic/node_modules/has-symbols/.eslintrc +11 -0
  48. package/dist/node_modules/form-data/node_modules/get-intrinsic/node_modules/has-symbols/.github/FUNDING.yml +12 -0
  49. package/dist/node_modules/form-data/node_modules/get-intrinsic/node_modules/has-symbols/.nycrc +9 -0
  50. package/dist/node_modules/form-data/node_modules/get-intrinsic/node_modules/has-symbols/index.d.ts +3 -0
  51. package/dist/node_modules/form-data/node_modules/get-intrinsic/node_modules/has-symbols/index.js +14 -0
  52. package/dist/node_modules/form-data/node_modules/get-intrinsic/node_modules/has-symbols/package.json +111 -0
  53. package/dist/node_modules/form-data/node_modules/get-intrinsic/node_modules/has-symbols/shams.d.ts +3 -0
  54. package/dist/node_modules/form-data/node_modules/get-intrinsic/node_modules/has-symbols/shams.js +45 -0
  55. package/dist/node_modules/form-data/node_modules/get-intrinsic/node_modules/has-symbols/test/index.js +22 -0
  56. package/dist/node_modules/form-data/node_modules/get-intrinsic/node_modules/has-symbols/test/shams/core-js.js +29 -0
  57. package/dist/node_modules/form-data/node_modules/get-intrinsic/node_modules/has-symbols/test/shams/get-own-property-symbols.js +29 -0
  58. package/dist/node_modules/form-data/node_modules/get-intrinsic/node_modules/has-symbols/test/tests.js +58 -0
  59. package/dist/node_modules/form-data/node_modules/get-intrinsic/node_modules/hasown/.eslintrc +5 -0
  60. package/dist/node_modules/form-data/node_modules/get-intrinsic/node_modules/hasown/.github/FUNDING.yml +12 -0
  61. package/dist/node_modules/form-data/node_modules/get-intrinsic/node_modules/hasown/.nycrc +13 -0
  62. package/dist/node_modules/form-data/node_modules/get-intrinsic/node_modules/hasown/index.d.ts +3 -0
  63. package/dist/node_modules/form-data/node_modules/get-intrinsic/node_modules/hasown/index.js +8 -0
  64. package/dist/node_modules/form-data/node_modules/get-intrinsic/node_modules/hasown/package.json +92 -0
  65. package/dist/node_modules/form-data/node_modules/get-intrinsic/package.json +97 -0
  66. package/dist/node_modules/form-data/node_modules/get-intrinsic/test/GetIntrinsic.js +274 -0
  67. package/dist/node_modules/form-data/node_modules/gopd/.eslintrc +16 -0
  68. package/dist/node_modules/form-data/node_modules/gopd/.github/FUNDING.yml +12 -0
  69. package/dist/node_modules/form-data/node_modules/gopd/gOPD.d.ts +1 -0
  70. package/dist/node_modules/form-data/node_modules/gopd/gOPD.js +4 -0
  71. package/dist/node_modules/form-data/node_modules/gopd/index.d.ts +5 -0
  72. package/dist/node_modules/form-data/node_modules/gopd/index.js +15 -0
  73. package/dist/node_modules/form-data/node_modules/gopd/package.json +77 -0
  74. package/dist/node_modules/form-data/node_modules/gopd/test/index.js +36 -0
  75. package/dist/node_modules/form-data/node_modules/has-tostringtag/.eslintrc +5 -0
  76. package/dist/node_modules/form-data/node_modules/has-tostringtag/.github/FUNDING.yml +12 -0
  77. package/dist/node_modules/form-data/node_modules/has-tostringtag/.nycrc +13 -0
  78. package/dist/node_modules/form-data/node_modules/has-tostringtag/index.d.ts +3 -0
  79. package/dist/node_modules/form-data/node_modules/has-tostringtag/index.js +8 -0
  80. package/dist/node_modules/form-data/node_modules/has-tostringtag/package.json +108 -0
  81. package/dist/node_modules/form-data/node_modules/has-tostringtag/shams.d.ts +3 -0
  82. package/dist/node_modules/form-data/node_modules/has-tostringtag/shams.js +8 -0
  83. package/dist/node_modules/form-data/node_modules/has-tostringtag/test/index.js +21 -0
  84. package/dist/node_modules/form-data/node_modules/has-tostringtag/test/shams/core-js.js +31 -0
  85. package/dist/node_modules/form-data/node_modules/has-tostringtag/test/shams/get-own-property-symbols.js +30 -0
  86. package/dist/node_modules/form-data/node_modules/has-tostringtag/test/tests.js +15 -0
  87. package/dist/node_modules/form-data/node_modules/hasown/.github/FUNDING.yml +12 -0
  88. package/dist/node_modules/form-data/node_modules/hasown/.nycrc +13 -0
  89. package/dist/node_modules/form-data/node_modules/hasown/index.d.ts +3 -0
  90. package/dist/node_modules/form-data/node_modules/hasown/index.js +8 -0
  91. package/dist/node_modules/form-data/node_modules/hasown/package.json +91 -0
  92. package/dist/node_modules/form-data/package.json +1 -1
  93. package/dist/node_modules/mime-types/index.js +3 -3
  94. package/dist/node_modules/mime-types/package.json +1 -1
  95. package/dist/server/actions.js +45 -35
  96. package/package.json +57 -46
  97. package/src/client/index.tsx +15 -15
  98. package/src/client-v2/components/EndpointsTab.tsx +578 -578
  99. package/src/client-v2/components/JobsTab.tsx +294 -294
  100. package/src/client-v2/components/PipelinesTab.tsx +962 -962
  101. package/src/client-v2/components/PluginSettings.tsx +54 -50
  102. package/src/client-v2/components/ServiceConfigTab.tsx +139 -139
  103. package/src/client-v2/components/__tests__/PluginSettings.test.tsx +39 -0
  104. package/src/client-v2/index.tsx +1 -1
  105. package/src/client-v2/locale.ts +21 -21
  106. package/src/client-v2/models/index.ts +12 -12
  107. package/src/client-v2/plugin.tsx +31 -21
  108. package/src/client-v2/types.ts +32 -32
  109. package/src/index.ts +2 -2
  110. package/src/locale/en-US.json +3 -1
  111. package/src/locale/zh-CN.json +3 -1
  112. package/src/server/__tests__/actions.test.ts +121 -98
  113. package/src/server/__tests__/cluster-safety.test.ts +259 -259
  114. package/src/server/__tests__/document-understanding-service.test.ts +82 -82
  115. package/src/server/__tests__/dugate-integration.test.ts +221 -221
  116. package/src/server/__tests__/smoke.test.ts +78 -55
  117. package/src/server/__tests__/upload-security.test.ts +128 -0
  118. package/src/server/actions.ts +53 -51
  119. package/src/server/collections/config.ts +18 -18
  120. package/src/server/collections/endpoints.ts +33 -33
  121. package/src/server/collections/jobs.ts +42 -42
  122. package/src/server/collections/pipeline-steps.ts +27 -27
  123. package/src/server/collections/pipelines.ts +19 -19
  124. package/src/server/dugate-seed.ts +491 -491
  125. package/src/server/index.ts +1 -1
  126. package/src/server/plugin.ts +143 -143
  127. package/src/server/services/AsyncJobManager.ts +238 -238
  128. package/src/server/services/DocumentUnderstandingService.ts +332 -332
  129. package/src/server/services/ExternalApiClient.ts +178 -178
  130. package/src/server/services/PipelineExecutor.ts +593 -593
  131. package/src/server/tools/document-understanding-tool.ts +181 -181
  132. package/src/server/types.ts +90 -90
@@ -1,178 +1,178 @@
1
- import axios, { AxiosInstance, AxiosResponse } from 'axios';
2
- import { ServiceConfig, EndpointDef } from '../types';
3
- import FormData from 'form-data';
4
-
5
- export interface FileInput {
6
- fieldName: string;
7
- buffer: Buffer;
8
- filename: string;
9
- mimeType: string;
10
- }
11
-
12
- export interface ApiCallOptions {
13
- endpoint: EndpointDef;
14
- body?: Record<string, any>;
15
- files?: FileInput[];
16
- overrideHeaders?: Record<string, string>;
17
- }
18
-
19
- export class ExternalApiClient {
20
- private config: ServiceConfig;
21
- private client: AxiosInstance;
22
- private static readonly HEADER_NAME_RE = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
23
-
24
- constructor(config: ServiceConfig) {
25
- this.config = config;
26
- this.client = axios.create({
27
- baseURL: config.baseUrl,
28
- timeout: config.defaultTimeout,
29
- });
30
- }
31
-
32
- private buildAuthHeaders(): Record<string, string> {
33
- const headers: Record<string, string> = {};
34
- if (!this.config.authType || this.config.authType === 'none') {
35
- return headers;
36
- }
37
-
38
- if (this.config.authType === 'bearer' && this.config.authKey) {
39
- headers['Authorization'] = `Bearer ${this.config.authKey}`;
40
- } else if (this.config.authType === 'api_key' && this.config.authKey) {
41
- // Assuming api_key is sent in Authorization header or x-api-key based on common patterns.
42
- // Usually authHeaderName handles custom API keys, but we'll default to x-api-key if not provided.
43
- const name = this.config.authHeaderName || 'x-api-key';
44
- headers[name] = this.config.authKey;
45
- } else if (this.config.authType === 'custom_header' && this.config.authHeaderName && this.config.authKey) {
46
- headers[this.config.authHeaderName] = this.config.authKey;
47
- }
48
-
49
- return headers;
50
- }
51
-
52
- private sanitizeHeaders(headers?: Record<string, any>): Record<string, string> {
53
- const normalized: Record<string, string> = {};
54
- if (!headers || typeof headers !== 'object' || Array.isArray(headers)) {
55
- return normalized;
56
- }
57
-
58
- for (const [rawName, rawValue] of Object.entries(headers)) {
59
- const name = rawName.trim();
60
- if (!name) continue;
61
- if (!ExternalApiClient.HEADER_NAME_RE.test(name)) {
62
- throw new Error(`Invalid HTTP header name: ${rawName}`);
63
- }
64
- if (rawValue === undefined || rawValue === null) continue;
65
- normalized[name] = String(rawValue);
66
- }
67
- return normalized;
68
- }
69
-
70
- /**
71
- * Appends the endpoint discriminator (if configured) to the request body so
72
- * DUGate-style gateways can route to the correct sub-case/profile.
73
- */
74
- private withDiscriminator(endpoint: EndpointDef, body?: Record<string, any>): Record<string, any> | undefined {
75
- const field = endpoint.discriminatorField?.trim();
76
- if (!field || !endpoint.discriminatorValue) {
77
- return body;
78
- }
79
- const merged: Record<string, any> = { ...(body || {}) };
80
- if (merged[field] !== undefined && merged[field] !== endpoint.discriminatorValue) {
81
- throw new Error(
82
- `Discriminator field '${field}' is locked by endpoint configuration (expected '${endpoint.discriminatorValue}', got '${merged[field]}').`,
83
- );
84
- }
85
- merged[field] = endpoint.discriminatorValue;
86
- return merged;
87
- }
88
-
89
- /**
90
- * Appends the DUGate sync flag (?sync=true) for endpoints configured with
91
- * `syncQueryParam`. Kept separate from other query parameters so GET/DELETE
92
- * params in `body` are not polluted by the discriminator logic.
93
- */
94
- private syncQueryParams(endpoint: EndpointDef): Record<string, string> {
95
- const param = endpoint.syncQueryParam?.trim();
96
- if (!param) return {};
97
- return { [param]: 'true' };
98
- }
99
-
100
- async call(options: ApiCallOptions): Promise<{ status: number; data: any; headers: any }> {
101
- const { endpoint, body, files, overrideHeaders } = options;
102
-
103
- const url = endpoint.subpath;
104
- const method = endpoint.method.toLowerCase();
105
-
106
- let requestData: any = body;
107
- let headers: Record<string, string> = {
108
- ...this.sanitizeHeaders(this.buildAuthHeaders()),
109
- ...this.sanitizeHeaders(endpoint.customHeaders),
110
- ...this.sanitizeHeaders(overrideHeaders),
111
- };
112
-
113
- if (endpoint.fileInputMode === 'multipart' && files && files.length > 0) {
114
- const formData = new FormData();
115
- const bodyWithDiscriminator = this.withDiscriminator(endpoint, body);
116
- if (bodyWithDiscriminator) {
117
- for (const [key, value] of Object.entries(bodyWithDiscriminator)) {
118
- formData.append(key, typeof value === 'object' ? JSON.stringify(value) : String(value));
119
- }
120
- }
121
- for (const file of files) {
122
- formData.append(file.fieldName, file.buffer, {
123
- filename: file.filename,
124
- contentType: file.mimeType,
125
- });
126
- }
127
- requestData = formData;
128
- headers = { ...headers, ...formData.getHeaders() };
129
- } else if (endpoint.fileInputMode === 'base64' && files && files.length > 0) {
130
- // Place base64 files under their fieldName keys within the body.
131
- // PipelineExecutor's inputMapping should map $files[n].base64 to the correct body path.
132
- // Here we nest them under a `_files` key to avoid overwriting body fields.
133
- const base64Files: Record<string, { data: string; filename: string; mimeType: string }> = {};
134
- for (const f of files) {
135
- base64Files[f.fieldName] = {
136
- data: f.buffer.toString('base64'),
137
- filename: f.filename,
138
- mimeType: f.mimeType,
139
- };
140
- }
141
- requestData = { ...this.withDiscriminator(endpoint, body), _files: base64Files };
142
- headers['Content-Type'] = 'application/json';
143
- } else {
144
- requestData = this.withDiscriminator(endpoint, body);
145
- headers['Content-Type'] = 'application/json';
146
- }
147
-
148
- try {
149
- const isBodyless = ['get', 'delete'].includes(method);
150
- const response: AxiosResponse = await this.client.request({
151
- url,
152
- method,
153
- data: isBodyless ? undefined : requestData,
154
- params: isBodyless
155
- ? { ...(requestData || {}), ...this.syncQueryParams(endpoint) }
156
- : this.syncQueryParams(endpoint),
157
- headers,
158
- });
159
-
160
- return {
161
- status: response.status,
162
- data: response.data,
163
- headers: response.headers,
164
- };
165
- } catch (error: any) {
166
- if (error.response) {
167
- throw new Error(`API Error [${error.response.status}]: ${JSON.stringify(error.response.data)}`);
168
- }
169
- throw error;
170
- }
171
- }
172
-
173
- async get(url: string, overrideHeaders?: Record<string, string>): Promise<any> {
174
- const headers = { ...this.buildAuthHeaders(), ...(overrideHeaders || {}) };
175
- const response = await this.client.get(url, { headers });
176
- return response.data;
177
- }
178
- }
1
+ import axios, { AxiosInstance, AxiosResponse } from 'axios';
2
+ import { ServiceConfig, EndpointDef } from '../types';
3
+ import FormData from 'form-data';
4
+
5
+ export interface FileInput {
6
+ fieldName: string;
7
+ buffer: Buffer;
8
+ filename: string;
9
+ mimeType: string;
10
+ }
11
+
12
+ export interface ApiCallOptions {
13
+ endpoint: EndpointDef;
14
+ body?: Record<string, any>;
15
+ files?: FileInput[];
16
+ overrideHeaders?: Record<string, string>;
17
+ }
18
+
19
+ export class ExternalApiClient {
20
+ private config: ServiceConfig;
21
+ private client: AxiosInstance;
22
+ private static readonly HEADER_NAME_RE = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
23
+
24
+ constructor(config: ServiceConfig) {
25
+ this.config = config;
26
+ this.client = axios.create({
27
+ baseURL: config.baseUrl,
28
+ timeout: config.defaultTimeout,
29
+ });
30
+ }
31
+
32
+ private buildAuthHeaders(): Record<string, string> {
33
+ const headers: Record<string, string> = {};
34
+ if (!this.config.authType || this.config.authType === 'none') {
35
+ return headers;
36
+ }
37
+
38
+ if (this.config.authType === 'bearer' && this.config.authKey) {
39
+ headers['Authorization'] = `Bearer ${this.config.authKey}`;
40
+ } else if (this.config.authType === 'api_key' && this.config.authKey) {
41
+ // Assuming api_key is sent in Authorization header or x-api-key based on common patterns.
42
+ // Usually authHeaderName handles custom API keys, but we'll default to x-api-key if not provided.
43
+ const name = this.config.authHeaderName || 'x-api-key';
44
+ headers[name] = this.config.authKey;
45
+ } else if (this.config.authType === 'custom_header' && this.config.authHeaderName && this.config.authKey) {
46
+ headers[this.config.authHeaderName] = this.config.authKey;
47
+ }
48
+
49
+ return headers;
50
+ }
51
+
52
+ private sanitizeHeaders(headers?: Record<string, any>): Record<string, string> {
53
+ const normalized: Record<string, string> = {};
54
+ if (!headers || typeof headers !== 'object' || Array.isArray(headers)) {
55
+ return normalized;
56
+ }
57
+
58
+ for (const [rawName, rawValue] of Object.entries(headers)) {
59
+ const name = rawName.trim();
60
+ if (!name) continue;
61
+ if (!ExternalApiClient.HEADER_NAME_RE.test(name)) {
62
+ throw new Error(`Invalid HTTP header name: ${rawName}`);
63
+ }
64
+ if (rawValue === undefined || rawValue === null) continue;
65
+ normalized[name] = String(rawValue);
66
+ }
67
+ return normalized;
68
+ }
69
+
70
+ /**
71
+ * Appends the endpoint discriminator (if configured) to the request body so
72
+ * DUGate-style gateways can route to the correct sub-case/profile.
73
+ */
74
+ private withDiscriminator(endpoint: EndpointDef, body?: Record<string, any>): Record<string, any> | undefined {
75
+ const field = endpoint.discriminatorField?.trim();
76
+ if (!field || !endpoint.discriminatorValue) {
77
+ return body;
78
+ }
79
+ const merged: Record<string, any> = { ...(body || {}) };
80
+ if (merged[field] !== undefined && merged[field] !== endpoint.discriminatorValue) {
81
+ throw new Error(
82
+ `Discriminator field '${field}' is locked by endpoint configuration (expected '${endpoint.discriminatorValue}', got '${merged[field]}').`,
83
+ );
84
+ }
85
+ merged[field] = endpoint.discriminatorValue;
86
+ return merged;
87
+ }
88
+
89
+ /**
90
+ * Appends the DUGate sync flag (?sync=true) for endpoints configured with
91
+ * `syncQueryParam`. Kept separate from other query parameters so GET/DELETE
92
+ * params in `body` are not polluted by the discriminator logic.
93
+ */
94
+ private syncQueryParams(endpoint: EndpointDef): Record<string, string> {
95
+ const param = endpoint.syncQueryParam?.trim();
96
+ if (!param) return {};
97
+ return { [param]: 'true' };
98
+ }
99
+
100
+ async call(options: ApiCallOptions): Promise<{ status: number; data: any; headers: any }> {
101
+ const { endpoint, body, files, overrideHeaders } = options;
102
+
103
+ const url = endpoint.subpath;
104
+ const method = endpoint.method.toLowerCase();
105
+
106
+ let requestData: any = body;
107
+ let headers: Record<string, string> = {
108
+ ...this.sanitizeHeaders(this.buildAuthHeaders()),
109
+ ...this.sanitizeHeaders(endpoint.customHeaders),
110
+ ...this.sanitizeHeaders(overrideHeaders),
111
+ };
112
+
113
+ if (endpoint.fileInputMode === 'multipart' && files && files.length > 0) {
114
+ const formData = new FormData();
115
+ const bodyWithDiscriminator = this.withDiscriminator(endpoint, body);
116
+ if (bodyWithDiscriminator) {
117
+ for (const [key, value] of Object.entries(bodyWithDiscriminator)) {
118
+ formData.append(key, typeof value === 'object' ? JSON.stringify(value) : String(value));
119
+ }
120
+ }
121
+ for (const file of files) {
122
+ formData.append(file.fieldName, file.buffer, {
123
+ filename: file.filename,
124
+ contentType: file.mimeType,
125
+ });
126
+ }
127
+ requestData = formData;
128
+ headers = { ...headers, ...formData.getHeaders() };
129
+ } else if (endpoint.fileInputMode === 'base64' && files && files.length > 0) {
130
+ // Place base64 files under their fieldName keys within the body.
131
+ // PipelineExecutor's inputMapping should map $files[n].base64 to the correct body path.
132
+ // Here we nest them under a `_files` key to avoid overwriting body fields.
133
+ const base64Files: Record<string, { data: string; filename: string; mimeType: string }> = {};
134
+ for (const f of files) {
135
+ base64Files[f.fieldName] = {
136
+ data: f.buffer.toString('base64'),
137
+ filename: f.filename,
138
+ mimeType: f.mimeType,
139
+ };
140
+ }
141
+ requestData = { ...this.withDiscriminator(endpoint, body), _files: base64Files };
142
+ headers['Content-Type'] = 'application/json';
143
+ } else {
144
+ requestData = this.withDiscriminator(endpoint, body);
145
+ headers['Content-Type'] = 'application/json';
146
+ }
147
+
148
+ try {
149
+ const isBodyless = ['get', 'delete'].includes(method);
150
+ const response: AxiosResponse = await this.client.request({
151
+ url,
152
+ method,
153
+ data: isBodyless ? undefined : requestData,
154
+ params: isBodyless
155
+ ? { ...(requestData || {}), ...this.syncQueryParams(endpoint) }
156
+ : this.syncQueryParams(endpoint),
157
+ headers,
158
+ });
159
+
160
+ return {
161
+ status: response.status,
162
+ data: response.data,
163
+ headers: response.headers,
164
+ };
165
+ } catch (error: any) {
166
+ if (error.response) {
167
+ throw new Error(`API Error [${error.response.status}]: ${JSON.stringify(error.response.data)}`);
168
+ }
169
+ throw error;
170
+ }
171
+ }
172
+
173
+ async get(url: string, overrideHeaders?: Record<string, string>): Promise<any> {
174
+ const headers = { ...this.buildAuthHeaders(), ...(overrideHeaders || {}) };
175
+ const response = await this.client.get(url, { headers });
176
+ return response.data;
177
+ }
178
+ }