@vtex/api 7.2.1 → 7.2.2-beta.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.
- package/lib/HttpClient/HttpClient.js +8 -8
- package/lib/HttpClient/middlewares/cache.js +4 -4
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/spanSetup.js +2 -2
- package/lib/clients/janus/Segment.js +1 -1
- package/lib/constants.d.ts +45 -29
- package/lib/constants.js +48 -30
- package/lib/service/logger/logger.js +6 -5
- package/lib/service/tracing/tracingMiddlewares.js +4 -4
- package/lib/service/worker/runtime/builtIn/middlewares.js +1 -1
- package/lib/service/worker/runtime/events/middlewares/context.js +4 -4
- package/lib/service/worker/runtime/events/router.js +1 -1
- package/lib/service/worker/runtime/graphql/middlewares/response.js +7 -7
- package/lib/service/worker/runtime/graphql/middlewares/updateSchema.js +4 -4
- package/lib/service/worker/runtime/http/middlewares/context.js +2 -2
- package/lib/service/worker/runtime/http/middlewares/vary.js +9 -9
- package/lib/service/worker/runtime/http/router.js +1 -1
- package/lib/service/worker/runtime/utils/context.js +14 -14
- package/lib/service/worker/runtime/utils/recorder.js +1 -1
- package/package.json +2 -1
|
@@ -112,14 +112,14 @@ class HttpClient {
|
|
|
112
112
|
...defaultHeaders,
|
|
113
113
|
'Accept-Encoding': 'gzip',
|
|
114
114
|
'User-Agent': userAgent,
|
|
115
|
-
...host ? { [constants_1.
|
|
116
|
-
...tenant ? { [constants_1.
|
|
117
|
-
...binding ? { [constants_1.
|
|
118
|
-
...locale ? { [constants_1.
|
|
119
|
-
...operationId ? {
|
|
120
|
-
...product ? { [constants_1.
|
|
121
|
-
...segmentToken ? { [constants_1.
|
|
122
|
-
...sessionToken ? { [constants_1.
|
|
115
|
+
...host ? { [constants_1.HeaderKeys.FORWARDED_HOST]: host } : null,
|
|
116
|
+
...tenant ? { [constants_1.HeaderKeys.TENANT]: (0, tenant_1.formatTenantHeaderValue)(tenant) } : null,
|
|
117
|
+
...binding ? { [constants_1.HeaderKeys.BINDING]: (0, binding_1.formatBindingHeaderValue)(binding) } : null,
|
|
118
|
+
...locale ? { [constants_1.HeaderKeys.LOCALE]: locale } : null,
|
|
119
|
+
...operationId ? { [constants_1.HeaderKeys.OPERATION_ID]: operationId } : null,
|
|
120
|
+
...product ? { [constants_1.HeaderKeys.PRODUCT]: product } : null,
|
|
121
|
+
...segmentToken ? { [constants_1.HeaderKeys.SEGMENT]: segmentToken } : null,
|
|
122
|
+
...sessionToken ? { [constants_1.HeaderKeys.SESSION]: sessionToken } : null,
|
|
123
123
|
};
|
|
124
124
|
if (authType && authToken) {
|
|
125
125
|
headers['Authorization'] = `${authType} ${authToken}`; // tslint:disable-line
|
|
@@ -7,7 +7,7 @@ const RANGE_HEADER_QS_KEY = '__range_header';
|
|
|
7
7
|
const cacheableStatusCodes = [200, 203, 204, 206, 300, 301, 404, 405, 410, 414, 501]; // https://tools.ietf.org/html/rfc7231#section-6.1
|
|
8
8
|
const cacheKey = (config) => {
|
|
9
9
|
const { baseURL = '', url = '', params, headers } = config;
|
|
10
|
-
const locale = headers === null || headers === void 0 ? void 0 : headers[constants_1.
|
|
10
|
+
const locale = headers === null || headers === void 0 ? void 0 : headers[constants_1.HeaderKeys.LOCALE];
|
|
11
11
|
const encodedBaseURL = baseURL.replace(/\//g, '\\');
|
|
12
12
|
const encodedURL = url.replace(/\//g, '\\');
|
|
13
13
|
let key = `${locale}--${encodedBaseURL}--${encodedURL}?`;
|
|
@@ -64,7 +64,7 @@ const cacheMiddleware = ({ type, storage, asyncSet }) => {
|
|
|
64
64
|
}
|
|
65
65
|
const { rootSpan: span, tracer, logger } = (_a = ctx.tracing) !== null && _a !== void 0 ? _a : {};
|
|
66
66
|
const key = (0, exports.cacheKey)(ctx.config);
|
|
67
|
-
const segmentToken = (_b = ctx.config.headers) === null || _b === void 0 ? void 0 : _b[constants_1.
|
|
67
|
+
const segmentToken = (_b = ctx.config.headers) === null || _b === void 0 ? void 0 : _b[constants_1.HeaderKeys.SEGMENT];
|
|
68
68
|
const keyWithSegment = key + segmentToken;
|
|
69
69
|
span === null || span === void 0 ? void 0 : span.log({
|
|
70
70
|
event: "cache-key-created" /* HttpLogEvents.CACHE_KEY_CREATE */,
|
|
@@ -156,11 +156,11 @@ const cacheMiddleware = ({ type, storage, asyncSet }) => {
|
|
|
156
156
|
return;
|
|
157
157
|
}
|
|
158
158
|
const shouldCache = maxAge || etag;
|
|
159
|
-
const varySession = ctx.response.headers.vary && ctx.response.headers.vary.includes(constants_1.
|
|
159
|
+
const varySession = ctx.response.headers.vary && ctx.response.headers.vary.includes(constants_1.HeaderKeys.SESSION);
|
|
160
160
|
if (shouldCache && !varySession) {
|
|
161
161
|
const { responseType, responseEncoding: configResponseEncoding } = ctx.config;
|
|
162
162
|
const currentAge = revalidated ? 0 : age;
|
|
163
|
-
const varySegment = ctx.response.headers.vary && ctx.response.headers.vary.includes(constants_1.
|
|
163
|
+
const varySegment = ctx.response.headers.vary && ctx.response.headers.vary.includes(constants_1.HeaderKeys.SEGMENT);
|
|
164
164
|
const setKey = varySegment ? keyWithSegment : key;
|
|
165
165
|
const responseEncoding = configResponseEncoding || (responseType === 'arraybuffer' ? 'base64' : undefined);
|
|
166
166
|
const cacheableData = type === CacheType.Disk && responseType === 'arraybuffer'
|
|
@@ -25,8 +25,8 @@ const injectResponseInfoOnSpan = (span, response) => {
|
|
|
25
25
|
}
|
|
26
26
|
span === null || span === void 0 ? void 0 : span.log({ 'response-headers': (0, utils_1.cloneAndSanitizeHeaders)(response.headers) });
|
|
27
27
|
span === null || span === void 0 ? void 0 : span.setTag(Tags_1.OpentracingTags.HTTP_STATUS_CODE, response.status);
|
|
28
|
-
if (response.headers[constants_1.
|
|
29
|
-
span === null || span === void 0 ? void 0 : span.setTag("http.cache.router" /* CustomHttpTags.HTTP_ROUTER_CACHE_RESULT */, response.headers[constants_1.
|
|
28
|
+
if (response.headers[constants_1.HeaderKeys.ROUTER_CACHE]) {
|
|
29
|
+
span === null || span === void 0 ? void 0 : span.setTag("http.cache.router" /* CustomHttpTags.HTTP_ROUTER_CACHE_RESULT */, response.headers[constants_1.HeaderKeys.ROUTER_CACHE]);
|
|
30
30
|
}
|
|
31
31
|
};
|
|
32
32
|
exports.injectResponseInfoOnSpan = injectResponseInfoOnSpan;
|
|
@@ -58,7 +58,7 @@ class Segment extends JanusClient_1.JanusClient {
|
|
|
58
58
|
forceMaxAge: SEGMENT_MAX_AGE_S,
|
|
59
59
|
headers: {
|
|
60
60
|
'Content-Type': 'application/json',
|
|
61
|
-
[constants_1.
|
|
61
|
+
[constants_1.HeaderKeys.PRODUCT]: product || '',
|
|
62
62
|
},
|
|
63
63
|
inflightKey: HttpClient_1.inflightUrlWithQuery,
|
|
64
64
|
metric,
|
package/lib/constants.d.ts
CHANGED
|
@@ -2,35 +2,51 @@ export declare const NODE_VTEX_API_VERSION: any;
|
|
|
2
2
|
export declare const DEFAULT_WORKSPACE = "master";
|
|
3
3
|
export declare const IS_IO: string | undefined;
|
|
4
4
|
export declare const PID: number;
|
|
5
|
-
export declare const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
5
|
+
export declare const HeaderKeys: {
|
|
6
|
+
CACHE_CONTROL: string;
|
|
7
|
+
SEGMENT: string;
|
|
8
|
+
SESSION: string;
|
|
9
|
+
PRODUCT: string;
|
|
10
|
+
LOCALE: string;
|
|
11
|
+
FORWARDED_HOST: string;
|
|
12
|
+
FORWARDED_FOR: string;
|
|
13
|
+
TENANT: string;
|
|
14
|
+
BINDING: string;
|
|
15
|
+
META: string;
|
|
16
|
+
META_BUCKET: string;
|
|
17
|
+
ETAG: string;
|
|
18
|
+
ACCOUNT: string;
|
|
19
|
+
CREDENTIAL: string;
|
|
20
|
+
REQUEST_ID: string;
|
|
21
|
+
ROUTER_CACHE: string;
|
|
22
|
+
OPERATION_ID: string;
|
|
23
|
+
PLATFORM: string;
|
|
24
|
+
WORKSPACE_IS_PRODUCTION: string;
|
|
25
|
+
WORKSPACE: string;
|
|
26
|
+
EVENT_KEY: string;
|
|
27
|
+
EVENT_SENDER: string;
|
|
28
|
+
EVENT_SUBJECT: string;
|
|
29
|
+
EVENT_HANDLER_ID: string;
|
|
30
|
+
COLOSSUS_ROUTE_DECLARER: string;
|
|
31
|
+
COLOSSUS_ROUTE_ID: string;
|
|
32
|
+
COLOSSUS_PARAMS: string;
|
|
33
|
+
TRACE_ID: string;
|
|
34
|
+
PROVIDER: string;
|
|
35
|
+
USER_AGENT: string;
|
|
36
|
+
VTEX_USER_AGENT: string;
|
|
37
|
+
VTEX_IO_CALLER: string;
|
|
38
|
+
VTEX_APP_SERVICE: string;
|
|
39
|
+
VTEX_APP_KEY: string;
|
|
40
|
+
VTEX_RETRY_COUNT: string;
|
|
41
|
+
};
|
|
42
|
+
export declare const AttributeKeys: {
|
|
43
|
+
VTEX_ACCOUNT_NAME: "vtex.account.name";
|
|
44
|
+
VTEX_IO_WORKSPACE_NAME: "vtex_io.workspace.name";
|
|
45
|
+
VTEX_IO_WORKSPACE_TYPE: "vtex_io.workspace.type";
|
|
46
|
+
VTEX_IO_APP_ID: "vtex_io.app.id";
|
|
47
|
+
VTEX_IO_APP_AUTHOR_TYPE: "vtex_io.app.author_type";
|
|
48
|
+
};
|
|
49
|
+
export type VaryHeaders = typeof HeaderKeys.SEGMENT | typeof HeaderKeys.SESSION | typeof HeaderKeys.PRODUCT | typeof HeaderKeys.LOCALE;
|
|
34
50
|
export declare const BODY_HASH = "__graphqlBodyHash";
|
|
35
51
|
export declare const UP_SIGNAL = "UP";
|
|
36
52
|
export declare const MAX_AGE: {
|
package/lib/constants.js
CHANGED
|
@@ -1,42 +1,60 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DK_APP_ID = exports.OTEL_EXPORTER_OTLP_ENDPOINT = exports.LOG_CLIENT_INIT_TIMEOUT_MS = exports.cancellableMethods = exports.INSPECT_DEBUGGER_PORT = exports.PRODUCTION = exports.WORKSPACE = exports.ACCOUNT = exports.NODE_ENV = exports.APP = exports.PUBLIC_ENDPOINT = exports.REGION = exports.LINKED = exports.MAX_WORKERS = exports.HTTP_SERVER_PORT = exports.MAX_AGE = exports.UP_SIGNAL = exports.BODY_HASH = exports.
|
|
4
|
-
exports.DIAGNOSTICS_TELEMETRY_ENABLED = void 0;
|
|
3
|
+
exports.DIAGNOSTICS_TELEMETRY_ENABLED = exports.DK_APP_ID = exports.OTEL_EXPORTER_OTLP_ENDPOINT = exports.LOG_CLIENT_INIT_TIMEOUT_MS = exports.cancellableMethods = exports.INSPECT_DEBUGGER_PORT = exports.PRODUCTION = exports.WORKSPACE = exports.ACCOUNT = exports.NODE_ENV = exports.APP = exports.PUBLIC_ENDPOINT = exports.REGION = exports.LINKED = exports.MAX_WORKERS = exports.HTTP_SERVER_PORT = exports.MAX_AGE = exports.UP_SIGNAL = exports.BODY_HASH = exports.AttributeKeys = exports.HeaderKeys = exports.PID = exports.IS_IO = exports.DEFAULT_WORKSPACE = exports.NODE_VTEX_API_VERSION = void 0;
|
|
5
4
|
const app_1 = require("./utils/app");
|
|
5
|
+
const diagnostics_semconv_1 = require("@vtex/diagnostics-semconv");
|
|
6
6
|
// tslint:disable-next-line
|
|
7
7
|
const pkg = require('../package.json');
|
|
8
8
|
exports.NODE_VTEX_API_VERSION = pkg.version;
|
|
9
9
|
exports.DEFAULT_WORKSPACE = 'master';
|
|
10
10
|
exports.IS_IO = process.env.VTEX_IO;
|
|
11
11
|
exports.PID = process.pid;
|
|
12
|
-
exports.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
12
|
+
exports.HeaderKeys = {
|
|
13
|
+
CACHE_CONTROL: 'cache-control',
|
|
14
|
+
SEGMENT: 'x-vtex-segment',
|
|
15
|
+
SESSION: 'x-vtex-session',
|
|
16
|
+
PRODUCT: 'x-vtex-product',
|
|
17
|
+
LOCALE: 'x-vtex-locale',
|
|
18
|
+
FORWARDED_HOST: 'x-forwarded-host',
|
|
19
|
+
FORWARDED_FOR: 'x-forwarded-for',
|
|
20
|
+
TENANT: 'x-vtex-tenant',
|
|
21
|
+
BINDING: 'x-vtex-binding',
|
|
22
|
+
META: 'x-vtex-meta',
|
|
23
|
+
META_BUCKET: 'x-vtex-meta-bucket',
|
|
24
|
+
ETAG: 'etag',
|
|
25
|
+
ACCOUNT: 'x-vtex-account',
|
|
26
|
+
CREDENTIAL: 'x-vtex-credential',
|
|
27
|
+
REQUEST_ID: 'x-request-id',
|
|
28
|
+
ROUTER_CACHE: 'x-router-cache',
|
|
29
|
+
OPERATION_ID: 'x-vtex-operation-id',
|
|
30
|
+
PLATFORM: 'x-vtex-platform',
|
|
31
|
+
WORKSPACE_IS_PRODUCTION: 'x-vtex-workspace-is-production',
|
|
32
|
+
WORKSPACE: 'x-vtex-workspace',
|
|
33
|
+
EVENT_KEY: 'x-event-key',
|
|
34
|
+
EVENT_SENDER: 'x-event-sender',
|
|
35
|
+
EVENT_SUBJECT: 'x-event-subject',
|
|
36
|
+
EVENT_HANDLER_ID: 'x-event-handler-id',
|
|
37
|
+
COLOSSUS_ROUTE_DECLARER: 'x-colossus-route-declarer',
|
|
38
|
+
COLOSSUS_ROUTE_ID: 'x-colossus-route-id',
|
|
39
|
+
COLOSSUS_PARAMS: 'x-colossus-params',
|
|
40
|
+
TRACE_ID: 'x-trace-id',
|
|
41
|
+
PROVIDER: 'x-vtex-provider',
|
|
42
|
+
USER_AGENT: 'user-agent',
|
|
43
|
+
VTEX_USER_AGENT: 'x-vtex-user-agent',
|
|
44
|
+
VTEX_IO_CALLER: 'x-vtex-io-caller',
|
|
45
|
+
VTEX_APP_SERVICE: 'x-vtex-app-service',
|
|
46
|
+
VTEX_APP_KEY: 'x-vtex-app-key',
|
|
47
|
+
VTEX_RETRY_COUNT: 'x-vtex-retry-count'
|
|
48
|
+
};
|
|
49
|
+
exports.AttributeKeys = {
|
|
50
|
+
// VTEX Semantic Attributes
|
|
51
|
+
VTEX_ACCOUNT_NAME: diagnostics_semconv_1.ATTR_VTEX_ACCOUNT_NAME,
|
|
52
|
+
// VTEX IO Semantic Attributes
|
|
53
|
+
VTEX_IO_WORKSPACE_NAME: diagnostics_semconv_1.ATTR_VTEX_IO_WORKSPACE_NAME,
|
|
54
|
+
VTEX_IO_WORKSPACE_TYPE: diagnostics_semconv_1.ATTR_VTEX_IO_WORKSPACE_TYPE,
|
|
55
|
+
VTEX_IO_APP_ID: diagnostics_semconv_1.ATTR_VTEX_IO_APP_ID,
|
|
56
|
+
VTEX_IO_APP_AUTHOR_TYPE: diagnostics_semconv_1.ATTR_VTEX_IO_APP_AUTHOR_TYPE,
|
|
57
|
+
};
|
|
40
58
|
exports.BODY_HASH = '__graphqlBodyHash';
|
|
41
59
|
exports.UP_SIGNAL = 'UP';
|
|
42
60
|
exports.MAX_AGE = {
|
|
@@ -24,13 +24,14 @@ class Logger {
|
|
|
24
24
|
const inflatedLog = {
|
|
25
25
|
__VTEX_IO_LOG: true,
|
|
26
26
|
level,
|
|
27
|
-
app,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
[constants_1.AttributeKeys.VTEX_IO_APP_ID]: app,
|
|
28
|
+
[constants_1.AttributeKeys.VTEX_ACCOUNT_NAME]: this.account,
|
|
29
|
+
[constants_1.AttributeKeys.VTEX_IO_WORKSPACE_NAME]: this.workspace,
|
|
30
|
+
[constants_1.AttributeKeys.VTEX_IO_WORKSPACE_TYPE]: this.production ? 'production' : 'development',
|
|
31
|
+
[constants_1.AttributeKeys.VTEX_IO_APP_AUTHOR_TYPE]: constants_1.APP.IS_THIRD_PARTY() ? '3p' : '1p',
|
|
32
32
|
operationId: this.operationId,
|
|
33
33
|
requestId: this.requestId,
|
|
34
|
+
data,
|
|
34
35
|
...(((_a = this.tracingState) === null || _a === void 0 ? void 0 : _a.isTraceSampled) ? { traceId: this.tracingState.traceId } : null),
|
|
35
36
|
};
|
|
36
37
|
// Mark third-party apps logs to send to skidder
|
|
@@ -44,13 +44,13 @@ const addTracingMiddleware = (tracer) => {
|
|
|
44
44
|
[Tags_1.OpentracingTags.HTTP_METHOD]: ctx.request.method,
|
|
45
45
|
[Tags_1.OpentracingTags.HTTP_STATUS_CODE]: ctx.response.status,
|
|
46
46
|
["http.path" /* CustomHttpTags.HTTP_PATH */]: ctx.request.path,
|
|
47
|
-
["vtex.request_id" /* VTEXIncomingRequestTags.VTEX_REQUEST_ID */]: ctx.get(constants_1.
|
|
48
|
-
["vtex.incoming.workspace" /* VTEXIncomingRequestTags.VTEX_WORKSPACE */]: ctx.get(constants_1.
|
|
49
|
-
["vtex.incoming.account" /* VTEXIncomingRequestTags.VTEX_ACCOUNT */]: ctx.get(constants_1.
|
|
47
|
+
["vtex.request_id" /* VTEXIncomingRequestTags.VTEX_REQUEST_ID */]: ctx.get(constants_1.HeaderKeys.REQUEST_ID),
|
|
48
|
+
["vtex.incoming.workspace" /* VTEXIncomingRequestTags.VTEX_WORKSPACE */]: ctx.get(constants_1.HeaderKeys.WORKSPACE),
|
|
49
|
+
["vtex.incoming.account" /* VTEXIncomingRequestTags.VTEX_ACCOUNT */]: ctx.get(constants_1.HeaderKeys.ACCOUNT),
|
|
50
50
|
});
|
|
51
51
|
currentSpan === null || currentSpan === void 0 ? void 0 : currentSpan.log((0, utils_1.cloneAndSanitizeHeaders)(ctx.request.headers, 'req.headers.'));
|
|
52
52
|
currentSpan === null || currentSpan === void 0 ? void 0 : currentSpan.log((0, utils_1.cloneAndSanitizeHeaders)(ctx.response.headers, 'res.headers.'));
|
|
53
|
-
ctx.set(constants_1.
|
|
53
|
+
ctx.set(constants_1.HeaderKeys.TRACE_ID, traceInfo.traceId);
|
|
54
54
|
}
|
|
55
55
|
const onResFinished = () => {
|
|
56
56
|
currentSpan === null || currentSpan === void 0 ? void 0 : currentSpan.finish();
|
|
@@ -30,7 +30,7 @@ const prometheusLoggerMiddleware = () => {
|
|
|
30
30
|
if (ctx.request.path !== '/metrics') {
|
|
31
31
|
return next();
|
|
32
32
|
}
|
|
33
|
-
const routeId = ctx.get(constants_1.
|
|
33
|
+
const routeId = ctx.get(constants_1.HeaderKeys.COLOSSUS_ROUTE_ID);
|
|
34
34
|
if (routeId) {
|
|
35
35
|
return next();
|
|
36
36
|
}
|
|
@@ -8,12 +8,12 @@ async function eventContextMiddleware(ctx, next) {
|
|
|
8
8
|
ctx.vtex = {
|
|
9
9
|
...(0, context_1.prepareHandlerCtx)(header, ctx.tracing),
|
|
10
10
|
eventInfo: {
|
|
11
|
-
key: header[constants_1.
|
|
12
|
-
sender: header[constants_1.
|
|
13
|
-
subject: header[constants_1.
|
|
11
|
+
key: header[constants_1.HeaderKeys.EVENT_KEY],
|
|
12
|
+
sender: header[constants_1.HeaderKeys.EVENT_SENDER],
|
|
13
|
+
subject: header[constants_1.HeaderKeys.EVENT_SUBJECT],
|
|
14
14
|
},
|
|
15
15
|
route: {
|
|
16
|
-
id: header[constants_1.
|
|
16
|
+
id: header[constants_1.HeaderKeys.EVENT_HANDLER_ID],
|
|
17
17
|
params: {},
|
|
18
18
|
type: 'event',
|
|
19
19
|
},
|
|
@@ -6,7 +6,7 @@ const logger_1 = require("../../../logger");
|
|
|
6
6
|
const console_1 = require("./../../../logger/console");
|
|
7
7
|
const routerFromEventHandlers = (events) => {
|
|
8
8
|
return async (ctx, next) => {
|
|
9
|
-
const handlerId = ctx.get(constants_1.
|
|
9
|
+
const handlerId = ctx.get(constants_1.HeaderKeys.EVENT_HANDLER_ID);
|
|
10
10
|
if (!handlerId || !events) {
|
|
11
11
|
return next();
|
|
12
12
|
}
|
|
@@ -4,13 +4,13 @@ exports.response = void 0;
|
|
|
4
4
|
const constants_1 = require("../../../../../constants");
|
|
5
5
|
const cacheControl_1 = require("../utils/cacheControl");
|
|
6
6
|
function setVaryHeaders(ctx, cacheControl) {
|
|
7
|
-
ctx.vary(constants_1.
|
|
7
|
+
ctx.vary(constants_1.HeaderKeys.FORWARDED_HOST);
|
|
8
8
|
if (cacheControl.scope === 'segment') {
|
|
9
|
-
ctx.vary(constants_1.
|
|
9
|
+
ctx.vary(constants_1.HeaderKeys.SEGMENT);
|
|
10
10
|
}
|
|
11
11
|
if (cacheControl.scope === 'private' || ctx.query.scope === 'private') {
|
|
12
|
-
ctx.vary(constants_1.
|
|
13
|
-
ctx.vary(constants_1.
|
|
12
|
+
ctx.vary(constants_1.HeaderKeys.SEGMENT);
|
|
13
|
+
ctx.vary(constants_1.HeaderKeys.SESSION);
|
|
14
14
|
}
|
|
15
15
|
else if (ctx.vtex.sessionToken) {
|
|
16
16
|
ctx.vtex.logger.warn({
|
|
@@ -24,11 +24,11 @@ async function response(ctx, next) {
|
|
|
24
24
|
await next();
|
|
25
25
|
const { cacheControl, status, graphqlResponse, } = ctx.graphql;
|
|
26
26
|
const cacheControlHeader = (0, cacheControl_1.cacheControlHTTP)(ctx);
|
|
27
|
-
ctx.set(constants_1.
|
|
27
|
+
ctx.set(constants_1.HeaderKeys.CACHE_CONTROL, cacheControlHeader);
|
|
28
28
|
if (status === 'error') {
|
|
29
29
|
// Do not generate etag for errors
|
|
30
|
-
ctx.remove(constants_1.
|
|
31
|
-
ctx.remove(constants_1.
|
|
30
|
+
ctx.remove(constants_1.HeaderKeys.META);
|
|
31
|
+
ctx.remove(constants_1.HeaderKeys.ETAG);
|
|
32
32
|
(_a = ctx.vtex.recorder) === null || _a === void 0 ? void 0 : _a.clear();
|
|
33
33
|
}
|
|
34
34
|
if (ctx.method.toUpperCase() === 'GET') {
|
|
@@ -6,20 +6,20 @@ const utils_1 = require("../../../../../utils");
|
|
|
6
6
|
const index_1 = require("../schema/index");
|
|
7
7
|
const updateSchema = (graphql, executableSchema) => async function updateRunnableSchema(ctx, next) {
|
|
8
8
|
const { clients: { apps }, vtex: { logger }, app, } = ctx;
|
|
9
|
-
if (!ctx.headers[constants_1.
|
|
9
|
+
if (!ctx.headers[constants_1.HeaderKeys.PROVIDER]) {
|
|
10
10
|
await next();
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
13
|
// fetches the new schema and generate a new runnable schema, updates the provider app,
|
|
14
14
|
if (executableSchema.hasProvider &&
|
|
15
15
|
(!executableSchema.provider ||
|
|
16
|
-
(0, utils_1.majorEqualAndGreaterThan)((0, utils_1.parseAppId)(ctx.headers[constants_1.
|
|
16
|
+
(0, utils_1.majorEqualAndGreaterThan)((0, utils_1.parseAppId)(ctx.headers[constants_1.HeaderKeys.PROVIDER]).version, (0, utils_1.parseAppId)(executableSchema.provider).version))) {
|
|
17
17
|
try {
|
|
18
|
-
const newSchema = (await apps.getAppFile(ctx.headers[constants_1.
|
|
18
|
+
const newSchema = (await apps.getAppFile(ctx.headers[constants_1.HeaderKeys.PROVIDER], 'public/schema.graphql')).data.toString('utf-8');
|
|
19
19
|
graphql.schema = newSchema;
|
|
20
20
|
const newRunnableSchema = (0, index_1.makeSchema)(graphql);
|
|
21
21
|
executableSchema.schema = newRunnableSchema.schema;
|
|
22
|
-
executableSchema.provider = ctx.headers[constants_1.
|
|
22
|
+
executableSchema.provider = ctx.headers[constants_1.HeaderKeys.PROVIDER];
|
|
23
23
|
}
|
|
24
24
|
catch (error) {
|
|
25
25
|
logger.error({ error, message: 'Update schema failed', app });
|
|
@@ -27,9 +27,9 @@ const createPubContextMiddleware = (routeId, { smartcache }) => {
|
|
|
27
27
|
...(0, context_1.prepareHandlerCtx)(header, ctx.tracing),
|
|
28
28
|
...(smartcache && { recorder: ctx.state.recorder }),
|
|
29
29
|
route: {
|
|
30
|
-
declarer: header[constants_1.
|
|
30
|
+
declarer: header[constants_1.HeaderKeys.COLOSSUS_ROUTE_DECLARER],
|
|
31
31
|
id: routeId,
|
|
32
|
-
params: (0, querystring_1.parse)(header[constants_1.
|
|
32
|
+
params: (0, querystring_1.parse)(header[constants_1.HeaderKeys.COLOSSUS_PARAMS]),
|
|
33
33
|
type: 'public',
|
|
34
34
|
},
|
|
35
35
|
};
|
|
@@ -6,17 +6,17 @@ const cachingStrategies = [
|
|
|
6
6
|
{
|
|
7
7
|
forbidden: [],
|
|
8
8
|
path: '/_v/private/',
|
|
9
|
-
vary: [constants_1.
|
|
9
|
+
vary: [constants_1.HeaderKeys.SEGMENT, constants_1.HeaderKeys.SESSION],
|
|
10
10
|
},
|
|
11
11
|
{
|
|
12
|
-
forbidden: [constants_1.
|
|
12
|
+
forbidden: [constants_1.HeaderKeys.SEGMENT, constants_1.HeaderKeys.SESSION],
|
|
13
13
|
path: '/_v/public/',
|
|
14
14
|
vary: [],
|
|
15
15
|
},
|
|
16
16
|
{
|
|
17
|
-
forbidden: [constants_1.
|
|
17
|
+
forbidden: [constants_1.HeaderKeys.SESSION],
|
|
18
18
|
path: '/_v/segment/',
|
|
19
|
-
vary: [constants_1.
|
|
19
|
+
vary: [constants_1.HeaderKeys.SEGMENT],
|
|
20
20
|
},
|
|
21
21
|
];
|
|
22
22
|
const shouldVaryByHeader = (ctx, header, strategy) => {
|
|
@@ -41,12 +41,12 @@ async function vary(ctx, next) {
|
|
|
41
41
|
await next();
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
|
-
ctx.vary(constants_1.
|
|
45
|
-
if (shouldVaryByHeader(ctx, constants_1.
|
|
46
|
-
ctx.vary(constants_1.
|
|
44
|
+
ctx.vary(constants_1.HeaderKeys.LOCALE);
|
|
45
|
+
if (shouldVaryByHeader(ctx, constants_1.HeaderKeys.SEGMENT, strategy)) {
|
|
46
|
+
ctx.vary(constants_1.HeaderKeys.SEGMENT);
|
|
47
47
|
}
|
|
48
|
-
if (shouldVaryByHeader(ctx, constants_1.
|
|
49
|
-
ctx.vary(constants_1.
|
|
48
|
+
if (shouldVaryByHeader(ctx, constants_1.HeaderKeys.SESSION, strategy)) {
|
|
49
|
+
ctx.vary(constants_1.HeaderKeys.SESSION);
|
|
50
50
|
}
|
|
51
51
|
await next();
|
|
52
52
|
}
|
|
@@ -7,7 +7,7 @@ const console_1 = require("./../../../logger/console");
|
|
|
7
7
|
const routerFromPublicHttpHandlers = (routes) => {
|
|
8
8
|
return async (ctx, next) => {
|
|
9
9
|
var _a;
|
|
10
|
-
const routeId = ctx.get(constants_1.
|
|
10
|
+
const routeId = ctx.get(constants_1.HeaderKeys.COLOSSUS_ROUTE_ID);
|
|
11
11
|
if (!routeId) {
|
|
12
12
|
return next();
|
|
13
13
|
}
|
|
@@ -16,23 +16,23 @@ const getPlatform = (account) => {
|
|
|
16
16
|
const prepareHandlerCtx = (header, tracingContext) => {
|
|
17
17
|
var _a;
|
|
18
18
|
const partialContext = {
|
|
19
|
-
account: header[constants_1.
|
|
20
|
-
authToken: header[constants_1.
|
|
21
|
-
binding: header[constants_1.
|
|
22
|
-
host: header[constants_1.
|
|
23
|
-
locale: header[constants_1.
|
|
24
|
-
operationId: header[constants_1.
|
|
25
|
-
platform: header[constants_1.
|
|
26
|
-
product: header[constants_1.
|
|
27
|
-
production: ((_a = header[constants_1.
|
|
19
|
+
account: header[constants_1.HeaderKeys.ACCOUNT],
|
|
20
|
+
authToken: header[constants_1.HeaderKeys.CREDENTIAL],
|
|
21
|
+
binding: header[constants_1.HeaderKeys.BINDING] ? (0, binding_1.parseBindingHeaderValue)(header[constants_1.HeaderKeys.BINDING]) : undefined,
|
|
22
|
+
host: header[constants_1.HeaderKeys.FORWARDED_HOST],
|
|
23
|
+
locale: header[constants_1.HeaderKeys.LOCALE],
|
|
24
|
+
operationId: header[constants_1.HeaderKeys.OPERATION_ID] || (0, v4_1.default)(),
|
|
25
|
+
platform: header[constants_1.HeaderKeys.PLATFORM] || getPlatform(header[constants_1.HeaderKeys.ACCOUNT]),
|
|
26
|
+
product: header[constants_1.HeaderKeys.PRODUCT],
|
|
27
|
+
production: ((_a = header[constants_1.HeaderKeys.WORKSPACE_IS_PRODUCTION]) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'true' || false,
|
|
28
28
|
region: constants_1.REGION,
|
|
29
|
-
requestId: header[constants_1.
|
|
30
|
-
segmentToken: header[constants_1.
|
|
31
|
-
sessionToken: header[constants_1.
|
|
32
|
-
tenant: header[constants_1.
|
|
29
|
+
requestId: header[constants_1.HeaderKeys.REQUEST_ID],
|
|
30
|
+
segmentToken: header[constants_1.HeaderKeys.SEGMENT],
|
|
31
|
+
sessionToken: header[constants_1.HeaderKeys.SESSION],
|
|
32
|
+
tenant: header[constants_1.HeaderKeys.TENANT] ? (0, tenant_1.parseTenantHeaderValue)(header[constants_1.HeaderKeys.TENANT]) : undefined,
|
|
33
33
|
tracer: new UserLandTracer_1.UserLandTracer(tracingContext === null || tracingContext === void 0 ? void 0 : tracingContext.tracer, tracingContext === null || tracingContext === void 0 ? void 0 : tracingContext.currentSpan),
|
|
34
34
|
userAgent: process.env.VTEX_APP_ID || '',
|
|
35
|
-
workspace: header[constants_1.
|
|
35
|
+
workspace: header[constants_1.HeaderKeys.WORKSPACE],
|
|
36
36
|
};
|
|
37
37
|
return {
|
|
38
38
|
...partialContext,
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Recorder = void 0;
|
|
4
4
|
const ramda_1 = require("ramda");
|
|
5
5
|
const constants_1 = require("./../../../../constants");
|
|
6
|
-
const HEADERS = [constants_1.
|
|
6
|
+
const HEADERS = [constants_1.HeaderKeys.META, constants_1.HeaderKeys.META_BUCKET];
|
|
7
7
|
class Recorder {
|
|
8
8
|
constructor() {
|
|
9
9
|
this._record = HEADERS.reduce((acc, headerName) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vtex/api",
|
|
3
|
-
"version": "7.2.
|
|
3
|
+
"version": "7.2.2-beta.0",
|
|
4
4
|
"description": "VTEX I/O API client",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
"@types/koa": "^2.11.0",
|
|
55
55
|
"@types/koa-compose": "^3.2.3",
|
|
56
56
|
"@vtex/diagnostics-nodejs": "0.1.0-io-beta.20",
|
|
57
|
+
"@vtex/diagnostics-semconv": "^1.1.2",
|
|
57
58
|
"@vtex/node-error-report": "^0.0.3",
|
|
58
59
|
"@wry/equality": "^0.1.9",
|
|
59
60
|
"agentkeepalive": "^4.0.2",
|