@ibm-cloud/cloudant 0.0.17 → 0.0.18

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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
  [![Release](https://img.shields.io/github/v/release/IBM/cloudant-node-sdk?include_prereleases&sort=semver)](https://github.com/IBM/cloudant-node-sdk/releases/latest)
3
3
  [![Docs](https://img.shields.io/static/v1?label=TypeDoc&message=latest&color=blue)](https://ibm.github.io/cloudant-node-sdk/)
4
4
 
5
- # IBM Cloudant Node.js SDK Version 0.0.17
5
+ # IBM Cloudant Node.js SDK Version 0.0.18
6
6
 
7
7
  IBM Cloudant Node.js SDK is a client library that interacts with the
8
8
  [IBM Cloudant APIs](https://cloud.ibm.com/apidocs/cloudant?code=node).
@@ -59,4 +59,8 @@ export declare abstract class CloudantBaseService extends BaseService {
59
59
  * the service options should be applied on it.
60
60
  */
61
61
  private configureSessionAuthenticator;
62
+ /**
63
+ * Extend createRequest to handle document and attachment validation.
64
+ */
65
+ protected createRequest(parameters: any): Promise<any>;
62
66
  }
@@ -36,6 +36,55 @@ var ibm_cloud_sdk_core_1 = require("ibm-cloud-sdk-core");
36
36
  var tough_cookie_1 = require("tough-cookie");
37
37
  var auth_1 = require("../auth");
38
38
  var common_1 = require("./common");
39
+ var DocumentOperations = [
40
+ 'deleteDocument',
41
+ 'getDocument',
42
+ 'headDocument',
43
+ 'putDocument',
44
+ 'deleteAttachment',
45
+ 'getAttachment',
46
+ 'headAttachment',
47
+ 'putAttachment',
48
+ ];
49
+ var AttachmentOperations = [
50
+ 'deleteAttachment',
51
+ 'getAttachment',
52
+ 'headAttachment',
53
+ 'putAttachment',
54
+ ];
55
+ var docIdRule = {
56
+ pathSegment: 'doc_id',
57
+ errorParameterName: 'Document ID',
58
+ operationIds: DocumentOperations,
59
+ };
60
+ var attIdRule = {
61
+ pathSegment: 'attachment_name',
62
+ errorParameterName: 'Attachment name',
63
+ operationIds: AttachmentOperations,
64
+ };
65
+ var validationRules = [docIdRule, attIdRule];
66
+ var rulesByOperation = {};
67
+ for (var _i = 0, validationRules_1 = validationRules; _i < validationRules_1.length; _i++) {
68
+ var rule = validationRules_1[_i];
69
+ for (var _a = 0, _b = rule.operationIds; _a < _b.length; _a++) {
70
+ var operationId = _b[_a];
71
+ if (!(operationId in rulesByOperation)) {
72
+ rulesByOperation[operationId] = [];
73
+ }
74
+ rulesByOperation[operationId].push(rule);
75
+ }
76
+ }
77
+ Object.freeze(rulesByOperation);
78
+ /**
79
+ * Extend Error interface to access the proper Error definition.
80
+ */
81
+ var InvalidArgumentValueError = /** @class */ (function (_super) {
82
+ __extends(InvalidArgumentValueError, _super);
83
+ function InvalidArgumentValueError() {
84
+ return _super !== null && _super.apply(this, arguments) || this;
85
+ }
86
+ return InvalidArgumentValueError;
87
+ }(Error));
39
88
  /**
40
89
  * Cloudant specific service that extends the base service functions.
41
90
  *
@@ -114,6 +163,40 @@ var CloudantBaseService = /** @class */ (function (_super) {
114
163
  auth.configure(this.baseOptions);
115
164
  }
116
165
  };
166
+ /**
167
+ * Extend createRequest to handle document and attachment validation.
168
+ */
169
+ CloudantBaseService.prototype.createRequest = function (parameters) {
170
+ var operationId = null;
171
+ if ('X-IBMCloud-SDK-Analytics' in parameters['defaultOptions']['headers']) {
172
+ // Extract operation id
173
+ var analyticsHeader = parameters['defaultOptions']['headers']['X-IBMCloud-SDK-Analytics'];
174
+ for (var _i = 0, _a = analyticsHeader.split(';'); _i < _a.length; _i++) {
175
+ var element = _a[_i];
176
+ if (element.startsWith('operation_id')) {
177
+ operationId = element.split('=')[1];
178
+ }
179
+ }
180
+ // Check if operation id exists in rulesByOperation object
181
+ if (operationId != null &&
182
+ Object.keys(rulesByOperation).includes(operationId)) {
183
+ for (var _b = 0, _c = rulesByOperation[operationId]; _b < _c.length; _b++) {
184
+ var rule = _c[_b];
185
+ // get the path segment e.g. doc_id from the response's path object
186
+ if ('path' in parameters['options'] &&
187
+ rule.pathSegment in parameters['options']['path']) {
188
+ var segmentToValidate = parameters['options']['path'][rule.pathSegment];
189
+ if (segmentToValidate.startsWith('_')) {
190
+ var err = new InvalidArgumentValueError(rule.errorParameterName + " " + segmentToValidate + " starts with the invalid _ character.");
191
+ err.code = 'ERR_INVALID_ARG_VALUE';
192
+ return Promise.reject(err);
193
+ }
194
+ }
195
+ }
196
+ }
197
+ }
198
+ return _super.prototype.createRequest.call(this, parameters);
199
+ };
117
200
  return CloudantBaseService;
118
201
  }(ibm_cloud_sdk_core_1.BaseService));
119
202
  exports.CloudantBaseService = CloudantBaseService;
@@ -1 +1 @@
1
- {"version":3,"file":"cloudantBaseService.js","sourceRoot":"","sources":["../../lib/cloudantBaseService.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;;AAEH,yDAA6E;AAC7E,sDAAsD;AACtD,6CAAyC;AACzC,gCAAsD;AACtD,mCAAyC;AAEzC;;;;;GAKG;AACH;IAAkD,uCAAW;IAC3D;;;;;;OAMG;IACH,6BAAY,WAAwB;QAApC,iBAMC;QALC,IAAI,WAAW,CAAC,aAAa,YAAY,kCAA2B,EAAE;YACpE,WAAW,CAAC,GAAG,GAAG,WAAW,CAAC,GAAG,IAAI,IAAI,wBAAS,EAAE,CAAC;SACtD;QACD,QAAA,kBAAM,WAAW,CAAC,SAAC;QACnB,KAAI,CAAC,6BAA6B,EAAE,CAAC;;IACvC,CAAC;IAED;;;;;;OAMG;IACI,2CAAa,GAApB,UAAqB,GAAW;QAC9B,iBAAM,aAAa,YAAC,GAAG,CAAC,CAAC;QACzB,IAAI,CAAC,6BAA6B,EAAE,CAAC;IACvC,CAAC;IAED;;;;;;;OAOG;IACO,8CAAgB,GAA1B,UAA2B,WAAmB;QAC5C,2DAA2D;QAC3D,iBAAM,gBAAgB,YAAC,WAAW,CAAC,CAAC;QACpC,IAAI,CAAC,6BAA6B,EAAE,CAAC;IACvC,CAAC;IAED;;;;;;OAMG;IACI,sDA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,CAAC;IACH,0BAAC;AAAD,CAAC,AApHD,CAAkD,gCAAW,GAoH5D;AApHqB,kDAAmB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ibm-cloud/cloudant",
3
- "version": "0.0.17",
3
+ "version": "0.0.18",
4
4
  "description": "IBM Cloudant Node.js SDK",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -35,7 +35,7 @@
35
35
  "dependencies": {
36
36
  "@types/node": "^16.0.0",
37
37
  "extend": "^3.0.2",
38
- "ibm-cloud-sdk-core": "~2.11.0"
38
+ "ibm-cloud-sdk-core": "~2.13.0"
39
39
  },
40
40
  "jest": {
41
41
  "collectCoverage": true,