splid-js-googlesheet-updater/node_modules/splid-js/dist/mjs/SplidClient.d.ts
2025-05-27 21:06:02 +02:00

335 lines
14 KiB
TypeScript

import { BatchClient } from './BatchClient';
import { Balance } from './getBalance';
import { createGroup } from './methods/createGroup';
import { getCodeConfig } from './methods/getCodeConfig';
import { getFileBlob } from './methods/getFileBlob';
import { joinGroupWithAnyCode } from './methods/joinGroupWithAnyCode';
import { uploadFile } from './methods/uploadFile';
import { RequestConfig } from './requestConfig';
import { IdToResponseTypesMap, RequestObject } from './requestObject';
import { Entry } from './types/entry';
import { Person } from './types/person';
import { FuncWithoutConfigArg } from './util';
export interface SplidClientOptions {
fetch?: typeof fetch;
/**
* by default, the client automatically switches to a new installation id if we hit a rate limit with the Splid API
*/
disableAutomaticInstallationIdRefresh?: boolean;
/**
* used for the `x-parse-installation-id` header when making requests to the Splid API.
*
* changing this resets any rate limits that may be active
*/
installationId?: string;
/**
* used for the `x-parse-application-id` header when making requests to the Splid API
*/
parseApplicationId?: string;
/**
* used for the `x-parse-client-key` header when making requests to the Splid API
*/
parseClientKey?: string;
}
export default class SplidClient {
private requestConfig;
/**
* by default, the client automatically switches to a new installation id if we hit a rate limit with the Splid API
*/
private disableAutomaticInstallationIdRefresh;
/**
* used for the `x-parse-application-id` header when making requests to the Splid API
*/
parseApplicationId: string;
/**
* used for the `x-parse-client-key` header when making requests to the Splid API
*/
parseClientKey: string;
constructor(options?: SplidClientOptions);
/**
* used for the `x-parse-installation-id` header when making requests to the Splid API.
*
* changing this resets any rate limits that may be active
*/
get installationId(): string;
/**
* resets any rate limits that may be active
*/
setInstallationId(installationId: string): void;
/**
* resets any rate limits that may be active
*/
setRandomInstallationId(): void;
private getHeaders;
/**
* the Splid App dynamically configures the length an invite code needs to have from the backend, presumably so they could seamlessly switch to longer codes should they run into limits in the future.
*
* at the time of writing, the length of invite codes is always `9`.
*/
getCodeConfig: FuncWithoutConfigArg<typeof getCodeConfig>;
/**
* returns the most recent currency exchange rates in form of a map of a currency code to its value in dollars
*/
getCurrencyRates: FuncWithoutConfigArg<() => Promise<Record<string, number>>>;
group: {
getByInviteCode: FuncWithoutConfigArg<typeof joinGroupWithAnyCode>;
create: FuncWithoutConfigArg<typeof createGroup>;
};
groupInfo: {
getByGroup: FuncWithoutConfigArg<(config: RequestConfig, groupId: string, skip?: number, limit?: number, minDate?: Date) => Promise<import("./methods/findObjects").FindObjectsResponse<import("./types/groupInfo").GroupInfo>>>;
getOneByGroup: FuncWithoutConfigArg<(config: RequestConfig, groupId: any) => Promise<import("./types/groupInfo").GroupInfo>>;
updateCurrencyRates: (groupId: string) => FuncWithoutConfigArg<(config: RequestConfig) => void>;
set: FuncWithoutConfigArg<(config: RequestConfig, data: {
GlobalId: import("./types/primitives").GroupId;
UpdateInstallationID: import("./types/primitives").Uuid;
createdGlobally: {
__type: "Date";
iso: import("./types/primitives").IsoTime;
};
isDeleted: boolean;
group: {
__type: "Pointer";
className: "_User";
objectId: string;
};
name: string;
defaultCurrencyCode: import("./types/primitives").CurrencyCode;
creatorInstallationID: import("./types/primitives").Uuid;
currencyRates: Record<import("./types/primitives").CurrencyCode, number>;
customCategories: string[];
wallpaperID?: string | {
__op: "Delete";
};
} | {
GlobalId: import("./types/primitives").GroupId;
UpdateInstallationID: import("./types/primitives").Uuid;
createdGlobally: {
__type: "Date";
iso: import("./types/primitives").IsoTime;
};
isDeleted: boolean;
group: {
__type: "Pointer";
className: "_User";
objectId: string;
};
name: string;
defaultCurrencyCode: import("./types/primitives").CurrencyCode;
creatorInstallationID: import("./types/primitives").Uuid;
currencyRates: Record<import("./types/primitives").CurrencyCode, number>;
customCategories: string[];
wallpaperID?: string | {
__op: "Delete";
};
}[]) => Promise<import("./methods/updateGroup").UpdateGroupResponse[]>>;
};
person: {
create: FuncWithoutConfigArg<(config: RequestConfig, groupId: string, name: string, initials?: string) => Promise<import("./methods/createPerson").CreatePersonResponse[]>>;
getByGroup: FuncWithoutConfigArg<(config: RequestConfig, groupId: string, skip?: number, limit?: number, minDate?: Date) => Promise<import("./methods/findObjects").FindObjectsResponse<Person>>>;
getAllByGroup: (groupId: string) => Promise<Person[]>;
set: FuncWithoutConfigArg<(config: RequestConfig, data: {
GlobalId: import("./types/primitives").UserId;
UpdateInstallationID: import("./types/primitives").Uuid;
createdGlobally: {
__type: "Date";
iso: import("./types/primitives").IsoTime;
};
isDeleted: boolean;
group: {
__type: "Pointer";
className: "_User";
objectId: string;
};
name: string;
initials: string;
} | {
GlobalId: import("./types/primitives").UserId;
UpdateInstallationID: import("./types/primitives").Uuid;
createdGlobally: {
__type: "Date";
iso: import("./types/primitives").IsoTime;
};
isDeleted: boolean;
group: {
__type: "Pointer";
className: "_User";
objectId: string;
};
name: string;
initials: string;
}[]) => Promise<import("./methods/updatePerson").UpdatePersonResponse[]>>;
};
entry: {
set: FuncWithoutConfigArg<(config: RequestConfig, data: {
GlobalId: import("./types/primitives").EntryId;
UpdateInstallationID: import("./types/primitives").Uuid;
createdGlobally: {
__type: "Date";
iso: import("./types/primitives").IsoTime;
};
isDeleted: boolean;
isPayment: boolean;
group: {
__type: "Pointer";
className: "_User";
objectId: string;
};
title?: string;
secondaryPayers?: Record<string, number>;
primaryPayer: import("./types/primitives").UserId;
items: import("./types/entry").EntryItem[];
currencyCode: import("./types/primitives").CurrencyCode;
category?: {
originalName: string;
type: import("./types/entry").EntryCategory;
} | {
__op: "Delete";
};
date?: {
__type: "Date";
iso: import("./types/primitives").IsoTime;
} | {
__op: "Delete";
};
} | {
GlobalId: import("./types/primitives").EntryId;
UpdateInstallationID: import("./types/primitives").Uuid;
createdGlobally: {
__type: "Date";
iso: import("./types/primitives").IsoTime;
};
isDeleted: boolean;
isPayment: boolean;
group: {
__type: "Pointer";
className: "_User";
objectId: string;
};
title?: string;
secondaryPayers?: Record<string, number>;
primaryPayer: import("./types/primitives").UserId;
items: import("./types/entry").EntryItem[];
currencyCode: import("./types/primitives").CurrencyCode;
category?: {
originalName: string;
type: import("./types/entry").EntryCategory;
} | {
__op: "Delete";
};
date?: {
__type: "Date";
iso: import("./types/primitives").IsoTime;
} | {
__op: "Delete";
};
}[]) => Promise<import("./methods/updateEntry").UpdateEntryResponse[]>>;
getByGroup: FuncWithoutConfigArg<(config: RequestConfig, groupId: string, skip?: number, limit?: number, minDate?: Date) => Promise<import("./methods/findObjects").FindObjectsResponse<Entry>>>;
getAllByGroup: (groupId: string) => Promise<Entry[]>;
create: FuncWithoutConfigArg<(config: RequestConfig, entry: Omit<Entry, "GlobalId" | "UpdateInstallationID" | "createdGlobally" | "createdAt" | "updatedAt" | "UpdateID" | "className" | "__type" | "objectId" | "isDeleted" | "isPayment" | "group"> & ({
isDeleted?: boolean;
isPayment?: boolean;
} & ({
group: {
__type: "Pointer";
className: "_User";
objectId: string;
};
} | {
groupObjectId: string;
}))) => Promise<import("./methods/createExpense").CreateExpenseResponse[]>>;
expense: {
create: FuncWithoutConfigArg<(config: RequestConfig, options: {
groupId: string;
title?: string;
date?: Date;
category?: {
type: any;
originalName: any;
};
payers: Record<string, number> | (string | {
id: string;
amount: number;
})[];
currencyCode?: string;
}, items: Omit<{
title?: string;
amount: number;
profiteers: Record<string, number> | (string | {
id: string;
share: number;
})[];
}, "title"> | {
title?: string;
amount: number;
profiteers: Record<string, number> | (string | {
id: string;
share: number;
})[];
}[]) => Promise<import("./methods/createExpense").CreateExpenseResponse[]>>;
};
payment: {
create: FuncWithoutConfigArg<(config: RequestConfig, options: {
groupId: string;
payer: string;
amount: number;
profiteer: string;
date?: Date;
currencyCode?: string;
}) => Promise<import("./methods/createPayment").CreatePaymentResponse[]>>;
};
};
file: {
/**
* uploads a file to the Splid API.
*
* at the time of writing, this is only used for group wallpapers.
*/
upload: FuncWithoutConfigArg<typeof uploadFile>;
/**
* returns the metadata of the asset with the given `dataID`.
*
* you'll probably want to use `SplidClient.file.getBlob` instead.
*/
getInfo: FuncWithoutConfigArg<(_: RequestConfig, dataID: string) => Promise<import("./methods/getFileWrapper").GetFileWrapperResponse[]>>;
/**
* returns the blob data of the asset with the given `dataID`.
*
* depending on your execution context, there are multiple ways of processing this data:
* ```ts
* // example: getting the wallpaper source of a group in the browser
* const src = URL.createObjectURL(await splid.file.getBlob(groupInfo.wallpaperID));
* ```
*
* ```ts
* // example: writing the wallpaper of a group to a file using NodeJs
* const blob = await splid.file.getBlob(groupInfo.wallpaperID);
*
* const arrayBuffer = await blob.arrayBuffer();
*
* const uint8Array = new Uint8Array(arrayBuffer);
*
* await promises.writeFile("./wallpaper.jpeg", uint8Array);
* ```
*/
getBlob: FuncWithoutConfigArg<typeof getFileBlob>;
};
/**
* a primitive that combines multiple actions into one request, speeding them up and making them less bandwidth intense.
*
* ```ts
* // example: creating multiple group members
* await splid.batch((b) => names.map((name) => b.person.create(groupId, name)));
* ```
*/
batch: <T extends RequestObject[]>(callback: (batch: BatchClient) => T) => Promise<{ [K in keyof T]: IdToResponseTypesMap[T[K]["id"]]; }>;
private assertResponseBody;
private injectRequestConfig;
static getBalance: (people: Pick<Person, "GlobalId">[], entries: Pick<Entry, "GlobalId" | "isDeleted" | "primaryPayer" | "secondaryPayers" | "items" | "currencyCode">[], groupInfo?: Pick<import("./types/groupInfo").GroupInfo, "currencyRates" | "defaultCurrencyCode">) => Balance;
static getSuggestedPayments: (balance: Balance) => import("./getSuggestedPayments").SuggestedPayment[];
static dedupeByGlobalId: <T extends {
GlobalId: string;
}>(entries: T[]) => T[];
static getRoundedBalance: (num: number, precision?: number) => string;
static getTotal: (balance: Balance) => string;
}