@prismatic-io/spectral 8.0.5 → 8.0.7

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.
@@ -51,6 +51,7 @@ const lodash_1 = require("lodash");
51
51
  const axios_1 = __importDefault(require("axios"));
52
52
  const axios_retry_1 = __importStar(require("axios-retry"));
53
53
  const form_data_1 = __importDefault(require("form-data"));
54
+ const object_sizeof_1 = __importDefault(require("object-sizeof"));
54
55
  const __1 = require("../..");
55
56
  const util_1 = __importDefault(require("../../util"));
56
57
  const inputs_1 = require("./inputs");
@@ -103,11 +104,33 @@ const createClient = ({ baseUrl, responseType, headers, timeout, params, debug =
103
104
  });
104
105
  if (debug) {
105
106
  client.interceptors.request.use((request) => {
106
- console.log(util_1.default.types.toJSON(request));
107
+ const { baseURL, headers, method, timeout, url, data } = request;
108
+ const dataSize = (0, object_sizeof_1.default)(data);
109
+ console.log(util_1.default.types.toJSON({
110
+ type: "request",
111
+ baseURL,
112
+ url,
113
+ headers,
114
+ method,
115
+ timeout,
116
+ data: dataSize > 1024 * 10 || Buffer.isBuffer(data)
117
+ ? `<data (${dataSize} bytes)>`
118
+ : data,
119
+ }, true, true));
107
120
  return request;
108
121
  });
109
122
  client.interceptors.response.use((response) => {
110
- console.log(util_1.default.types.toJSON(response));
123
+ const { headers, status, statusText, data } = response;
124
+ const dataSize = (0, object_sizeof_1.default)(data);
125
+ console.log(util_1.default.types.toJSON({
126
+ type: "response",
127
+ headers,
128
+ status,
129
+ statusText,
130
+ data: dataSize > 1024 * 10 || Buffer.isBuffer(data)
131
+ ? `<data (${dataSize} bytes)>`
132
+ : data,
133
+ }, true, true));
111
134
  return response;
112
135
  });
113
136
  }
package/dist/index.js CHANGED
@@ -33,7 +33,14 @@ const convertIntegration_1 = require("./serverTypes/convertIntegration");
33
33
  * @param definition An IntegrationDefinition type object.
34
34
  * @returns This function returns an integration object that has the shape the Prismatic API expects.
35
35
  */
36
- const integration = (definition) => (0, convertIntegration_1.convertIntegration)(definition);
36
+ const integration = (definition) => {
37
+ var _a;
38
+ const integrationDefinition = (0, convertIntegration_1.convertIntegration)(definition);
39
+ if (((_a = process.env) === null || _a === void 0 ? void 0 : _a.DEBUG) === "true") {
40
+ console.info(integrationDefinition.codeNativeIntegrationYAML);
41
+ }
42
+ return integrationDefinition;
43
+ };
37
44
  exports.integration = integration;
