UNPKG

oss-client

Version:

Aliyun OSS(Object Storage Service) Node.js Client

69 lines (68 loc) 2.47 kB
import { type RequestOptions, type IncomingHttpHeaders } from 'urllib'; import type { OSSRequestParams, OSSResult, RequestParameters } from './type/Request.js'; export interface OSSBaseClientInitOptions { /** access key you create */ accessKeyId: string; /** access secret you create */ accessKeySecret: string; /** * oss region domain. It takes priority over region. * e.g.: * - oss-cn-shanghai.aliyuncs.com * - oss-cn-shanghai-internal.aliyuncs.com */ endpoint: string; /** the bucket data region location, please see Data Regions, default is oss-cn-hangzhou. */ region?: string | undefined; /** access OSS with aliyun internal network or not, default is false. If your servers are running on aliyun too, you can set true to save lot of money. */ internal?: boolean | undefined; /** instance level timeout for all operations, default is 60s */ timeout?: number | string; isRequestPay?: boolean; } export type OSSBaseClientOptions = Required<OSSBaseClientInitOptions> & { timeout: number; }; export declare abstract class OSSBaseClient { #private; protected readonly options: OSSBaseClientOptions; constructor(options: OSSBaseClientInitOptions); /** public methods */ /** * get OSS signature */ signature(stringToSign: string): string; /** protected methods */ /** * get author header * * "Authorization: OSS " + Access Key Id + ":" + Signature * * Signature = base64(hmac-sha1(Access Key Secret + "\n" * + VERB + "\n" * + CONTENT-MD5 + "\n" * + CONTENT-TYPE + "\n" * + DATE + "\n" * + CanonicalizedOSSHeaders * + CanonicalizedResource)) */ protected authorization(method: string, resource: string, headers: IncomingHttpHeaders, subResource?: RequestParameters): string; /** * encodeURIComponent name except '/' */ protected escape(name: string): string; protected abstract getRequestEndpoint(): string; protected getRequestURL(params: Pick<OSSRequestParams, 'object' | 'query' | 'subResource'>): string; getResource(params: { bucket?: string; object?: string; }): string; createHttpClientRequestParams(params: OSSRequestParams): { url: string; options: RequestOptions; }; /** * request oss server */ protected request<T = any>(params: OSSRequestParams): Promise<OSSResult<T>>; }