@planet-a/affinity-node
Version:
API wrapper for the affinity.co API
119 lines (118 loc) • 4.68 kB
TypeScript
import * as dntShim from "../_dnt.shims.js";
import type { AxiosInstance } from 'axios';
import type { Readable } from 'node:stream';
import { EntityRequestFilter } from './field_value_changes.js';
import type { PagedRequest } from './paged_request.js';
import type { PagedResponse } from './paged_response.js';
import type { DateTime, Replace, RequireOnlyOne } from './types.js';
export type { DateTime } from './types.js';
export type EntityFileRaw = {
/** The unique identifier of the entity file object. */
id: number;
/** The name of the file. */
name: string;
/** The size of the file in bytes. */
size: number;
/** The unique identifier of the person corresponding to the entity file. */
person_id: number | null;
/** The unique identifier of the organization corresponding to the entity file. */
organization_id: number | null;
/** The unique identifier of the opportunity corresponding to the entity file. */
opportunity_id: number | null;
/** The unique identifier of the user who created the entity file. */
uploader_id: number;
/** The time when the entity file was created. */
created_at: DateTime;
};
export type EntityFile = Replace<EntityFileRaw, {
created_at: Date;
}>;
/**
* Represents the request parameters for retrieving entity files.
*/
export type AllEntityFileRequest = PagedRequest | (RequireOnlyOne<{
/**
* A unique ID that represents a Person whose associated files should be retrieved.
*/
person_id?: number;
/**
* A unique ID that represents an Organization whose associated files should be retrieved.
*/
organization_id?: number;
/**
* A unique ID that represents an Opportunity whose associated files should be retrieved.
*/
opportunity_id?: number;
}> & PagedRequest);
export type PagedEntityFileResponseRaw = {
entity_files: EntityFileRaw[];
} & PagedResponse;
export type PagedEntityFileResponse = Replace<PagedEntityFileResponseRaw, {
entity_files: EntityFile[];
}>;
export type SupportedFileType = dntShim.File | string;
export type UploadEntityFileRequest = {
files: SupportedFileType[];
} & RequireOnlyOne<EntityRequestFilter>;
/**
* Entity files are files uploaded to a relevant entity.
* Possible files, for example, would be a pitch deck for an opportunity or a physical mail correspondence for a person.
*/
export declare class EntityFiles {
private readonly axios;
/** @hidden */
constructor(axios: AxiosInstance);
private static transformEntityFile;
/**
* Returns all entity files within your organization.
*/
all(params?: AllEntityFileRequest): Promise<PagedEntityFileResponse>;
/**
* Returns an async iterator that yields all entity files matching the given request
* Each yielded array contains up to the number specified in {@link AllEntityFileRequest.page_size} of entity files.
* Use this method if you want to process the entity files in a streaming fashion.
*
* *Please note:* the yielded entity files array may be empty on the last page.
*
* @example
* ```typescript
* let page = 0
* for await (const entries of affinity.entityFiles.pagedIterator({
* person_id: 123,
* page_size: 10
* })) {
* console.log(`Page ${++page} of entries:`, entries)
* }
* ```
*/
pagedIterator: (params: Omit<AllEntityFileRequest | undefined, keyof PagedRequest> & Omit<PagedRequest, "page_token">) => AsyncGenerator<import("./create_search_iterator_fn.js").Unwrapped<(params?: AllEntityFileRequest) => Promise<PagedEntityFileResponse>, "entity_files">>;
/**
* Fetches an entity with a specified `entity_file_id`.
*/
get(entity_file_id: EntityFile['id']): Promise<EntityFile>;
/**
* Downloads the entity file with the specified `entity_file_id`.
*
* @example
* ```typescript
* import { promises as fsPromises } from 'node:fs';
* const fileResponseStream = affinity.entityFiles.download(123);
* await fsPromises.writeFile(filePath, fileResponseStream);
* ```
*/
download(entity_file_id: EntityFile['id']): Promise<Readable>;
/**
* Uploads files attached to the entity with the given id.
*
* The file will display on the entity's profile, provided that the entity is not a person internal to the user's organization.
*
* @example
* ```typescript
* const entityFile = await affinity.entityFiles.upload({
* files: ['/path/to/example.pdf'],
* person_id: 123,
* });
* ```
*/
upload(params: UploadEntityFileRequest): Promise<boolean>;
}