@vtex/api 6.50.0-beta → 6.50.0

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.
@@ -3,4 +3,4 @@ import { SchemaDirectiveVisitor } from 'graphql-tools';
3
3
  export declare class Auth extends SchemaDirectiveVisitor {
4
4
  visitFieldDefinition(field: GraphQLField<any, any>): void;
5
5
  }
6
- export declare const authDirectiveTypeDefs = "\nenum Scope {\n PUBLIC\n PRIVATE\n}\n\ndirective @auth(\n scope: Scope\n productCode: String\n resourceCode: String\n) on FIELD_DEFINITION\n";
6
+ export declare const authDirectiveTypeDefs = "\n\nenum IOAuthScope {\n PUBLIC\n PRIVATE\n}\n\ndirective @auth(\n scope: IOAuthScope\n productCode: String\n resourceCode: String\n) on FIELD_DEFINITION\n";
@@ -8,11 +8,6 @@ const apollo_server_errors_1 = require("apollo-server-errors");
8
8
  const axios_1 = __importDefault(require("axios"));
9
9
  const graphql_1 = require("graphql");
10
10
  const graphql_tools_1 = require("graphql-tools");
11
- var Scope;
12
- (function (Scope) {
13
- Scope["PUBLIC"] = "PUBLIC";
14
- Scope["PRIVATE"] = "PRIVATE";
15
- })(Scope || (Scope = {}));
16
11
  async function parseIdToken(authToken, vtexIdToken) {
17
12
  const url = `vtexid.vtex.com.br/api/vtexid/pub/authenticated/user?authToken=${vtexIdToken}`;
18
13
  const req = await axios_1.default.request({
@@ -55,8 +50,11 @@ async function auth(ctx, authArgs) {
55
50
  }
56
51
  }
57
52
  function parseArgs(authArgs) {
53
+ if (authArgs.scope == 'PUBLIC') {
54
+ return authArgs;
55
+ }
58
56
  if (!authArgs.productCode || !authArgs.resourceCode) {
59
- throw new apollo_server_errors_1.UserInputError('Invalid auth schema directive args. Usage: @auth(scope: Scope, productCode: String, resourceCode: String).');
57
+ throw new apollo_server_errors_1.UserInputError('Invalid auth schema directive args. Usage: @auth(scope: IOAuthScope, productCode: String, resourceCode: String).');
60
58
  }
61
59
  return authArgs;
62
60
  }
@@ -65,7 +63,7 @@ class Auth extends graphql_tools_1.SchemaDirectiveVisitor {
65
63
  const { resolve = graphql_1.defaultFieldResolver } = field;
66
64
  field.resolve = async (root, args, ctx, info) => {
67
65
  const authArgs = parseArgs(this.args);
68
- if (!authArgs.scope || authArgs.scope == Scope.PRIVATE) {
66
+ if (!authArgs.scope || authArgs.scope == 'PRIVATE') {
69
67
  await auth(ctx, authArgs);
70
68
  }
71
69
  return resolve(root, args, ctx, info);
@@ -74,13 +72,14 @@ class Auth extends graphql_tools_1.SchemaDirectiveVisitor {
74
72
  }
75
73
  exports.Auth = Auth;
76
74
  exports.authDirectiveTypeDefs = `
77
- enum Scope {
75
+
76
+ enum IOAuthScope {
78
77
  PUBLIC
79
78
  PRIVATE
80
79
  }
81
80
 
82
81
  directive @auth(
83
- scope: Scope
82
+ scope: IOAuthScope
84
83
  productCode: String
85
84
  resourceCode: String
86
85
  ) on FIELD_DEFINITION
@@ -2,7 +2,6 @@ import { Auth } from './Auth';
2
2
  import { CacheControl } from './CacheControl';
3
3
  import { Deprecated } from './Deprecated';
4
4
  import { Metric } from './Metric';
5
- import { Public } from './Public';
6
5
  import { SanitizeDirective } from './Sanitize';
7
6
  import { SettingsDirective } from './Settings';
8
7
  import { SmartCacheDirective } from './SmartCacheDirective';
@@ -19,6 +18,5 @@ export declare const nativeSchemaDirectives: {
19
18
  smartcache: typeof SmartCacheDirective;
20
19
  translatableV2: typeof TranslatableV2;
21
20
  translateTo: typeof TranslateTo;
22
- public: typeof Public;
23
21
  };
24
22
  export declare const nativeSchemaDirectivesTypeDefs: string;
@@ -5,7 +5,6 @@ const Auth_1 = require("./Auth");
5
5
  const CacheControl_1 = require("./CacheControl");
6
6
  const Deprecated_1 = require("./Deprecated");
7
7
  const Metric_1 = require("./Metric");
8
- const Public_1 = require("./Public");
9
8
  const Sanitize_1 = require("./Sanitize");
10
9
  const Settings_1 = require("./Settings");
11
10
  const SmartCacheDirective_1 = require("./SmartCacheDirective");
@@ -24,7 +23,6 @@ exports.nativeSchemaDirectives = {
24
23
  smartcache: SmartCacheDirective_1.SmartCacheDirective,
25
24
  translatableV2: TranslatableV2_1.TranslatableV2,
26
25
  translateTo: TranslateTo_1.TranslateTo,
27
- public: Public_1.Public
28
26
  };
29
27
  exports.nativeSchemaDirectivesTypeDefs = [
30
28
  Auth_1.authDirectiveTypeDefs,
@@ -36,5 +34,4 @@ exports.nativeSchemaDirectivesTypeDefs = [
36
34
  SmartCacheDirective_1.smartCacheDirectiveTypeDefs,
37
35
  TranslatableV2_1.translatableV2DirectiveTypeDefs,
38
36
  TranslateTo_1.translateToDirectiveTypeDefs,
39
- Public_1.publicDirectiveTypeDefs
40
37
  ].join('\n\n');
@@ -3,9 +3,14 @@ export interface TraceInfo {
3
3
  traceId?: string;
4
4
  isSampled: boolean;
5
5
  }
6
+ /**
7
+ * Headers that are interesting for tracing and debugging purposes
8
+ */
9
+ export declare const INTERESTING_HEADERS: string[];
6
10
  export declare function getTraceInfo(span?: Span): TraceInfo;
7
11
  /**
8
12
  * Do a shallow copy of a headers object and redacts sensitive information.
13
+ * Only includes headers that are in the INTERESTING_HEADERS whitelist.
9
14
  *
10
15
  * @param headersObj The headers object
11
16
  * @param resultFieldsPrefix The prefix that will be added to each field on the result object
@@ -1,7 +1,53 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cloneAndSanitizeHeaders = exports.getTraceInfo = void 0;
3
+ exports.cloneAndSanitizeHeaders = exports.getTraceInfo = exports.INTERESTING_HEADERS = void 0;
4
4
  const node_error_report_1 = require("@vtex/node-error-report");
5
+ /**
6
+ * Headers that are interesting for tracing and debugging purposes
7
+ */
8
+ exports.INTERESTING_HEADERS = [
9
+ // Request/Response Identification & Routing
10
+ 'x-request-id',
11
+ 'x-correlation-id',
12
+ 'x-trace-id',
13
+ 'x-span-id',
14
+ 'x-forwarded-for',
15
+ 'x-real-ip',
16
+ 'host',
17
+ 'referer',
18
+ // Content & Encoding
19
+ 'content-type',
20
+ 'content-length',
21
+ 'content-encoding',
22
+ 'accept',
23
+ 'accept-encoding',
24
+ 'accept-language',
25
+ // Caching & Performance
26
+ 'cache-control',
27
+ 'etag',
28
+ 'if-none-match',
29
+ 'expires',
30
+ 'last-modified',
31
+ // Client Information
32
+ 'user-agent',
33
+ 'x-forwarded-proto',
34
+ 'x-forwarded-host',
35
+ 'x-forwarded-port',
36
+ // VTEX/E-commerce Specific (x-vtex-* headers are handled automatically)
37
+ 'x-router-cache',
38
+ 'x-powered-by-vtex-cache',
39
+ 'jaeger-debug-id',
40
+ // API & Service Headers
41
+ 'x-api-version',
42
+ 'x-service-name',
43
+ 'x-timeout',
44
+ 'retry-after',
45
+ // Security (will be sanitized)
46
+ 'authorization',
47
+ 'cookie',
48
+ ];
49
+ // Create the set once for performance
50
+ const INTERESTING_HEADERS_SET = new Set(exports.INTERESTING_HEADERS.map(h => h.toLowerCase()));
5
51
  function getTraceInfo(span) {
6
52
  var _a, _b;
7
53
  const spanContext = span === null || span === void 0 ? void 0 : span.context();
@@ -13,6 +59,7 @@ function getTraceInfo(span) {
13
59
  exports.getTraceInfo = getTraceInfo;
14
60
  /**
15
61
  * Do a shallow copy of a headers object and redacts sensitive information.
62
+ * Only includes headers that are in the INTERESTING_HEADERS whitelist.
16
63
  *
17
64
  * @param headersObj The headers object
18
65
  * @param resultFieldsPrefix The prefix that will be added to each field on the result object
@@ -21,6 +68,11 @@ const cloneAndSanitizeHeaders = (headersObj, resultFieldsPrefix = '') => {
21
68
  const ret = {};
22
69
  const entries = Object.entries(headersObj);
23
70
  for (const [key, val] of entries) {
71
+ const lowerKey = key.toLowerCase();
72
+ // Only include headers that are in our whitelist or start with x-vtex-
73
+ if (!INTERESTING_HEADERS_SET.has(lowerKey) && !lowerKey.startsWith('x-vtex-')) {
74
+ continue;
75
+ }
24
76
  // Most of the time val is a string, but there are some cases, for example when we do a axios interceptor,
25
77
  // that a header field can contain an object, for example:
26
78
  // ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vtex/api",
3
- "version": "6.50.0-beta",
3
+ "version": "6.50.0",
4
4
  "description": "VTEX I/O API client",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -49,13 +49,13 @@
49
49
  "dependencies": {
50
50
  "@types/koa": "^2.11.0",
51
51
  "@types/koa-compose": "^3.2.3",
52
- "@vtex/diagnostics-nodejs": "0.1.0-beta.8",
52
+ "@vtex/diagnostics-nodejs": "0.1.0-beta.10",
53
53
  "@vtex/node-error-report": "^0.0.3",
54
54
  "@wry/equality": "^0.1.9",
55
55
  "agentkeepalive": "^4.0.2",
56
56
  "apollo-server-errors": "^2.2.1",
57
57
  "archiver": "^3.0.0",
58
- "axios": "^1.8.4",
58
+ "axios": "^0.21.1",
59
59
  "axios-retry": "^3.1.2",
60
60
  "bluebird": "^3.5.4",
61
61
  "chalk": "^2.4.2",
@@ -124,27 +124,5 @@
124
124
  "typemoq": "^2.1.0",
125
125
  "typescript": "^4.4.4",
126
126
  "typescript-json-schema": "^0.52.0"
127
- },
128
- "resolutions": {
129
- "@opentelemetry/core": "1.30.1",
130
- "@opentelemetry/exporter-metrics-otlp-grpc": "0.57.2",
131
- "@opentelemetry/exporter-metrics-otlp-http": "0.57.2",
132
- "@opentelemetry/exporter-logs-otlp-grpc": "0.57.2",
133
- "@opentelemetry/exporter-logs-otlp-http": "0.57.2",
134
- "@opentelemetry/exporter-trace-otlp-grpc": "0.57.2",
135
- "@opentelemetry/exporter-trace-otlp-http": "0.57.2",
136
- "@opentelemetry/instrumentation": "0.57.2",
137
- "@opentelemetry/instrumentation-http": "0.57.2",
138
- "@opentelemetry/instrumentation-grpc": "0.57.2",
139
- "@opentelemetry/instrumentation-net": "0.43.1",
140
- "@opentelemetry/propagator-b3": "1.30.1",
141
- "@opentelemetry/resource-detector-aws": "1.12.0",
142
- "@opentelemetry/resources": "1.30.1",
143
- "@opentelemetry/sdk-node": "0.57.2",
144
- "@opentelemetry/sdk-logs": "0.57.2",
145
- "@opentelemetry/sdk-metrics": "1.30.1",
146
- "@opentelemetry/sdk-trace-base": "1.30.1",
147
- "@opentelemetry/sdk-trace-node": "1.30.1"
148
- },
149
- "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
127
+ }
150
128
  }
@@ -1,6 +0,0 @@
1
- import { GraphQLField } from "graphql";
2
- import { SchemaDirectiveVisitor } from "graphql-tools";
3
- export declare class Public extends SchemaDirectiveVisitor {
4
- visitFieldDefinition(field: GraphQLField<any, any>): void;
5
- }
6
- export declare const publicDirectiveTypeDefs = "directive @public on FIELD_DEFINITION";
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.publicDirectiveTypeDefs = exports.Public = void 0;
4
- const graphql_1 = require("graphql");
5
- const graphql_tools_1 = require("graphql-tools");
6
- class Public extends graphql_tools_1.SchemaDirectiveVisitor {
7
- visitFieldDefinition(field) {
8
- const { resolve = graphql_1.defaultFieldResolver } = field;
9
- field.resolve = async function (...args) {
10
- return resolve.apply(this, args);
11
- };
12
- }
13
- }
14
- exports.Public = Public;
15
- exports.publicDirectiveTypeDefs = `directive @public on FIELD_DEFINITION`;