@vtex/api 6.45.5 → 6.45.8

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/CHANGELOG.md CHANGED
@@ -7,6 +7,24 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [6.45.8] - 2022-02-25
11
+
12
+ ### Fixed
13
+
14
+ - Remove only cookie fields when cleaning logs.
15
+
16
+ ## [6.45.7] - 2022-02-23
17
+
18
+ ### Fixed
19
+
20
+ - Remove sensitive data from logs.
21
+
22
+ ## [6.45.6] - 2021-10-26
23
+
24
+ ### Fixed
25
+
26
+ - `vtex_segment` cookie extraction
27
+
10
28
  ## [6.54.5] - 2021-10-22
11
29
 
12
30
  ### Fixed
@@ -30,7 +30,7 @@ export declare class Segment extends JanusClient {
30
30
  getSegmentByToken: (token: string | null, tracingConfig?: RequestTracingConfig | undefined) => Promise<SegmentData>;
31
31
  getOrCreateSegment: (query?: Record<string, string> | undefined, token?: string | undefined, tracingConfig?: RequestTracingConfig | undefined) => Promise<{
32
32
  segmentData: SegmentData;
33
- segmentToken: string | undefined;
33
+ segmentToken: string | null;
34
34
  }>;
35
35
  private rawSegment;
36
36
  }
@@ -1,10 +1,14 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ const cookie_1 = __importDefault(require("cookie"));
3
7
  const ramda_1 = require("ramda");
4
8
  const constants_1 = require("../../constants");
5
9
  const HttpClient_1 = require("../../HttpClient");
6
10
  const JanusClient_1 = require("./JanusClient");
7
- const Session_1 = require("./Session");
11
+ const SEGMENT_COOKIE = 'vtex_segment';
8
12
  const SEGMENT_MAX_AGE_S = 60 * 60; // 60 minutes - segment is actually immutable
9
13
  const ALLOWED_QUERY_PREFIXES = ['utm', 'cultureInfo', 'supportedLocales', '__bindingId'];
