Skip to content

Commit bfb29db

Browse files
🤖 Merge PR DefinitelyTyped#74303 ali-oss: add signatureUrlV4 by @cnjsstong
Co-authored-by: StarHeart <starheart233@gmail.com>
1 parent d731924 commit bfb29db

File tree

3 files changed

+63
-5
lines changed

3 files changed

+63
-5
lines changed

types/ali-oss/ali-oss-tests.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const ossOptions: OSS.Options = {
55
accessKeySecret: "your access secret",
66
bucket: "your bucket name",
77
region: "oss-cn-hangzhou",
8+
authorizationV4: true,
89
};
910

1011
const client = new OSS(ossOptions);
@@ -15,6 +16,43 @@ client.copy("newfile.png", "sourcefile.png", { timeout: 1000 });
1516
client.copy("newfile.png", "sourcefile.png", "sourceBucket");
1617
client.copy("newfile.png", "sourcefile.png", "sourceBucket", { timeout: 1000 });
1718

19+
// $ExpectType Promise<string>
20+
client.signatureUrlV4("GET", 60, undefined, "your object name");
21+
22+
// $ExpectType Promise<string>
23+
client.signatureUrlV4(
24+
"GET",
25+
60,
26+
{
27+
headers: {
28+
"Cache-Control": "no-cache",
29+
},
30+
queries: {
31+
versionId: "version ID of your object",
32+
},
33+
},
34+
"your object name",
35+
["Cache-Control"],
36+
);
37+
38+
// $ExpectType Promise<string>
39+
client.signatureUrlV4("PUT", 60, undefined, "your object name");
40+
41+
// $ExpectType Promise<string>
42+
client.signatureUrlV4(
43+
"PUT",
44+
60,
45+
{
46+
headers: {
47+
"Content-Type": "text/plain",
48+
"Content-MD5": "xxx",
49+
"Content-Length": 1,
50+
},
51+
},
52+
"your object name",
53+
["Content-Length"],
54+
);
55+
1856
const clusterOptions: OSS.ClusterOptions = {
1957
clusters: [],
2058
};

types/ali-oss/index.d.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ declare namespace OSS {
2727
refreshSTSTokenInterval?: number;
2828
/** used by auto set stsToken、accessKeyId、accessKeySecret when sts info expires. return value must be object contains stsToken、accessKeyId、accessKeySecret */
2929
refreshSTSToken?: () => Promise<{ accessKeyId: string; accessKeySecret: string; stsToken: string }>;
30+
/** Use V4 signature. Default is false. */
31+
authorizationV4?: boolean | undefined;
3032
}
3133

3234
/**
@@ -698,11 +700,11 @@ declare namespace OSS {
698700
signatureUrlV4(
699701
method: HTTPMethods,
700702
expires: number,
701-
request?: {
703+
request: {
702704
headers?: object | undefined;
703705
queries?: object | undefined;
704-
},
705-
objectName?: string,
706+
} | undefined,
707+
objectName: string,
706708
additionalHeaders?: string[],
707709
): Promise<string>;
708710

@@ -1083,6 +1085,20 @@ declare class OSS {
10831085
*/
10841086
signatureUrl(name: string, options?: OSS.SignatureUrlOptions): string;
10851087

1088+
/**
1089+
* Generate a signed URL for V4 of an OSS resource and share the URL to allow authorized third-party users to access the resource.
1090+
*/
1091+
signatureUrlV4(
1092+
method: OSS.HTTPMethods,
1093+
expires: number,
1094+
request: {
1095+
headers?: object | undefined;
1096+
queries?: object | undefined;
1097+
} | undefined,
1098+
objectName: string,
1099+
additionalHeaders?: string[],
1100+
): Promise<string>;
1101+
10861102
/**
10871103
* Basically the same as signatureUrl, if refreshSTSToken is configured asyncSignatureUrl will refresh stsToken
10881104
*/

types/ali-oss/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"private": true,
33
"name": "@types/ali-oss",
4-
"version": "6.16.9999",
4+
"version": "6.23.9999",
55
"projects": [
6-
"https://github.com/aliyun/oss-nodejs-sdk"
6+
"https://github.com/ali-sdk/ali-oss"
77
],
88
"devDependencies": {
99
"@types/ali-oss": "workspace:."
@@ -16,6 +16,10 @@
1616
{
1717
"name": "StarHeart",
1818
"githubUsername": "StarHeartHunt"
19+
},
20+
{
21+
"name": "cnjsstong",
22+
"githubUsername": "cnjsstong"
1923
}
2024
]
2125
}

0 commit comments

Comments
 (0)