diff --git a/types/ali-oss/ali-oss-tests.ts b/types/ali-oss/ali-oss-tests.ts new file mode 100644 index 0000000000..3cf3229da9 --- /dev/null +++ b/types/ali-oss/ali-oss-tests.ts @@ -0,0 +1,3 @@ +import OSS from "ali-oss"; + +const client = new OSS(); diff --git a/types/ali-oss/index.d.ts b/types/ali-oss/index.d.ts new file mode 100644 index 0000000000..b7c0f35067 --- /dev/null +++ b/types/ali-oss/index.d.ts @@ -0,0 +1,247 @@ +// Type definitions for ali-oss 6.0.1 +// Project: https://github.com/ali-sdk/ali-oss +// Definitions by: Ptrdu +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.2.0 + +export type Bucket = { + +} + +export type StorageType = "Standard" | "IA" | "Archive" + +export type ACLType = "public-read-write" | "public-read" | "and private" + +export type RequestOptions = { + // the operation timeout + timeout?: number +} + +export type RuleStatusType = "Enabled" | "Disabled" + +export type LifecycleRule = { + id?: string, // rule id, if not set, OSS will auto create it with random string. + prefix: string, // store prefix + status: RuleStatusType, // rule status, allow values: Enabled or Disabled + days?: number | string, // expire after the days + date: string // expire date, e.g.: 2022-10-11T00:00:00.000Z date and days only set one. +} + +export type CORSRule = { + allowedOrigin: string | Array, // configure for Access-Control-Allow-Origin header + allowedMethod: string | Array, // configure for Access-Control-Allow-Methods header + allowedHeader?: string | Array, // configure for Access-Control-Allow-Headers header + exposeHeader?: string | Array, // configure for Access-Control-Expose-Headers header + maxAgeSeconds?: string | Array, // configure for Access-Control-Max-Age header +} + +export interface NormalSuccessResponse { + //response status + status: number, + // response headers + headers: object, // todo the object in detail + // response size + size: number, + // request total use time (ms) + rt: number +} + +export default class OSS { + /******************************************* the bucket operations *************************************************/ + // base operators + /** + * List buckets in this account. + * @param {{prefix?: string; marker?: string; "max-keys"?: string | number} | null} query - query parameters, default is null + * prefix - search buckets using prefix key + * marker - search start from marker, including marker key + * max-keys - max buckets, default is 100, limit to 1000 + * @param {{timeout?: number}} options - optional parameters + * timeout - the operation timeout + * @return {Promise>} + */ + listBuckets(query: { prefix?: string, marker?: string, 'max-keys'?: string | number } | null, options?: { timeout?: number }): Promise> + + /** + * Create a new bucket. + * @param {string} name - bucket name If bucket exists and not belong to current account, will throw BucketAlreadyExistsError. If bucket not exists, will create a new bucket and set it's ACL. + * @param {{timeout: number; storageClass: StorageType}} options - optional parameters + * timeout - the operation timeout + * StorageClass - the storage type include (Standard,IA,Archive) + * @return { Promise<{ bucket: string, res: NormalSuccessResponse }> } + */ + putBucket(name: string, options?: { timeout: number, storageClass: StorageType }): Promise<{ bucket: string, res: NormalSuccessResponse }> + + /** + * Use the bucket. + * @param {string} name - bucket name + */ + useBucket(name: string) : void + + /** + * Delete an empty bucket. + * @param {string} name - bucket name If bucket is not empty, will throw BucketNotEmptyError. If bucket is not exists, will throw NoSuchBucketError. + * @param {RequestOptions} options + * @return {Promise} + */ + deleteBucket(name: string, options?: RequestOptions): Promise + + /** + * Get bucket information,include CreationDate、ExtranetEndpoint、IntranetEndpoint、Location、Name、StorageClass、 Owner、AccessControlList + * @param {string} name - bucket name + * @return {Promise} // todo the official document miss the return type + */ + getBucketInfo(name: string): Promise + + /** + * Get bucket location + * @param {string} name - bucket name + * @return {Promise} // todo the official document miss the return type + */ + getBucketLocation(name: string): Promise + // ACL operations + /** + * Update the bucket ACL. + * @param {string} name - bucket name + * @param {ACLType} acl - access control list, current available: public-read-write, public-read and private + * @param {RequestOptions} options + * @return {Promise} + */ + putBucketACL(name: string, acl: ACLType, options?: RequestOptions): Promise + + /** + * Get the bucket ACL. + * @param {string} name - bucket name + * @param {RequestOptions} options + * @return {Promise<{ acl: string, res: NormalSuccessResponse }>} + * acl - acl settings string + */ + getBucketACL(name: string, options?: RequestOptions ): Promise<{ acl: string, res: NormalSuccessResponse }> + // logging operations + /** + * Update the bucket logging settings. Log file will create every one hour and name format: -YYYY-mm-DD-HH-MM-SS-UniqueString. + * @param {string} name - bucket name + * @param {string} prefix - prefix path name to store the log files + * @param {RequestOptions} options + * @return {Promise} + */ + putBucketLogging(name: string, prefix?: string, options?: RequestOptions): Promise + + /** + * Get the bucket logging settings. + * @param {string} name + * @param {RequestOptions} options + * @return {Promise<{ enable: boolean, prefix: string | null, res: NormalSuccessResponse }>} + */ + getBucketLogging(name: string, options?: RequestOptions): Promise<{ enable: boolean, prefix: string | null, res: NormalSuccessResponse }> + + /** + * Delete the bucket logging settings. + * @param {string} name - bucket name + * @param {RequestOptions} options + * @return {Promise} + */ + deleteBucketLogging(name: string, options?: RequestOptions) : Promise + // Website operations + /** + * Set the bucket as a static website. + * @param {string} name - bucket name + * @param {{index: string; error?: string}} config + * index - default page, e.g.: index.html + * error - error page, e.g.: 'error.html' + * @return {Promise} + */ + putBucketWebsite(name: string, config: { index: string, error?: string }): Promise + + /** + * Get the bucket website config. + * @param {string} name - bucket name + * @param {RequestOptions} options + * @return {Promise<{ index: string, error: string, res: NormalSuccessResponse }>} + */ + getBucketWebsite(name: string, options?: RequestOptions): Promise<{ index: string, error: string, res: NormalSuccessResponse }> + + /** + * Delete the bucket website config. + * @param {string} name - bucket name + * @param {RequestOptions} options + * @return {Promise} + */ + deleteBucketWebsite(name: string, options?: RequestOptions): Promise + // referer operations + /** + * Set the bucket request Referer white list. + * @param {string} name + * @param {boolean} allowEmpty - allow empty request referer or not + * @param {Array} referers - Referer white list, e.g.: ['https://npm.taobao.org', 'http://cnpmjs.org'] + * @param {RequestOptions} options + * @return {Promise} + */ + putBucketReferer(name: string, allowEmpty: boolean, referers: Array, options?: RequestOptions): Promise + + /** + * Get the bucket request Referer white list. + * @param {string} name - bucket name + * @param {RequestOptions} options + * @return {Promise<{ allowEmpty: boolean, referers: Array, res: NormalSuccessResponse }>} + */ + getBucketReferer(name: string, options?: RequestOptions): Promise<{ allowEmpty: boolean, referers: Array, res: NormalSuccessResponse }> + + /** + * Delete the bucket request Referer white list. + * @param {string} name + * @param {RequestOptions} options + * @return {Promise} + */ + deleteBucketReferer(name: string, options?: RequestOptions): Promise + // lifecycle operations + /** + * Set the bucket object lifecycle. + * @param {string} name + * @param {Array} rules - rule config list + * @param {RequestOptions} options + * @return {Promise} + */ + putBucketLifecycle(name: string, rules: Array, options?: RequestOptions): Promise + + /** + * Get the bucket object lifecycle. + * @param {string} name + * @param {RequestOptions} options + * @return {Promise<{ rules: Array, res: NormalSuccessResponse }>} + */ + getBucketLifecycle(name: string, options?: RequestOptions): Promise<{ rules: Array, res: NormalSuccessResponse }> + + /** + * Delete the bucket object lifecycle. + * @param {string} name + * @param {RequestOptions} options + * @return {Promise} + */ + deleteBucketLifecycle(name: string, options?: RequestOptions): Promise + // CORS operations + /** + * Set CORS rules of the bucket object + * @param {string} name + * @param {Array} rules + * @param {RequestOptions} options + * @return {Promise} + */ + putBucketCORS(name: string, rules: Array, options?: RequestOptions): Promise + + /** + * Get CORS rules of the bucket object. + * @param {string} name + * @return {Promise<{rules: Array; res: NormalSuccessResponse}>} + */ + getBucketCORS(name: string): Promise<{ rules: Array, res: NormalSuccessResponse}> + + /** + * Delete CORS rules of the bucket object. + * @param {string} name + * @return {Promise} + */ + deleteBucketCORS(name: string): Promise + + /********************************************************** Object operations ********************************************/ + +} diff --git a/types/ali-oss/tsconfig.json b/types/ali-oss/tsconfig.json new file mode 100644 index 0000000000..a3e68ada2b --- /dev/null +++ b/types/ali-oss/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "ali-oss-tests.ts" + ] +} diff --git a/types/ali-oss/tslint.json b/types/ali-oss/tslint.json new file mode 100644 index 0000000000..a41bf5d19a --- /dev/null +++ b/types/ali-oss/tslint.json @@ -0,0 +1,79 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + "adjacent-overload-signatures": false, + "array-type": false, + "arrow-return-shorthand": false, + "ban-types": false, + "callable-types": false, + "comment-format": false, + "dt-header": false, + "eofline": false, + "export-just-namespace": false, + "import-spacing": false, + "interface-name": false, + "interface-over-type-literal": false, + "jsdoc-format": false, + "max-line-length": false, + "member-access": false, + "new-parens": false, + "no-any-union": false, + "no-boolean-literal-compare": false, + "no-conditional-assignment": false, + "no-consecutive-blank-lines": false, + "no-construct": false, + "no-declare-current-package": false, + "no-duplicate-imports": false, + "no-duplicate-variable": false, + "no-empty-interface": false, + "no-for-in-array": false, + "no-inferrable-types": false, + "no-internal-module": false, + "no-irregular-whitespace": false, + "no-mergeable-namespace": false, + "no-misused-new": false, + "no-namespace": false, + "no-object-literal-type-assertion": false, + "no-padding": false, + "no-redundant-jsdoc": false, + "no-redundant-jsdoc-2": false, + "no-redundant-undefined": false, + "no-reference-import": false, + "no-relative-import-in-test": false, + "no-self-import": false, + "no-single-declare-module": false, + "no-string-throw": false, + "no-unnecessary-callback-wrapper": false, + "no-unnecessary-class": false, + "no-unnecessary-generics": false, + "no-unnecessary-qualifier": false, + "no-unnecessary-type-assertion": false, + "no-useless-files": false, + "no-var-keyword": false, + "no-var-requires": false, + "no-void-expression": false, + "no-trailing-whitespace": false, + "object-literal-key-quotes": false, + "object-literal-shorthand": false, + "one-line": false, + "one-variable-per-declaration": false, + "only-arrow-functions": false, + "prefer-conditional-expression": false, + "prefer-const": false, + "prefer-declare-function": false, + "prefer-for-of": false, + "prefer-method-signature": false, + "prefer-template": false, + "radix": false, + "semicolon": false, + "space-before-function-paren": false, + "space-within-parens": false, + "strict-export-declare-modifiers": false, + "trim-file": false, + "triple-equals": false, + "typedef-whitespace": false, + "unified-signatures": false, + "void-return": false, + "whitespace": false + } +}