yakovkhalinsky/backblaze-b2

Please consider exposing/exporting types

Opened this issue · 0 comments

Please consider exporting some of these interface types, e.g. I need to reference StandardApiResponse in my code but I can't since it's not exported.

This means I can't do stuff like this:
const x: StandardApiResponse = await b2.listBuckets({}); (because I can't reference StandardApiResponse)

From index.d.ts:

/// <reference types="node" />

export as namespace BackBlazeB2;

export = BackBlazeB2;

interface B2InitOptions {
    applicationKeyId: string;
    applicationKey: string;
    axios?: Record<string, any> | undefined;
    retry?: Record<string, any> | undefined;
}

interface CommonArgs {
    axios?: Record<string, any> | undefined;
    axiosOverride?: Record<string, any> | undefined;
}

interface StandardApiResponse {
    status: number;
    statusText: string;
    headers: any;
    config: any;
    request: any;
    data: any;
}
type BucketType = "allPublic" | "allPrivate";

interface CreateBucketOpts extends CommonArgs {
    bucketName: string;
    bucketType: BucketType;
}
interface GetBucketOpts extends CommonArgs {
    bucketName: string;
    bucketId?: string | undefined;
}
interface UpdateBucketOpts extends CommonArgs {
    bucketId: string;
    bucketType: BucketType;
}
interface UploadProgressFn {
    (event: any): void;
}

interface UploadFileOpts extends CommonArgs {
    uploadUrl: string;
    uploadAuthToken: string;
    fileName: string;
    data: Buffer;
    /**
     * data length
     * @default  data.byteLength or data.length
     */
    contentLength?: number | undefined;
    /**
     * mime type
     * @default 'b2/x-auto'
     */
    mime?: string | undefined;
    /**
     * data hash
     * @default sha1(data)
     */
    hash?: string | undefined;
    /**
     * info headers, prepended with X-Bz-Info- when sent,
     * throws error if more than 10 keys set.
     * valid characters should be a-z, A-Z and '-',
     * all other characters will cause an error to be thrown
     */
    info?: Record<string, string> | undefined;
    onUploadProgress?: UploadProgressFn | null | undefined;
}

interface ListFileNamesOpts extends CommonArgs {
    bucketId: string;
    startFileName: string;
    maxFileCount: number;
    delimiter: string;
    prefix: string;
}

interface ListFileVersionsOpts extends CommonArgs {
    bucketId: string;
    startFileName: string;
    startFileId: string;
    maxFileCount: number;
}

interface ListPartsOpts extends CommonArgs {
    fileId: string;
    startPartNumber?: number | undefined;
    /**
     * maximum part count
     * max value 100
     */
    maxPartCount?: number | undefined;
}

interface GetDownloadAuthorizationOpts extends CommonArgs {
    bucketId: string;
    fileNamePrefix: string;
    /**
     * Authorization validity : 0 to 604800
     */
    validDurationInSeconds: number;
    b2ContentDisposition?: string;
}

interface DownloadFileOpts extends CommonArgs {
    responseType: "arraybuffer" | "blob" | "document" | "json" | "text" | "stream";
    onDownloadProgress?: UploadProgressFn | null | undefined;
}

interface DownlaodFileByNameOpts extends DownloadFileOpts {
    bucketName: string;
    fileName: string;
}

interface UploadPartOpts extends CommonArgs {
    /**
     * part number: 1 to 10000
     */
    partNumber: number;
    uploadUrl: string;
    uploadAuthToken: string;
    data: Buffer;
    hash?: string | undefined;
    onUploadProgress?: UploadProgressFn | null | undefined;
    contentLength?: number | undefined;
}

interface CreateKeyOpts extends CommonArgs {
    capabilities: string[];
    keyName: string;
    validDurationInSeconds?: number | undefined;
    bucketId?: string | undefined;
    namePrefix?: string | undefined;
}

declare class BackBlazeB2 {
    constructor(options: B2InitOptions);
    authorize(opts?: CommonArgs): Promise<StandardApiResponse>;

    createBucket(opts: CreateBucketOpts): Promise<StandardApiResponse>;
    deleteBucket(opts: { bucketId: string } & CommonArgs): Promise<StandardApiResponse>;
    listBuckets(opts?: CommonArgs): Promise<StandardApiResponse>;
    getBucket(opts: GetBucketOpts): Promise<StandardApiResponse>;
    updateBucket(opts: UpdateBucketOpts): Promise<StandardApiResponse>;

    getUploadUrl(opts: { bucketId: string } & CommonArgs): Promise<StandardApiResponse>;
    uploadFile(opts: UploadFileOpts): Promise<StandardApiResponse>;
    listFileNames(opts: ListFileNamesOpts): Promise<StandardApiResponse>;
    listFileVersions(opts: ListFileVersionsOpts): Promise<StandardApiResponse>;

    listParts(opts: ListPartsOpts): Promise<StandardApiResponse>;
    hideFile(opts: { bucketId: string; fileName: string } & CommonArgs): Promise<StandardApiResponse>;
    getFileInfo(opts: { fileId: string } & CommonArgs): Promise<StandardApiResponse>;
    getDownloadAuthorization(opts: GetDownloadAuthorizationOpts): Promise<StandardApiResponse>;
    downloadFileByName(opts: DownlaodFileByNameOpts): Promise<StandardApiResponse>;
    downloadFileById(opts: { fileId: string } & DownloadFileOpts): Promise<StandardApiResponse>;
    deleteFileVersion(opts: { fileId: string; fileName: string } & CommonArgs): Promise<StandardApiResponse>;
    startLargeFile(opts: { bucketId: string; fileName: string } & CommonArgs): Promise<StandardApiResponse>;
    getUploadPartUrl(opts: { fileId: string } & CommonArgs): Promise<StandardApiResponse>;
    uploadPart(opts: UploadPartOpts): Promise<StandardApiResponse>;
    finishLargeFile(opts: { fileId: string; partSha1Array: string[] } & CommonArgs): Promise<StandardApiResponse>;
    cancelLargeFile(opts: { fileId: string } & CommonArgs): Promise<StandardApiResponse>;

    createKey(opts: CreateKeyOpts): Promise<StandardApiResponse>;
    deleteKey(opts: { applicationKeyId: string } & CommonArgs): Promise<StandardApiResponse>;
    listKeys(opts: { maxKeyCount: number; startApplicationKeyId: string } & CommonArgs): Promise<StandardApiResponse>;
}