smartsuite-typescript-api
Version:
Typescript type generator and wrapper for the REST API provided by SmartSuite. Currently in pre 1.0 so no semver guarantees are given
76 lines (75 loc) • 3.77 kB
TypeScript
import { HttpsClientOptions } from "./httpClient/http.js";
import { AllFieldTypes, CountFieldParams, FieldFilter, FormulaFieldParams, SolutionMetadata, TableField, TableMetadata, TimeTrackingFieldParams } from "./metadataModels.js";
import { typeMap } from "./generatedTyping/typeMap.js";
interface SortingOptions {
/**
* Field ID
*/
field: string;
direction: "asc" | "desc";
}
/**
* Not all fields can be used for filtering and sorting, see the docs link attached
* @see https://help.smartsuite.com/en/articles/6963760-sorting-and-filtering-records-in-the-rest-api#h_4e0002bc33
*/
interface FilteringOptions {
filter?: FieldFilter;
sort?: SortingOptions[];
}
interface RecordFetchOptions {
hydrated?: boolean;
/**
* Include deleted records?
*/
all?: boolean;
}
export type SmartSuiteRecord = Record<string, any>;
export declare class SmartSuiteAPI {
private readonly httpsClient;
constructor(options: HttpsClientOptions);
getAllSolutions(): Promise<SolutionMetadata[]>;
getSolutionMetadata(solutionID: string): Promise<SolutionMetadata>;
createSolution(data: SolutionMetadata): Promise<any>;
/**
* Duplicate a solution to another workspace, null as the workspace id duplicates to this workspace
*
* duplicateSolution(someID, null) <-- Duplicates the solution with the given ID to this workspace
* @param solutionID
* @param toWorkspace the workspace to duplicate the given solution to
*/
duplicateSolution(solutionID: string, toWorkspace: string | null): Promise<void>;
/**
* Get all tables, or optionally all tables in a given solution.
* If you want all tables from multiple solutions fetch all tables and filter like:
*
* `const tables = api.getTables().filter(table => validSolutions.includes(table.solution))`
* @param solutionID
*/
getTables(solutionID?: string): Promise<TableMetadata[]>;
createTable(data: TableMetadata): Promise<any>;
getTableMetadata<T extends keyof typeof typeMap>(tableIDOrName: T | string): Promise<TableMetadata>;
/**
* Get a record from the given table, table can also be referenced by display name as shown on SmartSuite in addition to id.
* @param recordID the record id to fetch
* @param tableIDOrName either the id or display name of the table to fetch the record from
* @no
*/
getRecord<T extends keyof typeof typeMap>(recordID: string, tableIDOrName: T): Promise<SmartSuiteRecord>;
/**
* Get all records from the given table, table can be referenced by display name as shown on SmartSuite in addition to id.
* @param tableIDOrName either the id or display name of the table to fetch the records from
* @param options can be used to filter and/or sort the response, see types for possible options
* @see FilteringOptions
* @see RecordFetchOptions
*/
getRecords<T extends keyof typeof typeMap>(tableIDOrName: T, options?: FilteringOptions & RecordFetchOptions): Promise<ReturnType<typeof typeMap[T]["mapper"]["mapKeys"]>[]>;
createField<T extends keyof typeof typeMap>(tableIDOrName: T, data: TableField): Promise<any>;
createFieldBulk<T extends keyof typeof typeMap>(tableIDOrName: T, data: TableField<Exclude<AllFieldTypes, FormulaFieldParams | CountFieldParams | TimeTrackingFieldParams>>[]): Promise<any>;
listMembers(): Promise<any>;
getMember(memberID: string): Promise<any>;
updateMember(memberID: string, data: any): Promise<any>;
changeMember(memberID: string, updateFunction: (memberData: any) => any): Promise<any>;
getComments(recordID: string): Promise<any>;
postComment(comment: any): Promise<any>;
}
export { generateTableTypings } from "./typeGeneration.js";