ibm-cloud-sdk-core 2.17.14 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -0
- package/auth/authenticators/authenticator-interface.d.ts +1 -1
- package/auth/authenticators/authenticator.d.ts +1 -1
- package/auth/authenticators/basic-authenticator.d.ts +1 -1
- package/auth/authenticators/token-request-based-authenticator.d.ts +1 -1
- package/build/docs/ibm-cloud-sdk-core.authenticator.authenticate.md +2 -2
- package/build/docs/ibm-cloud-sdk-core.authenticatorinterface.authenticate.md +2 -2
- package/build/docs/ibm-cloud-sdk-core.basicauthenticator.authenticate.md +2 -2
- package/build/docs/ibm-cloud-sdk-core.buildrequestfileobject.md +2 -2
- package/build/docs/ibm-cloud-sdk-core.contenttype.md +1 -1
- package/build/docs/ibm-cloud-sdk-core.getcontenttype.md +2 -2
- package/build/docs/ibm-cloud-sdk-core.tokenrequestbasedauthenticator.authenticate.md +2 -2
- package/{docs → docs/ibm-cloud-sdk-core.api.json} +33 -51
- package/es/auth/authenticators/authenticator-interface.d.ts +1 -1
- package/es/auth/authenticators/authenticator.d.ts +1 -1
- package/es/auth/authenticators/basic-authenticator.d.ts +1 -1
- package/es/auth/authenticators/token-request-based-authenticator.d.ts +1 -1
- package/es/lib/content-type.d.ts +1 -1
- package/es/lib/helper.d.ts +2 -2
- package/es/lib/helper.js +62 -48
- package/es/lib/request-wrapper.js +3 -3
- package/etc/ibm-cloud-sdk-core.api.md +7 -7
- package/ibm-cloud-sdk-core.d.ts +7 -7
- package/lib/content-type.d.ts +1 -1
- package/lib/helper.d.ts +2 -2
- package/lib/helper.js +104 -50
- package/lib/request-wrapper.js +25 -16
- package/package.json +3 -3
- package/temp/ibm-cloud-sdk-core.api.json +33 -51
- package/temp/ibm-cloud-sdk-core.api.md +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,34 @@
|
|
|
1
|
+
## [3.0.1](https://github.com/IBM/node-sdk-core/compare/v3.0.0...v3.0.1) (2022-07-28)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* correct AuthenticatorInterface type ([#206](https://github.com/IBM/node-sdk-core/issues/206)) ([31dc7bd](https://github.com/IBM/node-sdk-core/commit/31dc7bd1e744a071cdabc2b5bf1e9513024079ac)), closes [#176](https://github.com/IBM/node-sdk-core/issues/176)
|
|
7
|
+
|
|
8
|
+
# [3.0.0](https://github.com/IBM/node-sdk-core/compare/v2.17.15...v3.0.0) (2022-07-28)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* update file-type to resolve vulnerability ([#205](https://github.com/IBM/node-sdk-core/issues/205)) ([843e66d](https://github.com/IBM/node-sdk-core/commit/843e66d10aeb43dc5a0f7c9583f93ce6a5dbaa7e)), closes [#204](https://github.com/IBM/node-sdk-core/issues/204)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### BREAKING CHANGES
|
|
17
|
+
|
|
18
|
+
* two synchronous public functions are now asynchronous
|
|
19
|
+
|
|
20
|
+
The function `getContentType` formerly returned a string but now returns a
|
|
21
|
+
Promise that resolves to a string. The function `buildRequestFileObject`
|
|
22
|
+
formerly returned a `FileObject` but now returns a Promise that resolves to
|
|
23
|
+
a `FileObject`.
|
|
24
|
+
|
|
25
|
+
## [2.17.15](https://github.com/IBM/node-sdk-core/compare/v2.17.14...v2.17.15) (2022-07-05)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Bug Fixes
|
|
29
|
+
|
|
30
|
+
* ensure dist/docs is a directory during build ([#202](https://github.com/IBM/node-sdk-core/issues/202)) ([1b3ef62](https://github.com/IBM/node-sdk-core/commit/1b3ef621e3cbfe0586d433269f63acf77dfa7251))
|
|
31
|
+
|
|
1
32
|
## [2.17.14](https://github.com/IBM/node-sdk-core/compare/v2.17.13...v2.17.14) (2022-05-02)
|
|
2
33
|
|
|
3
34
|
|
|
@@ -38,7 +38,7 @@ export interface AuthenticatorInterface {
|
|
|
38
38
|
* @param {object.<string, string>} requestOptions.headers The headers the
|
|
39
39
|
* authentication information will be added to.
|
|
40
40
|
*/
|
|
41
|
-
authenticate(requestOptions: AuthenticateOptions): Promise<void
|
|
41
|
+
authenticate(requestOptions: AuthenticateOptions): Promise<void>;
|
|
42
42
|
/**
|
|
43
43
|
* Returns a string that indicates the authentication type.
|
|
44
44
|
*/
|
|
@@ -46,7 +46,7 @@ export declare class Authenticator implements AuthenticatorInterface {
|
|
|
46
46
|
* @throws {Error} - The authenticate method was not implemented by a
|
|
47
47
|
* subclass.
|
|
48
48
|
*/
|
|
49
|
-
authenticate(requestOptions: AuthenticateOptions): Promise<void
|
|
49
|
+
authenticate(requestOptions: AuthenticateOptions): Promise<void>;
|
|
50
50
|
/**
|
|
51
51
|
* Retrieves the authenticator's type.
|
|
52
52
|
* The returned value will be the same string that is used
|
|
@@ -55,7 +55,7 @@ export declare class BasicAuthenticator extends Authenticator {
|
|
|
55
55
|
* @param {object.<string, string>} requestOptions.headers - The headers the
|
|
56
56
|
* authentication information will be added too.
|
|
57
57
|
*/
|
|
58
|
-
authenticate(requestOptions: AuthenticateOptions): Promise<void
|
|
58
|
+
authenticate(requestOptions: AuthenticateOptions): Promise<void>;
|
|
59
59
|
/**
|
|
60
60
|
* Returns the authenticator's type ('basic').
|
|
61
61
|
*
|
|
@@ -87,5 +87,5 @@ export declare class TokenRequestBasedAuthenticator extends Authenticator {
|
|
|
87
87
|
* authentication information will be added too. Overrides default headers
|
|
88
88
|
* where there's conflict.
|
|
89
89
|
*/
|
|
90
|
-
authenticate(requestOptions: AuthenticateOptions): Promise<void
|
|
90
|
+
authenticate(requestOptions: AuthenticateOptions): Promise<void>;
|
|
91
91
|
}
|
|
@@ -9,7 +9,7 @@ Augment the request with authentication information.
|
|
|
9
9
|
<b>Signature:</b>
|
|
10
10
|
|
|
11
11
|
```typescript
|
|
12
|
-
authenticate(requestOptions: AuthenticateOptions): Promise<void
|
|
12
|
+
authenticate(requestOptions: AuthenticateOptions): Promise<void>;
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
## Parameters
|
|
@@ -20,7 +20,7 @@ authenticate(requestOptions: AuthenticateOptions): Promise<void | Error>;
|
|
|
20
20
|
|
|
21
21
|
<b>Returns:</b>
|
|
22
22
|
|
|
23
|
-
Promise<void
|
|
23
|
+
Promise<void>
|
|
24
24
|
|
|
25
25
|
## Exceptions
|
|
26
26
|
|
|
@@ -9,7 +9,7 @@ Add authentication information to the specified request.
|
|
|
9
9
|
<b>Signature:</b>
|
|
10
10
|
|
|
11
11
|
```typescript
|
|
12
|
-
authenticate(requestOptions: AuthenticateOptions): Promise<void
|
|
12
|
+
authenticate(requestOptions: AuthenticateOptions): Promise<void>;
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
## Parameters
|
|
@@ -20,5 +20,5 @@ authenticate(requestOptions: AuthenticateOptions): Promise<void | Error>;
|
|
|
20
20
|
|
|
21
21
|
<b>Returns:</b>
|
|
22
22
|
|
|
23
|
-
Promise<void
|
|
23
|
+
Promise<void>
|
|
24
24
|
|
|
@@ -11,7 +11,7 @@ Authorization: Basic <<!-- -->encoded username and password<!-- -->>
|
|
|
11
11
|
<b>Signature:</b>
|
|
12
12
|
|
|
13
13
|
```typescript
|
|
14
|
-
authenticate(requestOptions: AuthenticateOptions): Promise<void
|
|
14
|
+
authenticate(requestOptions: AuthenticateOptions): Promise<void>;
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
## Parameters
|
|
@@ -22,5 +22,5 @@ authenticate(requestOptions: AuthenticateOptions): Promise<void | Error>;
|
|
|
22
22
|
|
|
23
23
|
<b>Returns:</b>
|
|
24
24
|
|
|
25
|
-
Promise<void
|
|
25
|
+
Promise<void>
|
|
26
26
|
|
|
@@ -9,7 +9,7 @@ This function builds a `form-data` object for each file parameter.
|
|
|
9
9
|
<b>Signature:</b>
|
|
10
10
|
|
|
11
11
|
```typescript
|
|
12
|
-
export declare function buildRequestFileObject(fileParam: FileWithMetadata): FileObject
|
|
12
|
+
export declare function buildRequestFileObject(fileParam: FileWithMetadata): Promise<FileObject>;
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
## Parameters
|
|
@@ -20,7 +20,7 @@ export declare function buildRequestFileObject(fileParam: FileWithMetadata): Fil
|
|
|
20
20
|
|
|
21
21
|
<b>Returns:</b>
|
|
22
22
|
|
|
23
|
-
[FileObject](./ibm-cloud-sdk-core.fileobject.md)
|
|
23
|
+
Promise<[FileObject](./ibm-cloud-sdk-core.fileobject.md)<!-- -->>
|
|
24
24
|
|
|
25
25
|
{<!-- -->FileObject<!-- -->}
|
|
26
26
|
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
```typescript
|
|
10
10
|
_default: {
|
|
11
|
-
fromFilename: (file: String | File |
|
|
11
|
+
fromFilename: (file: String | File | FileObject | NodeJS.ReadableStream | Buffer) => string;
|
|
12
12
|
fromHeader: (buffer: Buffer) => string;
|
|
13
13
|
}
|
|
14
14
|
```
|
|
@@ -9,7 +9,7 @@ This function retrieves the content type of the input.
|
|
|
9
9
|
<b>Signature:</b>
|
|
10
10
|
|
|
11
11
|
```typescript
|
|
12
|
-
export declare function getContentType(inputData: NodeJS.ReadableStream | Buffer): string
|
|
12
|
+
export declare function getContentType(inputData: NodeJS.ReadableStream | Buffer): Promise<string>;
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
## Parameters
|
|
@@ -20,7 +20,7 @@ export declare function getContentType(inputData: NodeJS.ReadableStream | Buffer
|
|
|
20
20
|
|
|
21
21
|
<b>Returns:</b>
|
|
22
22
|
|
|
23
|
-
string
|
|
23
|
+
Promise<string>
|
|
24
24
|
|
|
25
25
|
{<!-- -->string<!-- -->} the content type of the input.
|
|
26
26
|
|
|
@@ -11,7 +11,7 @@ Authorization: Bearer <bearer-token>
|
|
|
11
11
|
<b>Signature:</b>
|
|
12
12
|
|
|
13
13
|
```typescript
|
|
14
|
-
authenticate(requestOptions: AuthenticateOptions): Promise<void
|
|
14
|
+
authenticate(requestOptions: AuthenticateOptions): Promise<void>;
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
## Parameters
|
|
@@ -22,5 +22,5 @@ authenticate(requestOptions: AuthenticateOptions): Promise<void | Error>;
|
|
|
22
22
|
|
|
23
23
|
<b>Returns:</b>
|
|
24
24
|
|
|
25
|
-
Promise<void
|
|
25
|
+
Promise<void>
|
|
26
26
|
|
|
@@ -350,16 +350,7 @@
|
|
|
350
350
|
},
|
|
351
351
|
{
|
|
352
352
|
"kind": "Content",
|
|
353
|
-
"text": "<void
|
|
354
|
-
},
|
|
355
|
-
{
|
|
356
|
-
"kind": "Reference",
|
|
357
|
-
"text": "Error",
|
|
358
|
-
"canonicalReference": "!Error:interface"
|
|
359
|
-
},
|
|
360
|
-
{
|
|
361
|
-
"kind": "Content",
|
|
362
|
-
"text": ">"
|
|
353
|
+
"text": "<void>"
|
|
363
354
|
},
|
|
364
355
|
{
|
|
365
356
|
"kind": "Content",
|
|
@@ -370,7 +361,7 @@
|
|
|
370
361
|
"isStatic": false,
|
|
371
362
|
"returnTypeTokenRange": {
|
|
372
363
|
"startIndex": 3,
|
|
373
|
-
"endIndex":
|
|
364
|
+
"endIndex": 5
|
|
374
365
|
},
|
|
375
366
|
"releaseTag": "Public",
|
|
376
367
|
"overloadIndex": 1,
|
|
@@ -677,16 +668,7 @@
|
|
|
677
668
|
},
|
|
678
669
|
{
|
|
679
670
|
"kind": "Content",
|
|
680
|
-
"text": "<void
|
|
681
|
-
},
|
|
682
|
-
{
|
|
683
|
-
"kind": "Reference",
|
|
684
|
-
"text": "Error",
|
|
685
|
-
"canonicalReference": "!Error:interface"
|
|
686
|
-
},
|
|
687
|
-
{
|
|
688
|
-
"kind": "Content",
|
|
689
|
-
"text": ">"
|
|
671
|
+
"text": "<void>"
|
|
690
672
|
},
|
|
691
673
|
{
|
|
692
674
|
"kind": "Content",
|
|
@@ -696,7 +678,7 @@
|
|
|
696
678
|
"isOptional": false,
|
|
697
679
|
"returnTypeTokenRange": {
|
|
698
680
|
"startIndex": 3,
|
|
699
|
-
"endIndex":
|
|
681
|
+
"endIndex": 5
|
|
700
682
|
},
|
|
701
683
|
"releaseTag": "Public",
|
|
702
684
|
"overloadIndex": 1,
|
|
@@ -1280,16 +1262,7 @@
|
|
|
1280
1262
|
},
|
|
1281
1263
|
{
|
|
1282
1264
|
"kind": "Content",
|
|
1283
|
-
"text": "<void
|
|
1284
|
-
},
|
|
1285
|
-
{
|
|
1286
|
-
"kind": "Reference",
|
|
1287
|
-
"text": "Error",
|
|
1288
|
-
"canonicalReference": "!Error:interface"
|
|
1289
|
-
},
|
|
1290
|
-
{
|
|
1291
|
-
"kind": "Content",
|
|
1292
|
-
"text": ">"
|
|
1265
|
+
"text": "<void>"
|
|
1293
1266
|
},
|
|
1294
1267
|
{
|
|
1295
1268
|
"kind": "Content",
|
|
@@ -1300,7 +1273,7 @@
|
|
|
1300
1273
|
"isStatic": false,
|
|
1301
1274
|
"returnTypeTokenRange": {
|
|
1302
1275
|
"startIndex": 3,
|
|
1303
|
-
"endIndex":
|
|
1276
|
+
"endIndex": 5
|
|
1304
1277
|
},
|
|
1305
1278
|
"releaseTag": "Public",
|
|
1306
1279
|
"overloadIndex": 1,
|
|
@@ -1639,11 +1612,24 @@
|
|
|
1639
1612
|
"kind": "Content",
|
|
1640
1613
|
"text": "): "
|
|
1641
1614
|
},
|
|
1615
|
+
{
|
|
1616
|
+
"kind": "Reference",
|
|
1617
|
+
"text": "Promise",
|
|
1618
|
+
"canonicalReference": "!Promise:interface"
|
|
1619
|
+
},
|
|
1620
|
+
{
|
|
1621
|
+
"kind": "Content",
|
|
1622
|
+
"text": "<"
|
|
1623
|
+
},
|
|
1642
1624
|
{
|
|
1643
1625
|
"kind": "Reference",
|
|
1644
1626
|
"text": "FileObject",
|
|
1645
1627
|
"canonicalReference": "ibm-cloud-sdk-core!FileObject:interface"
|
|
1646
1628
|
},
|
|
1629
|
+
{
|
|
1630
|
+
"kind": "Content",
|
|
1631
|
+
"text": ">"
|
|
1632
|
+
},
|
|
1647
1633
|
{
|
|
1648
1634
|
"kind": "Content",
|
|
1649
1635
|
"text": ";"
|
|
@@ -1651,7 +1637,7 @@
|
|
|
1651
1637
|
],
|
|
1652
1638
|
"returnTypeTokenRange": {
|
|
1653
1639
|
"startIndex": 3,
|
|
1654
|
-
"endIndex":
|
|
1640
|
+
"endIndex": 7
|
|
1655
1641
|
},
|
|
1656
1642
|
"releaseTag": "Public",
|
|
1657
1643
|
"overloadIndex": 1,
|
|
@@ -2589,8 +2575,8 @@
|
|
|
2589
2575
|
},
|
|
2590
2576
|
{
|
|
2591
2577
|
"kind": "Reference",
|
|
2592
|
-
"text": "
|
|
2593
|
-
"canonicalReference": "!
|
|
2578
|
+
"text": "FileObject",
|
|
2579
|
+
"canonicalReference": "ibm-cloud-sdk-core!FileObject:interface"
|
|
2594
2580
|
},
|
|
2595
2581
|
{
|
|
2596
2582
|
"kind": "Content",
|
|
@@ -2607,8 +2593,8 @@
|
|
|
2607
2593
|
},
|
|
2608
2594
|
{
|
|
2609
2595
|
"kind": "Reference",
|
|
2610
|
-
"text": "
|
|
2611
|
-
"canonicalReference": "
|
|
2596
|
+
"text": "Buffer",
|
|
2597
|
+
"canonicalReference": "!Buffer:interface"
|
|
2612
2598
|
},
|
|
2613
2599
|
{
|
|
2614
2600
|
"kind": "Content",
|
|
@@ -3185,9 +3171,14 @@
|
|
|
3185
3171
|
"kind": "Content",
|
|
3186
3172
|
"text": "): "
|
|
3187
3173
|
},
|
|
3174
|
+
{
|
|
3175
|
+
"kind": "Reference",
|
|
3176
|
+
"text": "Promise",
|
|
3177
|
+
"canonicalReference": "!Promise:interface"
|
|
3178
|
+
},
|
|
3188
3179
|
{
|
|
3189
3180
|
"kind": "Content",
|
|
3190
|
-
"text": "string"
|
|
3181
|
+
"text": "<string>"
|
|
3191
3182
|
},
|
|
3192
3183
|
{
|
|
3193
3184
|
"kind": "Content",
|
|
@@ -3196,7 +3187,7 @@
|
|
|
3196
3187
|
],
|
|
3197
3188
|
"returnTypeTokenRange": {
|
|
3198
3189
|
"startIndex": 5,
|
|
3199
|
-
"endIndex":
|
|
3190
|
+
"endIndex": 7
|
|
3200
3191
|
},
|
|
3201
3192
|
"releaseTag": "Public",
|
|
3202
3193
|
"overloadIndex": 1,
|
|
@@ -5892,16 +5883,7 @@
|
|
|
5892
5883
|
},
|
|
5893
5884
|
{
|
|
5894
5885
|
"kind": "Content",
|
|
5895
|
-
"text": "<void
|
|
5896
|
-
},
|
|
5897
|
-
{
|
|
5898
|
-
"kind": "Reference",
|
|
5899
|
-
"text": "Error",
|
|
5900
|
-
"canonicalReference": "!Error:interface"
|
|
5901
|
-
},
|
|
5902
|
-
{
|
|
5903
|
-
"kind": "Content",
|
|
5904
|
-
"text": ">"
|
|
5886
|
+
"text": "<void>"
|
|
5905
5887
|
},
|
|
5906
5888
|
{
|
|
5907
5889
|
"kind": "Content",
|
|
@@ -5912,7 +5894,7 @@
|
|
|
5912
5894
|
"isStatic": false,
|
|
5913
5895
|
"returnTypeTokenRange": {
|
|
5914
5896
|
"startIndex": 3,
|
|
5915
|
-
"endIndex":
|
|
5897
|
+
"endIndex": 5
|
|
5916
5898
|
},
|
|
5917
5899
|
"releaseTag": "Public",
|
|
5918
5900
|
"overloadIndex": 1,
|
|
@@ -38,7 +38,7 @@ export interface AuthenticatorInterface {
|
|
|
38
38
|
* @param {object.<string, string>} requestOptions.headers The headers the
|
|
39
39
|
* authentication information will be added to.
|
|
40
40
|
*/
|
|
41
|
-
authenticate(requestOptions: AuthenticateOptions): Promise<void
|
|
41
|
+
authenticate(requestOptions: AuthenticateOptions): Promise<void>;
|
|
42
42
|
/**
|
|
43
43
|
* Returns a string that indicates the authentication type.
|
|
44
44
|
*/
|
|
@@ -46,7 +46,7 @@ export declare class Authenticator implements AuthenticatorInterface {
|
|
|
46
46
|
* @throws {Error} - The authenticate method was not implemented by a
|
|
47
47
|
* subclass.
|
|
48
48
|
*/
|
|
49
|
-
authenticate(requestOptions: AuthenticateOptions): Promise<void
|
|
49
|
+
authenticate(requestOptions: AuthenticateOptions): Promise<void>;
|
|
50
50
|
/**
|
|
51
51
|
* Retrieves the authenticator's type.
|
|
52
52
|
* The returned value will be the same string that is used
|
|
@@ -55,7 +55,7 @@ export declare class BasicAuthenticator extends Authenticator {
|
|
|
55
55
|
* @param {object.<string, string>} requestOptions.headers - The headers the
|
|
56
56
|
* authentication information will be added too.
|
|
57
57
|
*/
|
|
58
|
-
authenticate(requestOptions: AuthenticateOptions): Promise<void
|
|
58
|
+
authenticate(requestOptions: AuthenticateOptions): Promise<void>;
|
|
59
59
|
/**
|
|
60
60
|
* Returns the authenticator's type ('basic').
|
|
61
61
|
*
|
|
@@ -87,5 +87,5 @@ export declare class TokenRequestBasedAuthenticator extends Authenticator {
|
|
|
87
87
|
* authentication information will be added too. Overrides default headers
|
|
88
88
|
* where there's conflict.
|
|
89
89
|
*/
|
|
90
|
-
authenticate(requestOptions: AuthenticateOptions): Promise<void
|
|
90
|
+
authenticate(requestOptions: AuthenticateOptions): Promise<void>;
|
|
91
91
|
}
|
package/es/lib/content-type.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { FileObject } from "./helper";
|
|
3
3
|
declare const _default: {
|
|
4
|
-
fromFilename: (file: String | File |
|
|
4
|
+
fromFilename: (file: String | File | FileObject | NodeJS.ReadableStream | Buffer) => string;
|
|
5
5
|
fromHeader: (buffer: Buffer) => string;
|
|
6
6
|
};
|
|
7
7
|
export default _default;
|
package/es/lib/helper.d.ts
CHANGED
|
@@ -38,7 +38,7 @@ export declare function isEmptyObject(obj: any): boolean;
|
|
|
38
38
|
* @param {NodeJS.ReadableStream|Buffer} inputData - The data to retrieve content type for.
|
|
39
39
|
* @returns {string} the content type of the input.
|
|
40
40
|
*/
|
|
41
|
-
export declare function getContentType(inputData: NodeJS.ReadableStream | Buffer): string
|
|
41
|
+
export declare function getContentType(inputData: NodeJS.ReadableStream | Buffer): Promise<string>;
|
|
42
42
|
/**
|
|
43
43
|
*
|
|
44
44
|
* @param {string} url - the url string.
|
|
@@ -104,7 +104,7 @@ export declare function getFormat(params: {
|
|
|
104
104
|
* @param {string} fileParam.contentType The content type of the file.
|
|
105
105
|
* @returns {FileObject}
|
|
106
106
|
*/
|
|
107
|
-
export declare function buildRequestFileObject(fileParam: FileWithMetadata): FileObject
|
|
107
|
+
export declare function buildRequestFileObject(fileParam: FileWithMetadata): Promise<FileObject>;
|
|
108
108
|
/**
|
|
109
109
|
* This function converts an object's keys to lower case.
|
|
110
110
|
* note: does not convert nested keys
|
package/es/lib/helper.js
CHANGED
|
@@ -13,11 +13,20 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
17
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
18
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
19
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
20
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
21
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
22
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
23
|
+
});
|
|
24
|
+
};
|
|
17
25
|
import { isReadable } from 'isstream';
|
|
18
26
|
import { lookup } from 'mime-types';
|
|
19
27
|
import { basename } from 'path';
|
|
20
28
|
import logger from './logger';
|
|
29
|
+
const FileType = require('file-type');
|
|
21
30
|
// custom type guards
|
|
22
31
|
function isFileObject(obj) {
|
|
23
32
|
return Boolean(obj && obj.value);
|
|
@@ -40,17 +49,19 @@ export function isEmptyObject(obj) {
|
|
|
40
49
|
* @returns {string} the content type of the input.
|
|
41
50
|
*/
|
|
42
51
|
export function getContentType(inputData) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
let contentType = null;
|
|
54
|
+
if (isFileStream(inputData)) {
|
|
55
|
+
// if the inputData is a NodeJS.ReadableStream
|
|
56
|
+
const mimeType = lookup(inputData.path); // TODO: cleue quick hack, per type definition path could also be a Buffer
|
|
57
|
+
contentType = { mime: mimeType || null };
|
|
58
|
+
}
|
|
59
|
+
else if (Buffer.isBuffer(inputData)) {
|
|
60
|
+
// if the inputData is a Buffer
|
|
61
|
+
contentType = yield FileType.fromBuffer(inputData);
|
|
62
|
+
}
|
|
63
|
+
return contentType ? contentType.mime : null;
|
|
64
|
+
});
|
|
54
65
|
}
|
|
55
66
|
/**
|
|
56
67
|
*
|
|
@@ -198,44 +209,47 @@ export function getFormat(params, formats) {
|
|
|
198
209
|
* @returns {FileObject}
|
|
199
210
|
*/
|
|
200
211
|
export function buildRequestFileObject(fileParam) {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
212
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
213
|
+
let fileObj;
|
|
214
|
+
if (isFileObject(fileParam.data)) {
|
|
215
|
+
// For backward compatibility, we allow the data to be a FileObject.
|
|
216
|
+
fileObj = { value: fileParam.data.value, options: {} };
|
|
217
|
+
if (fileParam.data.options) {
|
|
218
|
+
fileObj.options = {
|
|
219
|
+
filename: fileParam.filename || fileParam.data.options.filename,
|
|
220
|
+
contentType: fileParam.contentType || fileParam.data.options.contentType,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
fileObj = {
|
|
226
|
+
value: fileParam.data,
|
|
227
|
+
options: {
|
|
228
|
+
filename: fileParam.filename,
|
|
229
|
+
contentType: fileParam.contentType,
|
|
230
|
+
},
|
|
209
231
|
};
|
|
210
232
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
fileObj.
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
}
|
|
232
|
-
// toString handles the case when path is a buffer
|
|
233
|
-
fileObj.options.filename = filename ? basename(filename.toString()) : '_';
|
|
234
|
-
// build contentType
|
|
235
|
-
if (!fileObj.options.contentType && isFileData(fileObj.value)) {
|
|
236
|
-
fileObj.options.contentType = getContentType(fileObj.value) || 'application/octet-stream';
|
|
237
|
-
}
|
|
238
|
-
return fileObj;
|
|
233
|
+
// Also for backward compatibility, we allow data to be a string
|
|
234
|
+
if (typeof fileObj.value === 'string') {
|
|
235
|
+
fileObj.value = Buffer.from(fileObj.value);
|
|
236
|
+
}
|
|
237
|
+
// build filename
|
|
238
|
+
// eslint-disable-next-line prefer-destructuring
|
|
239
|
+
let filename = fileObj.options.filename;
|
|
240
|
+
if (!filename && isFileStream(fileObj.value)) {
|
|
241
|
+
// if readable stream with path property
|
|
242
|
+
filename = fileObj.value.path;
|
|
243
|
+
}
|
|
244
|
+
// toString handles the case when path is a buffer
|
|
245
|
+
fileObj.options.filename = filename ? basename(filename.toString()) : '_';
|
|
246
|
+
// build contentType
|
|
247
|
+
if (!fileObj.options.contentType && isFileData(fileObj.value)) {
|
|
248
|
+
fileObj.options.contentType =
|
|
249
|
+
(yield getContentType(fileObj.value)) || 'application/octet-stream';
|
|
250
|
+
}
|
|
251
|
+
return fileObj;
|
|
252
|
+
});
|
|
239
253
|
}
|
|
240
254
|
/**
|
|
241
255
|
* This function converts an object's keys to lower case.
|
|
@@ -135,14 +135,14 @@ export class RequestWrapper {
|
|
|
135
135
|
// Skip keys with undefined/null values or empty object value
|
|
136
136
|
values
|
|
137
137
|
.filter((v) => v != null && !isEmptyObject(v))
|
|
138
|
-
.forEach((value) => {
|
|
138
|
+
.forEach((value) => __awaiter(this, void 0, void 0, function* () {
|
|
139
139
|
// Special case of empty file object
|
|
140
140
|
if (Object.prototype.hasOwnProperty.call(value, 'contentType') &&
|
|
141
141
|
!Object.prototype.hasOwnProperty.call(value, 'data')) {
|
|
142
142
|
return;
|
|
143
143
|
}
|
|
144
144
|
if (isFileWithMetadata(value)) {
|
|
145
|
-
const fileObj = buildRequestFileObject(value);
|
|
145
|
+
const fileObj = yield buildRequestFileObject(value);
|
|
146
146
|
multipartForm.append(key, fileObj.value, fileObj.options);
|
|
147
147
|
}
|
|
148
148
|
else {
|
|
@@ -151,7 +151,7 @@ export class RequestWrapper {
|
|
|
151
151
|
}
|
|
152
152
|
multipartForm.append(key, value);
|
|
153
153
|
}
|
|
154
|
-
});
|
|
154
|
+
}));
|
|
155
155
|
});
|
|
156
156
|
}
|
|
157
157
|
// Path params
|