@ibm-cloud/cloudant 0.0.14 → 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.
@@ -22,6 +22,8 @@ var __extends = (this && this.__extends) || (function () {
22
22
  return extendStatics(d, b);
23
23
  };
24
24
  return function (d, b) {
25
+ if (typeof b !== "function" && b !== null)
26
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
25
27
  extendStatics(d, b);
26
28
  function __() { this.constructor = d; }
27
29
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
@@ -34,6 +36,55 @@ var ibm_cloud_sdk_core_1 = require("ibm-cloud-sdk-core");
34
36
  var tough_cookie_1 = require("tough-cookie");
35
37
  var auth_1 = require("../auth");
36
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));
37
88
  /**
38
89
  * Cloudant specific service that extends the base service functions.
39
90
  *
@@ -92,7 +143,6 @@ var CloudantBaseService = /** @class */ (function (_super) {
92
143
  CloudantBaseService.prototype.setEnableGzipCompression = function (setting) {
93
144
  // Read external configuration and set as request defaults.
94
145
  _super.prototype.setEnableGzipCompression.call(this, setting);
95
- this.baseOptions.enableGzipCompression = setting;
96
146
  this.configureSessionAuthenticator();
97
147
  };
98
148
  /**
@@ -113,6 +163,40 @@ var CloudantBaseService = /** @class */ (function (_super) {
113
163
  auth.configure(this.baseOptions);
114
164
  }
115
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
+ };
116
200
  return CloudantBaseService;
117
201
  }(ibm_cloud_sdk_core_1.BaseService));
118
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,sDAAwB,GAA/B,UAAgC,OAAgB;QAC9C,2DAA2D;QAC3D,iBAAM,wBAAwB,YAAC,OAAO,CAAC,CAAC;QACxC,IA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kD,gCAAW,GAoH5D;AApHqB,kDAAmB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ibm-cloud/cloudant",
3
- "version": "0.0.14",
3
+ "version": "0.0.18",
4
4
  "description": "IBM Cloudant Node.js SDK",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -26,18 +26,16 @@
26
26
  "test-integration": "npm run build && jest test/integration",
27
27
  "test-travis": "jest --runInBand --testNamePattern='^((?!@slow).)*$' test/",
28
28
  "test-unit-travis": "jest --runInBand test/unit/",
29
- "test-integration-travis": "jest --runInBand --no-colors --testNamePattern='^((?!@slow).)*$' --json test/integration > test-output.log",
30
- "report-coverage": "codecov",
31
- "check-packages": "installed-check -e -d -v"
29
+ "test-integration-travis": "jest --runInBand --no-colors --testNamePattern='^((?!@slow).)*$' --json test/integration > test-output.log"
32
30
  },
33
31
  "license": "Apache-2.0",
34
32
  "engines": {
35
- "node": ">=10.0.0"
33
+ "node": "^12 || ^14 || ^16"
36
34
  },
37
35
  "dependencies": {
38
- "@types/node": "^14.14.7",
36
+ "@types/node": "^16.0.0",
39
37
  "extend": "^3.0.2",
40
- "ibm-cloud-sdk-core": "~2.8.0"
38
+ "ibm-cloud-sdk-core": "~2.13.0"
41
39
  },
42
40
  "jest": {
43
41
  "collectCoverage": true,