10
14
  const filterAndSortQuery = (query) => {
@@ -21,7 +25,7 @@ const filterAndSortQuery = (query) => {
21
25
  };
22
26
  const routes = {
23
27
  base: '/api/segments',
24
- segments: (token) => token ? `${routes.base}/${token}` : routes.base,
28
+ segments: (token) => (token ? `${routes.base}/${token}` : routes.base),
25
29
  };
26
30
  class Segment extends JanusClient_1.JanusClient {
27
31
  constructor() {
@@ -39,17 +43,17 @@ class Segment extends JanusClient_1.JanusClient {
39
43
  */
40
44
  this.getSegmentByToken = (token, tracingConfig) => this.rawSegment(token, undefined, tracingConfig).then(ramda_1.prop('data'));
41
45
  this.getOrCreateSegment = async (query, token, tracingConfig) => {
42
- const { data: segmentData, headers, } = await this.rawSegment(token, query, tracingConfig);
46
+ const { data: segmentData, headers } = await this.rawSegment(token, query, tracingConfig);
43
47
  return {
44
48
  segmentData,
45
- segmentToken: Session_1.extractSessionCookie(headers) || token,
49
+ segmentToken: extractSegmentCookie(headers),
46
50
  };
47
51
  };
48
52
  this.rawSegment = (token, query, tracingConfig) => {
49
53
  const { product, workspace } = this.context;
50
54
  const filteredQuery = filterAndSortQuery(query);
51
55
  const metric = token ? 'segment-get-token' : 'segment-get-new';
52
- return this.http.getRaw(routes.segments(token), ({
56
+ return this.http.getRaw(routes.segments(token), {
53
57
  forceMaxAge: SEGMENT_MAX_AGE_S,
54
58
  headers: {
55
59
  'Content-Type': 'application/json',
@@ -66,8 +70,19 @@ class Segment extends JanusClient_1.JanusClient {
66
70
  requestSpanNameSuffix: metric,
67
71
  ...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing,
68
72
  },
69
- }));
73
+ });
70
74
  };
71
75
  }
72
76
  }
73
77
  exports.Segment = Segment;
78
+ function extractSegmentCookie(headers) {
79
+ var _a;
80
+ for (const setCookie of (_a = headers['set-cookie']) !== null && _a !== void 0 ? _a : []) {
81
+ const parsedCookie = cookie_1.default.parse(setCookie);
82
+ const segmentCookie = parsedCookie[SEGMENT_COOKIE];
83
+ if (segmentCookie != null) {
84
+ return segmentCookie;
85
+ }
86
+ }
87
+ return null;
88
+ }
@@ -13,4 +13,3 @@ export declare class Session extends JanusClient {
13
13
  */
14
14
  updateSession: (key: string, value: any, items: string[], token: any, tracingConfig?: RequestTracingConfig | undefined) => Promise<void>;
15
15
  }
16
- export declare function extractSessionCookie(headers: Record<string, string>): string | null;
@@ -21,7 +21,7 @@ class Session extends JanusClient_1.JanusClient {
21
21
  const { data: sessionData, headers } = await this.http.getRaw(routes.base, {
22
22
  headers: {
23
23
  'Content-Type': 'application/json',
24
- 'Cookie': `vtex_session=${token};`,
24
+ Cookie: `vtex_session=${token};`,
25
25
  },
26
26
  metric,
27
27
  params: {
@@ -46,7 +46,7 @@ class Session extends JanusClient_1.JanusClient {
46
46
  const config = {
47
47
  headers: {
48
48
  'Content-Type': 'application/json',
49
- 'Cookie': `vtex_session=${token};`,
49
+ Cookie: `vtex_session=${token};`,
50
50
  },
51
51
  metric,
52
52
  params: {
@@ -73,4 +73,3 @@ function extractSessionCookie(headers) {
73
73
  }
74
74
  return null;
75
75
  }
76
- exports.extractSessionCookie = extractSessionCookie;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const constants_1 = require("../../constants");
4
4
  const error_1 = require("../../utils/error");
5
+ const log_1 = require("../../utils/log");
5
6
  const console_1 = require("./console");
6
7
  const linked = !!process.env.VTEX_APP_LINK;
7
8
  const app = constants_1.APP.ID;
@@ -22,6 +23,7 @@ class Logger {
22
23
  this.log = (message, level) => {
23
24
  var _a;
24
25
  const data = message ? error_1.cleanError(message) : EMPTY_MESSAGE;
26
+ log_1.cleanLog(data);
25
27
  /* tslint:disable:object-literal-sort-keys */
26
28
  const inflatedLog = {
27
29
  __VTEX_IO_LOG: true,
@@ -0,0 +1,5 @@
1
+ export declare function cleanJson(json: {
2
+ [k: string]: any;
3
+ }, targetFields: string[]): {
4
+ [k: string]: any;
5
+ };
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function cleanJson(json, targetFields) {
4
+ for (const key of json.keys()) {
5
+ let deleted = false;
6
+ for (const field of targetFields) {
7
+ if (key === field) {
8
+ delete json[key];
9
+ deleted = true;
10
+ }
11
+ }
12
+ if (!deleted && typeof json[key] === 'object') {
13
+ json[key] = cleanJson(json[key], targetFields);
14
+ }
15
+ }
16
+ return json;
17
+ }
18
+ exports.cleanJson = cleanJson;
@@ -0,0 +1,3 @@
1
+ export declare const cleanLog: (log: any) => {
2
+ [k: string]: any;
3
+ };
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const json_1 = require("./json");
4
+ const SENSITIVE_FIELDS = ['cookie', 'Cookie', 'vtexIdclientautcookie', 'error'];
5
+ exports.cleanLog = (log) => {
6
+ return json_1.cleanJson(log, SENSITIVE_FIELDS);
7
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vtex/api",
3
- "version": "6.45.5",
3
+ "version": "6.45.8",
4
4
  "description": "VTEX I/O API client",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",