Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@planet-a/affinity-node

Package Overview
Dependencies
Maintainers
0
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@planet-a/affinity-node - npm Package Compare versions

Comparing version 0.0.1-test.15 to 0.0.1-test.16

44

esm/v1/entity_files.js
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 { defaultTransformers } from './axios_default_transformers.js';

@@ -116,15 +118,3 @@ import { createSearchIteratorFn } from './create_search_iterator_fn.js';

assert(files.length, 'At least one file must be provided');
if (files.length === 1) {
// Append the file as 'file' if only one file is provided
// it's a bit odd that the Affinity API expects the file to be sent in a different
// parameter, but maybe there is an implementation detail that treats multiple files
// differently to a single one, so we're complying with the API here
const [file] = files;
formData.append('file', file, file.name);
}
else {
files.forEach((file) => {
formData.append('files[]', file, file.name);
});
}
await Promise.all(files.map((file) => appendToFormData(formData, file)));
if (params.person_id) {

@@ -150,1 +140,29 @@ formData.append('person_id', params.person_id.toString());

}
function isFile(file) {
return file instanceof dntShim.File;
}
async function appendToFormData(formData, file) {
if (typeof file === 'string') {
formData.append('files[]', await openAsBlob(file), path.basename(file));
}
else if (isFile(file)) {
formData.append('files[]', file);
}
else {
throw new Error('Unsupported file type');
}
}
// 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.15",
"version": "0.0.1-test.16",
"description": "API wrapper for the affinity.co API",

@@ -41,2 +41,5 @@ "keywords": [

},
"engines": {
"node": ">=20"
},
"dependencies": {

@@ -43,0 +46,0 @@ "axios": "^1.7.2",

@@ -54,4 +54,5 @@ /// <reference types="node" />

}>;
export type SupportedFileType = dntShim.File | string;
export type UploadEntityFileRequest = {
files: dntShim.File[];
files: SupportedFileType[];
} & RequireOnlyOne<EntityRequestFilter, keyof EntityRequestFilter>;

@@ -58,0 +59,0 @@ /**

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc