dalux-build-api 2.0.1 → 2.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dalux-build-api",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "Node.js client for the Dalux Build API",
5
5
  "main": "src/index.js",
6
6
  "exports": {
@@ -20,11 +20,13 @@ class FileRevisionsApi {
20
20
  * @param {string} fileRevisionId
21
21
  * @returns {Promise<Buffer>} Raw binary content
22
22
  */
23
- getFileRevisionContent(projectId, fileAreaId, fileId, fileRevisionId) {
24
- return this._client.get(
23
+ async getFileRevisionContent(projectId, fileAreaId, fileId, fileRevisionId) {
24
+ const data = await this._client.get(
25
25
  `/2.0/projects/${projectId}/file_areas/${fileAreaId}/files/${fileId}/revisions/${fileRevisionId}/content`,
26
26
  {},
27
+ { responseType: 'arraybuffer' },
27
28
  );
29
+ return Buffer.from(data);
28
30
  }
29
31
  }
30
32
 
@@ -161,6 +161,26 @@ class FilesApi {
161
161
  return path.resolve(filePath);
162
162
  }
163
163
 
164
+ /**
165
+ * Fetch a file's raw bytes from a direct download URL using X-API-KEY, without
166
+ * writing to disk. Useful when the caller needs to relay the content onward
167
+ * (e.g. as an HTTP response body) rather than save it to a local filesystem.
168
+ * @param {string} downloadLink
169
+ * @returns {Promise<{ buffer: Buffer, contentType: string|undefined }>}
170
+ */
171
+ async downloadFileBuffer(downloadLink) {
172
+ const apiKey = this._client.configuration.apiKey;
173
+ const response = await axios.get(downloadLink, {
174
+ headers: { 'X-API-KEY': apiKey },
175
+ responseType: 'arraybuffer',
176
+ validateStatus: () => true,
177
+ });
178
+ if (response.status !== 200) {
179
+ throw new Error(`Failed to download file. Status code: ${response.status}`);
180
+ }
181
+ return { buffer: Buffer.from(response.data), contentType: response.headers['content-type'] };
182
+ }
183
+
164
184
  /**
165
185
  * Get a file by IDs or by full path.
166
186
  *
package/src/apiClient.js CHANGED
@@ -44,6 +44,9 @@ class ApiClient {
44
44
  _getErrorDetail(response) {
45
45
  try {
46
46
  const data = response.data;
47
+ if (Buffer.isBuffer(data) || data instanceof ArrayBuffer) {
48
+ return Buffer.from(data).toString('utf8').slice(0, 200);
49
+ }
47
50
  if (data && typeof data === 'object') {
48
51
  if (data.message) return data.message;
49
52
  if (data.error) return data.error;
@@ -76,11 +79,12 @@ class ApiClient {
76
79
  * Perform a GET request.
77
80
  * @param {string} path - URL path (e.g. '/5.1/projects')
78
81
  * @param {object} [params] - Query string parameters
82
+ * @param {object} [config] - Extra axios config (e.g. { responseType: 'arraybuffer' } for binary content)
79
83
  * @returns {Promise<any>} Parsed response body
80
84
  */
81
- async get(path, params = {}) {
85
+ async get(path, params = {}, config = {}) {
82
86
  try {
83
- const response = await this._axios.get(path, { params });
87
+ const response = await this._axios.get(path, { params, ...config });
84
88
  return response.data;
85
89
  } catch (err) {
86
90
  this._handleAxiosError(err, path);