38
45
  /**
39
46
  * For information on writing Code Native Integrations, see
@@ -132,11 +132,14 @@ const convertConfigVar = (key, configVar, referenceKey) => {
132
132
  component: { key: referenceKey, version: "LATEST", isPublic: false },
133
133
  key: (0, lodash_1.camelCase)(key),
134
134
  }, inputs: Object.entries(configVar.inputs).reduce((result, [key, input]) => {
135
- var _a;
136
135
  if (input.shown === false) {
137
136
  return result;
138
137
  }
139
- const value = ((_a = input.default) !== null && _a !== void 0 ? _a : input.collection) ? [] : "";
138
+ const value = input.default
139
+ ? input.default
140
+ : input.collection
141
+ ? []
142
+ : "";
140
143
  return Object.assign(Object.assign({}, result), { [key]: { type: "value", value } });
141
144
  }, {}), meta });
142
145
  }
package/dist/util.d.ts CHANGED
@@ -45,7 +45,7 @@ declare const _default: {
45
45
  toString: (value: unknown, defaultValue?: string) => string;
46
46
  keyValPairListToObject: <TValue = unknown>(kvpList: KeyValuePair<unknown>[], valueConverter?: ((value: unknown) => TValue) | undefined) => Record<string, TValue>;
47
47
  isJSON: (value: string) => boolean;
48
- toJSON: (value: unknown) => string;
48
+ toJSON: (value: unknown, prettyPrint?: boolean, retainKeyOrder?: boolean) => string;
49
49
  lowerCaseHeaders: (headers: Record<string, string>) => Record<string, string>;
50
50
  isObjectSelection: (value: unknown) => value is ObjectSelection;
51
51
  toObjectSelection: (value: unknown) => ObjectSelection;
@@ -58,6 +58,7 @@ declare const _default: {
58
58
  isConnection: (value: unknown) => value is ConnectionDefinition;
59
59
  isElement: (value: unknown) => value is Element;
60
60
  toObject: (value: unknown) => object;
61
+ cleanObject: (obj: Record<string, unknown>, predicate?: ((v: any) => boolean) | undefined) => import("lodash").Dictionary<unknown>;
61
62
  };
62
63
  };
63
64
  export default _default;
package/dist/util.js CHANGED
@@ -14,6 +14,7 @@ const parseISO_1 = __importDefault(require("date-fns/parseISO"));
14
14
  const isValid_1 = __importDefault(require("date-fns/isValid"));
15
15
  const isDate_1 = __importDefault(require("date-fns/isDate"));
16
16
  const fromUnixTime_1 = __importDefault(require("date-fns/fromUnixTime"));
17
+ const lodash_1 = require("lodash");
17
18
  const safe_stable_stringify_1 = require("safe-stable-stringify");
18
19
  const valid_url_1 = require("valid-url");
19
20
  const isObjectWithTruthyKeys = (value, keys) => {
@@ -457,11 +458,16 @@ const isJSON = (value) => {
457
458
  * This function accepts an arbitrary object/value and safely serializes it (handles cyclic references).
458
459
  *
459
460
  * @param value Arbitrary object/value to serialize.
461
+ * @param prettyPrint When true, convert to pretty printed JSON with 2 spaces and newlines. When false, JSON is compact.
462
+ * @param retainKeyOrder When true, the order of keys in the JSON output will be the same as the order in the input object.
460
463
  * @returns JSON serialized text that can be safely logged.
461
464
  */
462
- const toJSON = (value) => {
463
- const stringify = (0, safe_stable_stringify_1.configure)({ circularValue: undefined });
464
- return stringify(value, null, 2);
465
+ const toJSON = (value, prettyPrint = true, retainKeyOrder = false) => {
466
+ const stringify = (0, safe_stable_stringify_1.configure)({
467
+ circularValue: undefined,
468
+ deterministic: !retainKeyOrder,
469
+ });
470
+ return prettyPrint ? stringify(value, null, 2) : stringify(value);
465
471
  };
466
472
  /**
467
473
  * This function returns a lower cased version of the headers passed to it.
@@ -494,6 +500,21 @@ const toObject = (value) => {
494
500
  }
495
501
  };
496
502
  exports.toObject = toObject;
503
+ /**
504
+ * This function removes any properties of an object that match a certain predicate.
505
+ * By default properties with values of undefined, null and "" are removed.
506
+ *
507
+ * - `cleanObject({foo: undefined, bar: "abc", baz: null, buz: ""})` will return `{bar: "abc"}`
508
+ * - `cleanObject({foo: 1, bar: 2, baz: 3}, v => v % 2 === 0)` will filter even number values, returning `{foo: 1, baz: 3}`
509
+ *
510
+ * @param obj A key-value object to remove properties from
511
+ * @param predicate A function that returns true for properties to remove. Defaults to removing properties with undefined, null and "" values.
512
+ * @returns An object with certain properties removed
513
+ */
514
+ const cleanObject = (obj, predicate) => {
515
+ const defaultPredicate = (v) => v === undefined || v === null || v === "";
516
+ return (0, lodash_1.omitBy)(obj, predicate || defaultPredicate);
517
+ };
497
518
  exports.default = {
498
519
  types: {
499
520
  isBool,
@@ -528,5 +549,6 @@ exports.default = {
528
549
  isConnection,
529
550
  isElement,
530
551
  toObject: exports.toObject,
552
+ cleanObject,
531
553
  },
532
554
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismatic-io/spectral",
3
- "version": "8.0.5",
3
+ "version": "8.0.7",
4
4
  "description": "Utility library for building Prismatic components",
5
5
  "keywords": [
6
6
  "prismatic"
@@ -44,6 +44,7 @@
44
44
  "form-data": "4.0.0",
45
45
  "jest-mock": "27.0.3",
46
46
  "lodash": "4.17.21",
47
+ "object-sizeof": "^2.6.4",
47
48
  "safe-stable-stringify": "2.3.1",
48
49
  "serialize-error": "8.1.0",
49
50
  "url-join": "5.0.0",