forked from qiniu/nodejs-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
1751 lines (1535 loc) · 56.1 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* typescript definition for qiniu 7.x
* @author xialeistudio<[email protected]>
*/
import { Callback, RequestOptions } from 'urllib';
import { Agent as HttpAgent, IncomingMessage} from 'http';
import { Agent as HttpsAgent } from 'https';
import { Readable } from "stream";
import {
BatchOpsResult,
FetchObjectResult,
GetBucketCorsRulesResult,
GetBucketDomainsV3Result,
GetBucketEventsResult,
GetBucketInfoV2Result,
GetBucketQuotaResult,
GetBucketRulesResult,
GetBucketsResult,
GetObjectsResult,
StatObjectResult
} from "./StorageResponseInterface";
export declare type callback = (e?: Error, respBody?: any, respInfo?: any) => void;
export declare namespace auth {
namespace digest {
interface MacOptions {
disableQiniuTimestampSignature?: boolean;
}
class Mac {
accessKey: string;
secretKey: string;
options: MacOptions;
constructor(accessKey?: string, secretKey?: string, options?: MacOptions);
}
}
}
export declare namespace cdn {
class CdnManager {
mac: auth.digest.Mac;
constructor(mac?: auth.digest.Mac);
/**
* 获取域名日志下载链接
* @see http://developer.qiniu.com/article/fusion/api/log.html
*
* @param domains 域名列表 如:['obbid7qc6.qnssl.com','7xkh68.com1.z0.glb.clouddn.com']
* @param logDay logDay 如 2016-07-01
* @param callback callbackFunc(err, respBody, respInfo)
*/
getCdnLogList(domains: string[], logDay: string, callback: callback): void;
/**
* 获取域名访问流量数据
* @see http://developer.qiniu.com/article/fusion/api/traffic-bandwidth.html#batch-flux
*
* @param startDate 开始日期,例如:2016-07-01
* @param endDate 结束日期,例如:2016-07-03
* @param granularity 粒度,取值:5min/hour/day
* @param domains 域名列表 domain = ['obbid7qc6.qnssl.com','obbid7qc6.qnssl.com'];
* @param callback callbackFunc(err, respBody, respInfo)
*/
getFluxData(startDate: string, endDate: string, granularity: string, domains: string[], callback: callback): void;
/**
* 获取域名带宽数据
* @see http://developer.qiniu.com/article/fusion/api/traffic-bandwidth.html#batch-flux
* @param startDate 开始日期,例如:2016-07-01
* @param endDate 结束日期,例如:2016-07-03
* @param granularity 粒度,取值:5min/hour/day
* @param domains 域名列表 domain = ['obbid7qc6.qnssl.com','obbid7qc6.qnssl.com'];
* @param callback callbackFunc(err, respBody, respInfo)
*/
getBandwidthData(startDate: string, endDate: string, granularity: string, domains: string[], callback: callback): void;
/**
* 预取文件链接
* @see http://developer.qiniu.com/article/fusion/api/prefetch.html
*
* @param urls 预取urls urls = ['http://obbid7qc6.qnssl.com/023','http://obbid7qc6.qnssl.com/025']
* @param callback callbackFunc(err, respBody, respInfo)
*/
prefetchUrls(urls: string[], callback: callback): void;
/**
* 刷新链接
* @see http://developer.qiniu.com/article/fusion/api/refresh.html
*
* @param urls refreshUrls = ['http://obbid7qc6.qnssl.com/023','http://obbid7qc6.qnssl.com/025']
* @param callback callbackFunc(err, respBody, respInfo)
*/
refreshUrls(urls: string[], callback: callback): void;
/**
* 刷新目录列表,每次最多不可以超过10个目录, 刷新目录需要额外开通权限,可以联系七牛技术支持处理
* @see http://developer.qiniu.com/article/fusion/api/refresh.html
*
* @param dirs refreshDirs = ['http://obbid7qc6.qnssl.com/wo/','http://obbid7qc6.qnssl.com/']
* @param callback callbackFunc(err, respBody, respInfo)
*/
refreshDirs(dirs: string[], callback: callback): void;
/**
* 刷新目录和链接
* @param urls refreshUrls = ['http://obbid7qc6.qnssl.com/023','http://obbid7qc6.qnssl.com/025']
* @param dirs refreshDirs = ['http://obbid7qc6.qnssl.com/wo/','http://obbid7qc6.qnssl.com/']
* @param callback callbackFunc(err, respBody, respInfo)
*/
refreshUrlsAndDirs(urls: string[], dirs: string[], callback: callback): void;
/**
* 构建标准的基于时间戳的防盗链
* @param domain 自定义域名,例如 http://img.abc.com
* @param fileName 待访问的原始文件名,必须是utf8编码,不需要进行urlencode
* @param query 业务自身的查询参数,必须是utf8编码,不需要进行urlencode, 例如 {aa:"23", attname:"11111111111111"}
* @param encryptKey 时间戳防盗链的签名密钥,从七牛后台获取
* @param deadline 链接的有效期时间戳,是以秒为单位的Unix时间戳
* @return signedUrl 最终的带时间戳防盗链的url
*/
createTimestampAntiLeechUrl(domain: string, fileName: string, query: any, encryptKey: string, deadline: number): string;
}
}
export declare namespace conf {
let ACCESS_KEY: string;
let SECRET_KEY: string;
let USER_AGENT: string;
let BLOCK_SIZE: number;
let FormMimeUrl: string;
let FormMimeJson: string;
let FormMimeRaw: string;
let RS_HOST: string;
let RPC_TIMEOUT: number;
interface getRegionsProviderOptions {
bucketName: string;
accessKey: string;
}
interface ConfigOptions {
/**
* @default false
*/
useHttpsDomain?: boolean;
/**
* @default true
*/
useCdnDomain?: boolean;
/**
* @default null
*/
ucEndpointsProvider?: httpc.EndpointsProvider;
/**
* @default null
*/
queryRegionsEndpointsProvider?: httpc.EndpointsProvider;
/**
* @deprecated use regionsProvider instead
* @default null
*/
zone?: Zone;
/**
* @deprecated
* @default -1
*/
zoneExpire?: number;
/**
* @default null
*/
regionsProvider?: httpc.RegionsProvider;
}
class Config {
useHttpsDomain: boolean;
useCdnDomain: boolean;
ucEndpointsProvider?: httpc.EndpointsProvider | null;
queryRegionsEndpointsProvider?: httpc.EndpointsProvider | null;
regionsProvider?: httpc.RegionsProvider | null;
zone?: Zone | null;
zoneExpire?: number;
constructor(options?: ConfigOptions);
getUcEndpointsProvider(): httpc.EndpointsProvider;
getRegionsProvider(options?: getRegionsProviderOptions): Promise<httpc.RegionsProvider>
}
class Zone {
srcUpHosts: any;
cdnUpHosts: any;
ioHost: string;
rsHost: string;
rsfHost: string;
apiHost: string;
constructor(srcUpHosts?: any, cdnUpHosts?: any, ioHost?: string, rsHost?: string, rsfHost?: string, apiHost?: string);
}
}
export declare namespace form_up {
type UploadResult = httpc.ResponseWrapper
class FormUploader {
conf: conf.Config;
constructor(config?: conf.Config);
/**
*
* @param uploadToken
* @param key
* @param fsStream
* @param putExtra
* @param callback
*/
putStream(
uploadToken: string,
key: string | null,
fsStream: NodeJS.ReadableStream,
putExtra: PutExtra | null,
callback?: callback
): Promise<UploadResult>;
/**
*
* @param uploadToken
* @param key
* @param body
* @param putExtra
* @param callback
*/
put(
uploadToken: string,
key: string | null,
body: any,
putExtra: PutExtra | null,
callback?: callback
): Promise<UploadResult>;
/**
*
* @param uploadToken
* @param body
* @param putExtra
* @param callback
*/
putWithoutKey(
uploadToken: string,
body: any,
putExtra: PutExtra | null,
callback?: callback
): Promise<UploadResult>;
/**
* 上传本地文件
* @param uploadToken 上传凭证
* @param key 目标文件名
* @param localFile 本地文件路径
* @param putExtra 额外选项
* @param callback
*/
putFile(
uploadToken: string,
key: string | null,
localFile: string,
putExtra: PutExtra | null,
callback?: callback
): Promise<UploadResult>;
/**
*
* @param uploadToken
* @param localFile
* @param putExtra
* @param callback
*/
putFileWithoutKey(
uploadToken: string,
localFile: string,
putExtra: PutExtra | null,
callback?: callback
): Promise<UploadResult>;
}
class PutExtra {
/**
* @default ''
*/
fname: string;
/**
* @default {}
*/
params: Record<string, string>;
/**
* @default null
*/
mimeType?: string;
/**
* @default null
*/
crc32?: string;
/**
* @default 0|false
*/
checkCrc?: number | boolean;
/**
* @default {}
*/
metadata?: Record<string, string>;
/**
* 上传可选参数
* @param fname 请求体中的文件的名称
* @param params 额外参数设置,参数名称必须以x:开头
* @param mimeType 指定文件的mimeType
* @param crc32 指定文件的crc32值
* @param checkCrc 指定是否检测文件的crc32值
* @param metadata 元数据设置,参数名称必须以 x-qn-meta-${name}: 开头
*/
constructor(fname?: string, params?: Record<string, string>, mimeType?: string, crc32?: string, checkCrc?: number | boolean, metadata?: Record<string, string>);
}
}
export declare namespace resume_up {
type UploadResult = {
data: any;
resp: IncomingMessage;
}
class ResumeUploader {
config: conf.Config;
constructor(config?: conf.Config);
/**
*
* @param uploadToken
* @param key
* @param rsStream
* @param rsStreamLen
* @param putExtra
* @param callback
*/
putStream(
uploadToken: string,
key: string | null,
rsStream: NodeJS.ReadableStream,
rsStreamLen: number,
putExtra: PutExtra | null,
callback?: callback
): Promise<UploadResult>;
/**
*
* @param uploadToken
* @param key
* @param localFile
* @param putExtra
* @param callback
*/
putFile(
uploadToken: string,
key: string | null,
localFile: string,
putExtra: PutExtra | null,
callback?: callback
): Promise<UploadResult>;
/**
*
* @param uploadToken
* @param localFile
* @param putExtra
* @param callback
*/
putFileWithoutKey(
uploadToken: string,
localFile: string,
putExtra: PutExtra | null,
callback?: callback
): Promise<UploadResult>;
}
class PutExtra {
/**
* @default ''
*/
fname?: string;
/**
* @default {}
*/
params?: Record<string, string>;
/**
* @default null
*/
mimeType?: string;
/**
* @default null
*/
resumeRecordFile?: string
/**
* @default null
*/
progressCallback?: (uploadBytes: number, totalBytes: number) => void
/**
* @default v1
*/
version?: string
/**
* @default 4 * 1024 * 1024
*/
partSize?: number
/**
* @default {}
*/
metadata?: Record<string, string>
/**
* 上传可选参数
* @param fname 请求体中的文件的名称
* @param params 额外参数设置,参数名称必须以x:开头
* @param mimeType 指定文件的mimeType
* @param resumeRecordFile
* @param progressCallback
* @param partSize 分片上传v2必传字段 默认大小为4MB 分片大小范围为1 MB - 1 GB
* @param version 分片上传版本 目前支持v1/v2版本 默认v1
* @param metadata 元数据设置,参数名称必须以 x-qn-meta-${name}: 开头
*/
constructor(fname?: string, params?: Record<string, string>, mimeType?: string, resumeRecordFile?: string,
progressCallback?: (uploadBytes: number, totalBytes: number) => void,
partSize?:number, version?:string, metadata?: Record<string, string>);
}
}
export declare namespace util {
function isTimestampExpired(timestamp: number): boolean;
/**
* 使用 UTC 时间来格式化日期时间
*
* @param date 与 new Date() 接受的参数一样,内部会使用 new Date(date) 生成日期时间对象
* @param layout 目前仅接受
* YYYY
* MM
* DD
* HH
* mm
* ss
* SSS
*/
function formatDateUTC(date: Date | number | string, layout?: string): string;
function encodedEntry(bucket: string, key?: string): string;
function getAKFromUptoken(uploadToken: string): string;
function getBucketFromUptoken(uploadToken: string): string;
function base64ToUrlSafe(v: string): string;
function urlSafeToBase64(v: string): string;
function urlsafeBase64Encode(jsonFlags: string): string;
function urlSafeBase64Decode(fromStr: string): string;
function hmacSha1(encodedFlags: string | Buffer, secretKey: string | Buffer): string;
function canonicalMimeHeaderKey(fieldName: string): string;
/**
* 创建AccessToken凭证
* @param mac AK&SK对象
* @param requestURI 请求URL
* @param reqBody 请求Body,仅当请求的ContentType为application/x-www-form-urlencoded 时才需要传入该参数
*/
function generateAccessToken(mac: auth.digest.Mac, requestURI: string, reqBody?: string): string;
/**
* 创建AccessToken凭证
* @param mac AK&SK对象
* @param requestURI 请求URL
* @param reqMethod 请求方法,例如 GET,POST
* @param reqContentType 请求类型,例如 application/json 或者 application/x-www-form-urlencoded
* @param reqBody 请求Body,仅当请求的 ContentType 为 application/json 或者 application/x-www-form-urlencoded 时才需要传入该参数
* @param reqHeaders 请求Headers,例如 {"X-Qiniu-Name": "Qiniu", "Content-Type": "application/x-www-form-urlencoded"}
*/
function generateAccessTokenV2(mac: auth.digest.Mac, requestURI: string, reqMethod: string, reqContentType: string, reqBody?: string, reqHeaders?: Record<string, string>): string;
/**
* 校验七牛上传回调的Authorization
* @param mac AK&SK对象
* @param requestURI 回调的URL中的requestURI
* @param reqBody 回调的URL中的requestURI 请求Body,仅当请求的ContentType为application/x-www-form-urlencoded时才需要传入该参数
* @param callbackAuth 回调时请求的Authorization头部值
*/
function isQiniuCallback(mac: auth.digest.Mac, requestURI: string, reqBody: string | null, callbackAuth: string): boolean;
}
export declare namespace httpc {
interface ReqOpts<T = any> {
agent?: HttpAgent;
httpsAgent?: HttpsAgent;
url: string;
middlewares?: middleware.Middleware[];
callback?: Callback<T>;
urllibOptions: RequestOptions;
}
// responseWrapper.js
interface ResponseWrapperOptions<T = any> {
data: T;
resp: IncomingMessage;
}
interface ResponseError {
error_code?: string,
error?: string,
}
class ResponseWrapper<T = any> {
data: T extends void ? undefined | ResponseError : T & ResponseError;
resp: IncomingMessage;
constructor(options: ResponseWrapperOptions);
ok(): boolean;
needRetry(): boolean;
}
// middleware package
namespace middleware {
interface Middleware {
send<T>(
request: ReqOpts<T>,
next: (reqOpts: ReqOpts<T>) => Promise<ResponseWrapper<T>>
): Promise<ResponseWrapper<T>>;
}
/**
* 组合中间件为一个调用函数
* @param middlewares 中间件列表
* @param handler 请求函数
*/
function composeMiddlewares<T>(
middlewares: Middleware[],
handler: (reqOpts: ReqOpts<T>) => Promise<ResponseWrapper<T>>
): (reqOpts: ReqOpts<T>) => Promise<ResponseWrapper<T>>;
/**
* 设置 User-Agent 请求头中间件
*/
class UserAgentMiddleware implements Middleware {
constructor(sdkVersion: string);
send<T>(
request: httpc.ReqOpts<T>,
next: (reqOpts: httpc.ReqOpts<T>) => Promise<httpc.ResponseWrapper<T>>
): Promise<httpc.ResponseWrapper<T>>;
}
interface RetryDomainsMiddlewareOptions {
backupDomains: string[];
maxRetryTimes: number;
retryCondition: () => boolean;
}
class RetryDomainsMiddleware implements Middleware {
/**
* 备用域名
*/
backupDomains: string[];
/**
* 最大重试次数,包括首次请求
*/
maxRetryTimes: number;
/**
* 是否可以重试,可以通过该函数配置更详细的重试规则
*/
retryCondition: () => boolean;
/**
* 已经重试的次数
* @private
*/
private _retriedTimes: number;
/**
* 实例化重试域名中间件
* @param retryDomainsOptions
*/
constructor(retryDomainsOptions: RetryDomainsMiddlewareOptions)
/**
* 重试域名中间件逻辑
* @param request
* @param next
*/
send<T>(
request: httpc.ReqOpts<T>,
next: (reqOpts: httpc.ReqOpts<T>) => Promise<httpc.ResponseWrapper<T>>
): Promise<httpc.ResponseWrapper<T>>;
/**
* 控制重试逻辑,主要为 {@link retryCondition} 服务。若没有设置 retryCondition,默认 2xx 才会终止重试
* @param err
* @param respWrapper
* @param reqOpts
* @private
*/
private _shouldRetry<T>(
err: Error | null,
respWrapper: ResponseWrapper<T>,
reqOpts: ReqOpts<T>
): boolean;
}
}
// client.js
interface HttpClientOptions {
httpAgent?: HttpAgent;
httpsAgent?: HttpsAgent;
middlewares?: middleware.Middleware[];
}
interface GetOptions<T = any> extends ReqOpts<T> {
params: Record<string, string>;
headers: Record<string, string>;
}
interface PostOptions<T = any> extends ReqOpts<T> {
data: string | Buffer | Readable;
headers: Record<string, string>;
}
interface PutOptions<T = any> extends ReqOpts<T> {
data: string | Buffer | Readable;
headers: Record<string, string>
}
class HttpClient {
httpAgent: HttpAgent;
httpsAgent: HttpsAgent;
middlewares: middleware.Middleware[];
constructor(options: HttpClientOptions)
sendRequest(requestOptions: ReqOpts): Promise<ResponseWrapper>
get(getOptions: GetOptions): Promise<ResponseWrapper>
post(postOptions: PostOptions): Promise<ResponseWrapper>
put(putOptions: PutOptions): Promise<ResponseWrapper>
}
// endpoint.js
interface EndpointOptions {
defaultScheme?: string;
}
interface EndpointPersistInfo {
host: string;
defaultScheme: string;
}
class Endpoint implements EndpointsProvider {
host: string;
defaultScheme: string;
constructor(host: string, options?: EndpointOptions);
getValue(options?: {scheme?: string}): string;
getEndpoints(): Promise<httpc.Endpoint[]>;
}
// region.js
enum SERVICE_NAME {
UC = 'uc',
UP = 'up',
IO = 'io',
RS = 'rs',
RSF = 'rsf',
API = 'api',
S3 = 's3'
}
interface RegionOptions {
regionId?: string;
s3RegionId?: string;
services?: Record<string, Endpoint[]>;
ttl?: number;
createTime?: Date;
}
interface RegionFromZoneOptions {
regionId?: string;
s3RegionId?: string;
ttl?: number;
preferredScheme?: 'http' | 'https' | string
isPreferCdnHost?: boolean;
}
interface RegionFromRegionIdOptions {
s3RegionId?: string;
ttl?: number;
createTime?: Date;
extendedServices?: Record<SERVICE_NAME | string, Endpoint[]>
preferredScheme?: 'http' | 'https' | string
isPreferCdnUpHost?: boolean
}
interface RegionPersistInfo {
regionId?: string;
s3RegionId?: string;
services: Record<SERVICE_NAME | string, EndpointPersistInfo[]>;
ttl: number;
createTime: number;
}
interface QueryRegionsRespData {
region: string;
ttl: number;
s3: {
domains: string[];
region_alias: string;
};
uc: {
domains: string[];
};
up: {
domains: string[];
};
io: {
domains: string[];
};
rs: {
domains: string[];
};
rsf: {
domains: string[];
};
api: {
domains: string[];
};
}
class Region implements RegionsProvider {
static fromZone(zone: conf.Zone, options?: RegionFromZoneOptions): Region;
static fromRegionId(regionId: string, options?: RegionFromRegionIdOptions): Region;
// non-unique
regionId?: string;
s3RegionId?: string;
services: Record<SERVICE_NAME | string, Endpoint[]>
ttl: number;
createTime: Date;
constructor(options: RegionOptions);
getRegions(): Promise<httpc.Region[]>;
get isLive(): boolean;
}
// endpointProvider.js
interface EndpointsProvider {
getEndpoints(): Promise<Endpoint[]>
}
interface MutableEndpointsProvider extends EndpointsProvider {
setEndpoints(endpoints: Endpoint[]): Promise<void>
}
class StaticEndpointsProvider implements EndpointsProvider {
static fromRegion(region: Region, serviceName: SERVICE_NAME | string): StaticEndpointsProvider;
constructor(endpoints: Endpoint[]);
getEndpoints(): Promise<Endpoint[]>;
}
// regionsProvider.js
interface RegionsProvider {
getRegions(): Promise<Region[]>
}
interface MutableRegionsProvider extends RegionsProvider {
setRegions(regions: Region[]): Promise<void>
}
// StaticRegionsProvider
class StaticRegionsProvider implements RegionsProvider {
regions: Region[];
constructor(regions: Region[]);
getRegions(): Promise<Region[]>;
}
// CachedRegionsProviderOptions
interface CachedRegionsProviderOptions {
cacheKey: string;
baseRegionsProvider: RegionsProvider;
persistPath?: string;
shrinkInterval?: number; // ms
}
class CachedRegionsProvider implements MutableRegionsProvider {
static cleanupCache(options: {
isClearAll?: boolean,
/**
* if instance is not passed, it will clean up the default scoop.
*/
instance?: CachedRegionsProvider,
}): Promise<void>
cacheKey: string;
baseRegionsProvider: RegionsProvider;
lastShrinkAt: Date;
shrinkInterval: number;
constructor(
options: CachedRegionsProviderOptions
);
setRegions(regions: Region[]): Promise<void>;
getRegions(): Promise<Region[]>;
}
// QueryRegionsProvider
interface QueryRegionsProviderOptions {
accessKey: string;
bucketName: string;
endpointsProvider: EndpointsProvider;
preferredScheme?: 'http' | 'https' | string;
}
class QueryRegionsProvider implements RegionsProvider {
accessKey: string;
bucketName: string;
endpointsProvider: EndpointsProvider;
constructor(options: QueryRegionsProviderOptions);
getRegions(): Promise<Region[]>;
}
}
export declare namespace rpc {
type Headers = Record<string, string> & {
'User-Agent'?: string;
Connection?: string;
}
interface RequestOptions {
headers: Headers;
mac: auth.digest.Mac;
}
const qnHttpClient: httpc.HttpClient;
/**
*
* @param requestUrl 请求地址
* @param headers 请求 headers
* @param callbackFunc 回调函数
*/
function get(requestUrl: string, headers: Headers | null, callbackFunc: callback): void;
/**
* @param requestUrl 请求地址
* @param options 请求的配置
* @param callbackFunc 回调函数
*/
function getWithOptions(
requestUrl: string,
options: RequestOptions | null,
callbackFunc: callback
): ReturnType<typeof get>;
/**
*
* @param requestUrl 请求地址
* @param token 请求认证签名
* @param callbackFunc 回调函数
*/
function getWithToken(requestUrl: string, token: string | null, callbackFunc: callback): void;
/**
*
* @param requestURI
* @param requestForm
* @param headers
* @param callback
*/
function post(requestURI: string, requestForm: Buffer | string | NodeJS.ReadableStream | null, headers: Headers | null, callback: callback): void;
/**
* @param requestUrl 请求地址
* @param requestForm 请求体
* @param options 请求的配置
* @param callbackFunc 回调函数
*/
function postWithOptions(
requestUrl: string,
requestForm: Buffer | string | NodeJS.ReadableStream | null,
options: RequestOptions | null,
callbackFunc: callback
): ReturnType<typeof post>;
/**
*
* @param requestURI
* @param requestForm
* @param callback
*/
function postMultipart(requestURI: string, requestForm: Buffer | string | NodeJS.ReadableStream | null, callback: callback): void;
/**
*
* @param requestURI
* @param requestForm
* @param token
* @param callback
*/
function postWithForm(requestURI: string, requestForm: Buffer | string | NodeJS.ReadableStream | null, token: string | null, callback: callback): void;
/**
*
* @param requestURI
* @param token
* @param callback
*/
function postWithoutForm(requestURI: string, token: string | null, callback: callback): void;
}
export declare namespace zone {
//huadong
const Zone_z0: conf.Zone;
//huadong2
const Zone_cn_east_2: conf.Zone;
//huabei
const Zone_z1: conf.Zone;
//huanan
const Zone_z2: conf.Zone;
//beimei
const Zone_na0: conf.Zone;
//Southeast Asia
const Zone_as0: conf.Zone;
}
export declare namespace fop {
interface PfopOptions {
/**
* 回调业务服务器,通知处理结果
*/
notifyURL?: string;
/**
* 结果是否强制覆盖已有的同名文件
*/
force?: boolean;
}
class OperationManager {
mac: auth.digest.Mac;
config: conf.Config;
constructor(mac?: auth.digest.Mac, config?: conf.Config);
/**
* 发送持久化数据处理请求
* @param bucket 空间名称
* @param key 文件名称
* @param fops 处理指令集合
* @param pipeline 处理队列名称
* @param options
* @param callback
*/
pfop(bucket: string, key: string, fops: string[], pipeline: string, options: PfopOptions | null, callback: callback): void;