@planet-a/affinity-node
Advanced tools
Comparing version 0.0.1-test.16 to 0.0.1-test.17
import * as dntShim from "../_dnt.shims.js"; | ||
import { assert } from '../deps/jsr.io/@std/assert/0.226.0/mod.js'; | ||
import fs from 'node:fs'; | ||
import path from 'node:path'; | ||
import { fileFrom } from 'fetch-blob/from.js'; | ||
import { defaultTransformers } from './axios_default_transformers.js'; | ||
@@ -107,5 +106,4 @@ import { createSearchIteratorFn } from './create_search_iterator_fn.js'; | ||
* ```typescript | ||
* const file = fs.createReadStream('example.pdf'); | ||
* const entityFile = await affinity.entityFiles.upload({ | ||
* files: [file], | ||
* files: ['/path/to/example.pdf'], | ||
* person_id: 123, | ||
@@ -119,3 +117,2 @@ * }); | ||
assert(files.length, 'At least one file must be provided'); | ||
await Promise.all(files.map((file) => appendToFormData(formData, file))); | ||
if (params.person_id) { | ||
@@ -133,2 +130,3 @@ formData.append('person_id', params.person_id.toString()); | ||
} | ||
await Promise.all(files.map((file) => appendToFormData(formData, file))); | ||
const response = await this.axios.post(entityFilesUrl(), formData, { | ||
@@ -147,6 +145,8 @@ headers: { | ||
if (typeof file === 'string') { | ||
formData.append('files[]', await openAsBlob(file), path.basename(file)); | ||
const f = await fileFrom(file); | ||
formData.append('files[]', f); | ||
} | ||
else if (isFile(file)) { | ||
formData.append('files[]', file); | ||
return null; | ||
} | ||
@@ -157,15 +157,1 @@ else { | ||
} | ||
// TODO(@joscha): replace with `import { openAsBlob } from "node:fs";` ASAP | ||
function openAsBlob(filePath) { | ||
return new Promise((resolve, reject) => { | ||
const fileStream = fs.createReadStream(filePath); | ||
const chunks = []; | ||
fileStream.on('data', (chunk) => { | ||
chunks.push(typeof chunk === 'string' ? chunk : chunk.buffer); | ||
}); | ||
fileStream.on('end', () => { | ||
resolve(new Blob(chunks)); | ||
}); | ||
fileStream.on('error', reject); | ||
}); | ||
} |
{ | ||
"name": "@planet-a/affinity-node", | ||
"version": "0.0.1-test.16", | ||
"version": "0.0.1-test.17", | ||
"description": "API wrapper for the affinity.co API", | ||
@@ -46,2 +46,3 @@ "keywords": [ | ||
"axios": "^1.7.2", | ||
"fetch-blob": "^4.0.0", | ||
"undici": "^6.0.0" | ||
@@ -48,0 +49,0 @@ }, |
@@ -112,5 +112,4 @@ /// <reference types="node" /> | ||
* ```typescript | ||
* const file = fs.createReadStream('example.pdf'); | ||
* const entityFile = await affinity.entityFiles.upload({ | ||
* files: [file], | ||
* files: ['/path/to/example.pdf'], | ||
* person_id: 123, | ||
@@ -117,0 +116,0 @@ * }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
245426
3
6728
+ Addedfetch-blob@^4.0.0
+ Addedfetch-blob@4.0.0(transitive)
+ Addednode-domexception@1.0.0(transitive)