@ibm-cloud/cloudant
Advanced tools
Comparing version 0.0.17 to 0.0.18
@@ -62,2 +62,6 @@ /** | ||
private configureSessionAuthenticator; | ||
/** | ||
* Extend createRequest to handle document and attachment validation. | ||
*/ | ||
protected createRequest(parameters: any): Promise<any>; | ||
} |
@@ -39,3 +39,52 @@ "use strict"; | ||
var common_1 = require("./common"); | ||
var DocumentOperations = [ | ||
'deleteDocument', | ||
'getDocument', | ||
'headDocument', | ||
'putDocument', | ||
'deleteAttachment', | ||
'getAttachment', | ||
'headAttachment', | ||
'putAttachment', | ||
]; | ||
var AttachmentOperations = [ | ||
'deleteAttachment', | ||
'getAttachment', | ||
'headAttachment', | ||
'putAttachment', | ||
]; | ||
var docIdRule = { | ||
pathSegment: 'doc_id', | ||
errorParameterName: 'Document ID', | ||
operationIds: DocumentOperations, | ||
}; | ||
var attIdRule = { | ||
pathSegment: 'attachment_name', | ||
errorParameterName: 'Attachment name', | ||
operationIds: AttachmentOperations, | ||
}; | ||
var validationRules = [docIdRule, attIdRule]; | ||
var rulesByOperation = {}; | ||
for (var _i = 0, validationRules_1 = validationRules; _i < validationRules_1.length; _i++) { | ||
var rule = validationRules_1[_i]; | ||
for (var _a = 0, _b = rule.operationIds; _a < _b.length; _a++) { | ||
var operationId = _b[_a]; | ||
if (!(operationId in rulesByOperation)) { | ||
rulesByOperation[operationId] = []; | ||
} | ||
rulesByOperation[operationId].push(rule); | ||
} | ||
} | ||
Object.freeze(rulesByOperation); | ||
/** | ||
* Extend Error interface to access the proper Error definition. | ||
*/ | ||
var InvalidArgumentValueError = /** @class */ (function (_super) { | ||
__extends(InvalidArgumentValueError, _super); | ||
function InvalidArgumentValueError() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
return InvalidArgumentValueError; | ||
}(Error)); | ||
/** | ||
* Cloudant specific service that extends the base service functions. | ||
@@ -118,2 +167,36 @@ * | ||
}; | ||
/** | ||
* Extend createRequest to handle document and attachment validation. | ||
*/ | ||
CloudantBaseService.prototype.createRequest = function (parameters) { | ||
var operationId = null; | ||
if ('X-IBMCloud-SDK-Analytics' in parameters['defaultOptions']['headers']) { | ||
// Extract operation id | ||
var analyticsHeader = parameters['defaultOptions']['headers']['X-IBMCloud-SDK-Analytics']; | ||
for (var _i = 0, _a = analyticsHeader.split(';'); _i < _a.length; _i++) { | ||
var element = _a[_i]; | ||
if (element.startsWith('operation_id')) { | ||
operationId = element.split('=')[1]; | ||
} | ||
} | ||
// Check if operation id exists in rulesByOperation object | ||
if (operationId != null && | ||
Object.keys(rulesByOperation).includes(operationId)) { | ||
for (var _b = 0, _c = rulesByOperation[operationId]; _b < _c.length; _b++) { | ||
var rule = _c[_b]; | ||
// get the path segment e.g. doc_id from the response's path object | ||
if ('path' in parameters['options'] && | ||
rule.pathSegment in parameters['options']['path']) { | ||
var segmentToValidate = parameters['options']['path'][rule.pathSegment]; | ||
if (segmentToValidate.startsWith('_')) { | ||
var err = new InvalidArgumentValueError(rule.errorParameterName + " " + segmentToValidate + " starts with the invalid _ character."); | ||
err.code = 'ERR_INVALID_ARG_VALUE'; | ||
return Promise.reject(err); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return _super.prototype.createRequest.call(this, parameters); | ||
}; | ||
return CloudantBaseService; | ||
@@ -120,0 +203,0 @@ }(ibm_cloud_sdk_core_1.BaseService)); |
{ | ||
"name": "@ibm-cloud/cloudant", | ||
"version": "0.0.17", | ||
"version": "0.0.18", | ||
"description": "IBM Cloudant Node.js SDK", | ||
@@ -38,3 +38,3 @@ "main": "index.js", | ||
"extend": "^3.0.2", | ||
"ibm-cloud-sdk-core": "~2.11.0" | ||
"ibm-cloud-sdk-core": "~2.13.0" | ||
}, | ||
@@ -41,0 +41,0 @@ "jest": { |
@@ -5,3 +5,3 @@ [![Build Status](https://travis-ci.com/IBM/cloudant-node-sdk.svg?branch=master)](https://travis-ci.com/IBM/cloudant-node-sdk) | ||
# IBM Cloudant Node.js SDK Version 0.0.17 | ||
# IBM Cloudant Node.js SDK Version 0.0.18 | ||
@@ -8,0 +8,0 @@ IBM Cloudant Node.js SDK is a client library that interacts with the |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
924235
13995
+ Addedibm-cloud-sdk-core@2.13.0(transitive)
- Removedibm-cloud-sdk-core@2.11.3(transitive)
Updatedibm-cloud-sdk-core@~2.13.0