Socket
Socket
Sign inDemoInstall

ibm-cloud-sdk-core

Package Overview
Dependencies
Maintainers
3
Versions
144
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ibm-cloud-sdk-core - npm Package Compare versions

Comparing version 2.17.15 to 3.0.0

4

build/docs/ibm-cloud-sdk-core.buildrequestfileobject.md

@@ -12,3 +12,3 @@ <!-- Do not edit this file. It is automatically generated by API Documenter. -->

```typescript
export declare function buildRequestFileObject(fileParam: FileWithMetadata): FileObject;
export declare function buildRequestFileObject(fileParam: FileWithMetadata): Promise<FileObject>;
```

@@ -24,5 +24,5 @@

[FileObject](./ibm-cloud-sdk-core.fileobject.md)
Promise&lt;[FileObject](./ibm-cloud-sdk-core.fileobject.md)<!-- -->&gt;
{<!-- -->FileObject<!-- -->}

@@ -11,5 +11,5 @@ <!-- Do not edit this file. It is automatically generated by API Documenter. -->

_default: {
fromFilename: (file: String | File | Buffer | NodeJS.ReadableStream | FileObject) => string;
fromFilename: (file: String | File | FileObject | NodeJS.ReadableStream | Buffer) => string;
fromHeader: (buffer: Buffer) => string;
}
```

@@ -12,3 +12,3 @@ <!-- Do not edit this file. It is automatically generated by API Documenter. -->

```typescript
export declare function getContentType(inputData: NodeJS.ReadableStream | Buffer): string;
export declare function getContentType(inputData: NodeJS.ReadableStream | Buffer): Promise<string>;
```

@@ -24,5 +24,5 @@

string
Promise&lt;string&gt;
{<!-- -->string<!-- -->} the content type of the input.

@@ -0,1 +1,18 @@

# [3.0.0](https://github.com/IBM/node-sdk-core/compare/v2.17.15...v3.0.0) (2022-07-28)
### Bug Fixes
* 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)
### BREAKING CHANGES
* two synchronous public functions are now asynchronous
The function `getContentType` formerly returned a string but now returns a
Promise that resolves to a string. The function `buildRequestFileObject`
formerly returned a `FileObject` but now returns a Promise that resolves to
a `FileObject`.
## [2.17.15](https://github.com/IBM/node-sdk-core/compare/v2.17.14...v2.17.15) (2022-07-05)

@@ -2,0 +19,0 @@

/// <reference types="node" />
import { FileObject } from "./helper";
declare const _default: {
fromFilename: (file: String | File | Buffer | NodeJS.ReadableStream | FileObject) => string;
fromFilename: (file: String | File | FileObject | NodeJS.ReadableStream | Buffer) => string;
fromHeader: (buffer: Buffer) => string;
};
export default _default;

@@ -41,3 +41,3 @@ /**

*/
export declare function getContentType(inputData: NodeJS.ReadableStream | Buffer): string;
export declare function getContentType(inputData: NodeJS.ReadableStream | Buffer): Promise<string>;
/**

@@ -108,3 +108,3 @@ *

*/
export declare function buildRequestFileObject(fileParam: FileWithMetadata): FileObject;
export declare function buildRequestFileObject(fileParam: FileWithMetadata): Promise<FileObject>;
/**

@@ -111,0 +111,0 @@ * This function converts an object's keys to lower case.

@@ -16,3 +16,11 @@ /**

*/
import fileType from 'file-type';
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { isReadable } from 'isstream';

@@ -22,2 +30,3 @@ import { lookup } from 'mime-types';

import logger from './logger';
const FileType = require('file-type');
// custom type guards

@@ -45,13 +54,15 @@ function isFileObject(obj) {

export function getContentType(inputData) {
let contentType = null;
if (isFileStream(inputData)) {
// if the inputData is a NodeJS.ReadableStream
const mimeType = lookup(inputData.path); // TODO: cleue quick hack, per type definition path could also be a Buffer
contentType = { mime: mimeType || null };
}
else if (Buffer.isBuffer(inputData)) {
// if the inputData is a Buffer
contentType = fileType(inputData);
}
return contentType ? contentType.mime : null;
return __awaiter(this, void 0, void 0, function* () {
let contentType = null;
if (isFileStream(inputData)) {
// if the inputData is a NodeJS.ReadableStream
const mimeType = lookup(inputData.path); // TODO: cleue quick hack, per type definition path could also be a Buffer
contentType = { mime: mimeType || null };
}
else if (Buffer.isBuffer(inputData)) {
// if the inputData is a Buffer
contentType = yield FileType.fromBuffer(inputData);
}
return contentType ? contentType.mime : null;
});
}

@@ -204,40 +215,43 @@ /**

export function buildRequestFileObject(fileParam) {
let fileObj;
if (isFileObject(fileParam.data)) {
// For backward compatibility, we allow the data to be a FileObject.
fileObj = { value: fileParam.data.value, options: {} };
if (fileParam.data.options) {
fileObj.options = {
filename: fileParam.filename || fileParam.data.options.filename,
contentType: fileParam.contentType || fileParam.data.options.contentType,
return __awaiter(this, void 0, void 0, function* () {
let fileObj;
if (isFileObject(fileParam.data)) {
// For backward compatibility, we allow the data to be a FileObject.
fileObj = { value: fileParam.data.value, options: {} };
if (fileParam.data.options) {
fileObj.options = {
filename: fileParam.filename || fileParam.data.options.filename,
contentType: fileParam.contentType || fileParam.data.options.contentType,
};
}
}
else {
fileObj = {
value: fileParam.data,
options: {
filename: fileParam.filename,
contentType: fileParam.contentType,
},
};
}
}
else {
fileObj = {
value: fileParam.data,
options: {
filename: fileParam.filename,
contentType: fileParam.contentType,
},
};
}
// Also for backward compatibility, we allow data to be a string
if (typeof fileObj.value === 'string') {
fileObj.value = Buffer.from(fileObj.value);
}
// build filename
// eslint-disable-next-line prefer-destructuring
let filename = fileObj.options.filename;
if (!filename && isFileStream(fileObj.value)) {
// if readable stream with path property
filename = fileObj.value.path;
}
// toString handles the case when path is a buffer
fileObj.options.filename = filename ? basename(filename.toString()) : '_';
// build contentType
if (!fileObj.options.contentType && isFileData(fileObj.value)) {
fileObj.options.contentType = getContentType(fileObj.value) || 'application/octet-stream';
}
return fileObj;
// Also for backward compatibility, we allow data to be a string
if (typeof fileObj.value === 'string') {
fileObj.value = Buffer.from(fileObj.value);
}
// build filename
// eslint-disable-next-line prefer-destructuring
let filename = fileObj.options.filename;
if (!filename && isFileStream(fileObj.value)) {
// if readable stream with path property
filename = fileObj.value.path;
}
// toString handles the case when path is a buffer
fileObj.options.filename = filename ? basename(filename.toString()) : '_';
// build contentType
if (!fileObj.options.contentType && isFileData(fileObj.value)) {
fileObj.options.contentType =
(yield getContentType(fileObj.value)) || 'application/octet-stream';
}
return fileObj;
});
}

@@ -244,0 +258,0 @@ /**

@@ -138,3 +138,3 @@ /* eslint-disable class-methods-use-this */

.filter((v) => v != null && !isEmptyObject(v))
.forEach((value) => {
.forEach((value) => __awaiter(this, void 0, void 0, function* () {
// Special case of empty file object

@@ -146,3 +146,3 @@ if (Object.prototype.hasOwnProperty.call(value, 'contentType') &&

if (isFileWithMetadata(value)) {
const fileObj = buildRequestFileObject(value);
const fileObj = yield buildRequestFileObject(value);
multipartForm.append(key, fileObj.value, fileObj.options);

@@ -156,3 +156,3 @@ }

}
});
}));
});

@@ -159,0 +159,0 @@ }

@@ -97,3 +97,3 @@ ## API Report File for "ibm-cloud-sdk-core"

// @public
export function buildRequestFileObject(fileParam: FileWithMetadata): FileObject;
export function buildRequestFileObject(fileParam: FileWithMetadata): Promise<FileObject>;

@@ -159,3 +159,3 @@ // @public

export const contentType: {
fromFilename: (file: String | File | Buffer | NodeJS.ReadableStream | FileObject) => string;
fromFilename: (file: String | File | FileObject | NodeJS.ReadableStream | Buffer) => string;
fromHeader: (buffer: Buffer) => string;

@@ -216,3 +216,3 @@ };

// @public
export function getContentType(inputData: NodeJS.ReadableStream | Buffer): string;
export function getContentType(inputData: NodeJS.ReadableStream | Buffer): Promise<string>;

@@ -219,0 +219,0 @@ // @public

/// <reference types="node" />
import { FileObject } from "./helper";
declare const _default: {
fromFilename: (file: String | File | Buffer | NodeJS.ReadableStream | FileObject) => string;
fromFilename: (file: String | File | FileObject | NodeJS.ReadableStream | Buffer) => string;
fromHeader: (buffer: Buffer) => string;
};
export default _default;

@@ -41,3 +41,3 @@ /**

*/
export declare function getContentType(inputData: NodeJS.ReadableStream | Buffer): string;
export declare function getContentType(inputData: NodeJS.ReadableStream | Buffer): Promise<string>;
/**

@@ -108,3 +108,3 @@ *

*/
export declare function buildRequestFileObject(fileParam: FileWithMetadata): FileObject;
export declare function buildRequestFileObject(fileParam: FileWithMetadata): Promise<FileObject>;
/**

@@ -111,0 +111,0 @@ * This function converts an object's keys to lower case.

@@ -17,2 +17,38 @@ "use strict";

*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __spreadArrays = (this && this.__spreadArrays) || function () {

@@ -29,3 +65,2 @@ for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;

Object.defineProperty(exports, "__esModule", { value: true });
var file_type_1 = __importDefault(require("file-type"));
var isstream_1 = require("isstream");

@@ -35,2 +70,3 @@ var mime_types_1 = require("mime-types");

var logger_1 = __importDefault(require("./logger"));
var FileType = require('file-type');
// custom type guards

@@ -61,13 +97,23 @@ function isFileObject(obj) {

function getContentType(inputData) {
var contentType = null;
if (isFileStream(inputData)) {
// if the inputData is a NodeJS.ReadableStream
var mimeType = mime_types_1.lookup(inputData.path); // TODO: cleue quick hack, per type definition path could also be a Buffer
contentType = { mime: mimeType || null };
}
else if (Buffer.isBuffer(inputData)) {
// if the inputData is a Buffer
contentType = file_type_1.default(inputData);
}
return contentType ? contentType.mime : null;
return __awaiter(this, void 0, void 0, function () {
var contentType, mimeType;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
contentType = null;
if (!isFileStream(inputData)) return [3 /*break*/, 1];
mimeType = mime_types_1.lookup(inputData.path);
contentType = { mime: mimeType || null };
return [3 /*break*/, 3];
case 1:
if (!Buffer.isBuffer(inputData)) return [3 /*break*/, 3];
return [4 /*yield*/, FileType.fromBuffer(inputData)];
case 2:
// if the inputData is a Buffer
contentType = _a.sent();
_a.label = 3;
case 3: return [2 /*return*/, contentType ? contentType.mime : null];
}
});
});
}

@@ -227,40 +273,48 @@ exports.getContentType = getContentType;

function buildRequestFileObject(fileParam) {
var fileObj;
if (isFileObject(fileParam.data)) {
// For backward compatibility, we allow the data to be a FileObject.
fileObj = { value: fileParam.data.value, options: {} };
if (fileParam.data.options) {
fileObj.options = {
filename: fileParam.filename || fileParam.data.options.filename,
contentType: fileParam.contentType || fileParam.data.options.contentType,
};
}
}
else {
fileObj = {
value: fileParam.data,
options: {
filename: fileParam.filename,
contentType: fileParam.contentType,
},
};
}
// Also for backward compatibility, we allow data to be a string
if (typeof fileObj.value === 'string') {
fileObj.value = Buffer.from(fileObj.value);
}
// build filename
// eslint-disable-next-line prefer-destructuring
var filename = fileObj.options.filename;
if (!filename && isFileStream(fileObj.value)) {
// if readable stream with path property
filename = fileObj.value.path;
}
// toString handles the case when path is a buffer
fileObj.options.filename = filename ? path_1.basename(filename.toString()) : '_';
// build contentType
if (!fileObj.options.contentType && isFileData(fileObj.value)) {
fileObj.options.contentType = getContentType(fileObj.value) || 'application/octet-stream';
}
return fileObj;
return __awaiter(this, void 0, void 0, function () {
var fileObj, filename, _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
if (isFileObject(fileParam.data)) {
// For backward compatibility, we allow the data to be a FileObject.
fileObj = { value: fileParam.data.value, options: {} };
if (fileParam.data.options) {
fileObj.options = {
filename: fileParam.filename || fileParam.data.options.filename,
contentType: fileParam.contentType || fileParam.data.options.contentType,
};
}
}
else {
fileObj = {
value: fileParam.data,
options: {
filename: fileParam.filename,
contentType: fileParam.contentType,
},
};
}
// Also for backward compatibility, we allow data to be a string
if (typeof fileObj.value === 'string') {
fileObj.value = Buffer.from(fileObj.value);
}
filename = fileObj.options.filename;
if (!filename && isFileStream(fileObj.value)) {
// if readable stream with path property
filename = fileObj.value.path;
}
// toString handles the case when path is a buffer
fileObj.options.filename = filename ? path_1.basename(filename.toString()) : '_';
if (!(!fileObj.options.contentType && isFileData(fileObj.value))) return [3 /*break*/, 2];
_a = fileObj.options;
return [4 /*yield*/, getContentType(fileObj.value)];
case 1:
_a.contentType =
(_b.sent()) || 'application/octet-stream';
_b.label = 2;
case 2: return [2 /*return*/, fileObj];
}
});
});
}

@@ -267,0 +321,0 @@ exports.buildRequestFileObject = buildRequestFileObject;

@@ -194,19 +194,28 @@ "use strict";

.filter(function (v) { return v != null && !helper_1.isEmptyObject(v); })
.forEach(function (value) {
// Special case of empty file object
if (Object.prototype.hasOwnProperty.call(value, 'contentType') &&
!Object.prototype.hasOwnProperty.call(value, 'data')) {
return;
}
if (helper_1.isFileWithMetadata(value)) {
var fileObj = helper_1.buildRequestFileObject(value);
multipartForm.append(key, fileObj.value, fileObj.options);
}
else {
if (typeof value === 'object' && !helper_1.isFileData(value)) {
value = JSON.stringify(value);
.forEach(function (value) { return __awaiter(_this, void 0, void 0, function () {
var fileObj;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
// Special case of empty file object
if (Object.prototype.hasOwnProperty.call(value, 'contentType') &&
!Object.prototype.hasOwnProperty.call(value, 'data')) {
return [2 /*return*/];
}
if (!helper_1.isFileWithMetadata(value)) return [3 /*break*/, 2];
return [4 /*yield*/, helper_1.buildRequestFileObject(value)];
case 1:
fileObj = _a.sent();
multipartForm.append(key, fileObj.value, fileObj.options);
return [3 /*break*/, 3];
case 2:
if (typeof value === 'object' && !helper_1.isFileData(value)) {
value = JSON.stringify(value);
}
multipartForm.append(key, value);
_a.label = 3;
case 3: return [2 /*return*/];
}
multipartForm.append(key, value);
}
});
});
}); });
});

@@ -213,0 +222,0 @@ }

{
"name": "ibm-cloud-sdk-core",
"version": "2.17.15",
"version": "3.0.0",
"description": "Core functionality to support SDKs generated with IBM's OpenAPI SDK Generator.",

@@ -52,3 +52,3 @@ "main": "index.js",

"extend": "^3.0.2",
"file-type": "^7.7.1",
"file-type": "16.5.4",
"form-data": "^2.3.3",

@@ -55,0 +55,0 @@ "isstream": "~0.1.2",

@@ -97,3 +97,3 @@ ## API Report File for "ibm-cloud-sdk-core"

// @public
export function buildRequestFileObject(fileParam: FileWithMetadata): FileObject;
export function buildRequestFileObject(fileParam: FileWithMetadata): Promise<FileObject>;

@@ -159,3 +159,3 @@ // @public

export const contentType: {
fromFilename: (file: String | File | Buffer | NodeJS.ReadableStream | FileObject) => string;
fromFilename: (file: String | File | FileObject | NodeJS.ReadableStream | Buffer) => string;
fromHeader: (buffer: Buffer) => string;

@@ -216,3 +216,3 @@ };

// @public
export function getContentType(inputData: NodeJS.ReadableStream | Buffer): string;
export function getContentType(inputData: NodeJS.ReadableStream | Buffer): Promise<string>;

@@ -219,0 +219,0 @@ // @public

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc