Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please consider exposing/exporting types #137

Open
Sebastian-Nielsen opened this issue May 4, 2024 · 0 comments
Open

Please consider exposing/exporting types #137

Sebastian-Nielsen opened this issue May 4, 2024 · 0 comments

Comments

@Sebastian-Nielsen
Copy link

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>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant