@vtex/api 6.48.1-beta.2 → 6.48.1-beta.3
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/GraphQLClient.d.ts +1 -1
- package/lib/HttpClient/HttpClient.d.ts +2 -3
- package/lib/HttpClient/HttpClient.js +14 -14
- package/lib/HttpClient/agents.d.ts +2 -5
- package/lib/HttpClient/agents.js +4 -10
- package/lib/HttpClient/index.js +2 -7
- package/lib/HttpClient/middlewares/cache.d.ts +1 -1
- package/lib/HttpClient/middlewares/cache.js +36 -38
- package/lib/HttpClient/middlewares/cancellationToken.d.ts +1 -1
- package/lib/HttpClient/middlewares/cancellationToken.js +1 -2
- package/lib/HttpClient/middlewares/inflight.d.ts +1 -1
- package/lib/HttpClient/middlewares/inflight.js +3 -6
- package/lib/HttpClient/middlewares/memoization.d.ts +1 -1
- package/lib/HttpClient/middlewares/memoization.js +8 -9
- package/lib/HttpClient/middlewares/metrics.js +7 -8
- package/lib/HttpClient/middlewares/notFound.d.ts +1 -1
- package/lib/HttpClient/middlewares/notFound.js +2 -4
- package/lib/HttpClient/middlewares/recorder.js +1 -2
- package/lib/HttpClient/middlewares/request/HttpAgentSingleton.js +1 -1
- package/lib/HttpClient/middlewares/request/index.d.ts +1 -1
- package/lib/HttpClient/middlewares/request/index.js +10 -13
- package/lib/HttpClient/middlewares/request/setupAxios/index.d.ts +1 -0
- package/lib/HttpClient/middlewares/request/setupAxios/index.js +4 -5
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/exponentialBackoff.js +5 -6
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/index.js +0 -1
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/index.js +8 -8
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/spanSetup.js +8 -10
- package/lib/HttpClient/middlewares/tracing.js +10 -11
- package/lib/HttpClient/typings.d.ts +2 -2
- package/lib/caches/DiskCache.js +2 -2
- package/lib/caches/LRUCache.d.ts +2 -2
- package/lib/caches/LRUDiskCache.d.ts +1 -1
- package/lib/caches/LRUDiskCache.js +2 -2
- package/lib/caches/MultilayeredCache.d.ts +2 -2
- package/lib/caches/MultilayeredCache.js +6 -6
- package/lib/caches/index.js +2 -6
- package/lib/caches/typings.d.ts +5 -5
- package/lib/clients/IOClient.d.ts +1 -1
- package/lib/clients/IOClients.d.ts +1 -1
- package/lib/clients/apps/AppClient.js +1 -1
- package/lib/clients/apps/AppGraphQLClient.js +1 -1
- package/lib/clients/apps/Billing.d.ts +1 -1
- package/lib/clients/apps/Builder.d.ts +7 -7
- package/lib/clients/apps/Builder.js +1 -1
- package/lib/clients/apps/MessagesGraphQL.d.ts +1 -1
- package/lib/clients/apps/MessagesGraphQL.js +3 -3
- package/lib/clients/apps/Settings.js +3 -3
- package/lib/clients/apps/catalogGraphQL/index.d.ts +4 -4
- package/lib/clients/apps/catalogGraphQL/index.js +4 -4
- package/lib/clients/apps/index.js +2 -6
- package/lib/clients/external/ID.d.ts +4 -4
- package/lib/clients/external/PaymentProvider.d.ts +2 -2
- package/lib/clients/external/index.js +2 -6
- package/lib/clients/index.js +2 -6
- package/lib/clients/infra/Apps.d.ts +27 -32
- package/lib/clients/infra/Apps.js +16 -16
- package/lib/clients/infra/Assets.d.ts +5 -6
- package/lib/clients/infra/Assets.js +11 -11
- package/lib/clients/infra/BillingMetrics.d.ts +1 -1
- package/lib/clients/infra/Events.d.ts +1 -1
- package/lib/clients/infra/Events.js +1 -1
- package/lib/clients/infra/Housekeeper.d.ts +3 -3
- package/lib/clients/infra/Registry.d.ts +17 -23
- package/lib/clients/infra/Registry.js +3 -3
- package/lib/clients/infra/Router.d.ts +8 -8
- package/lib/clients/infra/Sphinx.d.ts +2 -2
- package/lib/clients/infra/VBase.d.ts +14 -15
- package/lib/clients/infra/VBase.js +2 -2
- package/lib/clients/infra/Workspaces.d.ts +7 -7
- package/lib/clients/infra/index.js +2 -6
- package/lib/clients/janus/JanusClient.d.ts +1 -1
- package/lib/clients/janus/LicenseManager.js +1 -1
- package/lib/clients/janus/Segment.d.ts +3 -3
- package/lib/clients/janus/Segment.js +2 -2
- package/lib/clients/janus/Session.d.ts +2 -2
- package/lib/clients/janus/Tenant.d.ts +1 -1
- package/lib/clients/janus/index.js +2 -6
- package/lib/constants.d.ts +1 -1
- package/lib/constants.js +1 -1
- package/lib/errors/ResolverError.js +1 -1
- package/lib/errors/index.js +2 -6
- package/lib/index.js +2 -6
- package/lib/metrics/MetricsAccumulator.d.ts +2 -2
- package/lib/metrics/MetricsAccumulator.js +9 -9
- package/lib/responses.d.ts +4 -4
- package/lib/service/index.js +6 -7
- package/lib/service/loaders.js +6 -8
- package/lib/service/logger/console.js +4 -7
- package/lib/service/logger/index.js +2 -6
- package/lib/service/logger/logger.js +2 -2
- package/lib/service/logger/metricsLogger.js +10 -10
- package/lib/service/master.js +6 -7
- package/lib/service/metrics/requestMetricsMiddleware.js +13 -14
- package/lib/service/tracing/TracerSingleton.js +9 -9
- package/lib/service/tracing/metrics/MetricNames.js +12 -12
- package/lib/service/tracing/metrics/instruments.js +7 -14
- package/lib/service/tracing/metrics/measurers/EventLoopLagMeasurer.js +5 -5
- package/lib/service/tracing/tracingMiddlewares.js +15 -18
- package/lib/service/worker/index.js +23 -24
- package/lib/service/worker/listeners.js +1 -2
- package/lib/service/worker/runtime/Service.js +1 -1
- package/lib/service/worker/runtime/builtIn/handlers.js +3 -6
- package/lib/service/worker/runtime/builtIn/middlewares.js +3 -5
- package/lib/service/worker/runtime/events/index.d.ts +1 -1
- package/lib/service/worker/runtime/events/index.js +10 -11
- package/lib/service/worker/runtime/events/middlewares/body.js +2 -2
- package/lib/service/worker/runtime/events/middlewares/context.js +1 -1
- package/lib/service/worker/runtime/events/router.js +2 -3
- package/lib/service/worker/runtime/graphql/index.js +7 -8
- package/lib/service/worker/runtime/graphql/middlewares/error.js +5 -5
- package/lib/service/worker/runtime/graphql/middlewares/query.js +6 -7
- package/lib/service/worker/runtime/graphql/middlewares/response.js +1 -1
- package/lib/service/worker/runtime/graphql/middlewares/run.js +2 -3
- package/lib/service/worker/runtime/graphql/middlewares/updateSchema.js +3 -4
- package/lib/service/worker/runtime/graphql/middlewares/upload.js +1 -1
- package/lib/service/worker/runtime/graphql/schema/index.d.ts +1 -1
- package/lib/service/worker/runtime/graphql/schema/index.js +7 -8
- package/lib/service/worker/runtime/graphql/schema/messagesLoaderV2.d.ts +2 -2
- package/lib/service/worker/runtime/graphql/schema/messagesLoaderV2.js +3 -4
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Deprecated.js +1 -1
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Settings.js +1 -1
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/TranslatableV2.js +2 -2
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/TranslateTo.js +2 -2
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/index.js +1 -1
- package/lib/service/worker/runtime/graphql/schema/typeDefs/index.js +1 -2
- package/lib/service/worker/runtime/graphql/schema/typeDefs/sanitizedString.js +2 -2
- package/lib/service/worker/runtime/graphql/typings.d.ts +3 -3
- package/lib/service/worker/runtime/graphql/utils/cacheControl.js +1 -2
- package/lib/service/worker/runtime/graphql/utils/error.js +9 -10
- package/lib/service/worker/runtime/graphql/utils/pathname.js +2 -3
- package/lib/service/worker/runtime/graphql/utils/translations.d.ts +1 -1
- package/lib/service/worker/runtime/graphql/utils/translations.js +4 -7
- package/lib/service/worker/runtime/http/index.d.ts +2 -2
- package/lib/service/worker/runtime/http/index.js +20 -22
- package/lib/service/worker/runtime/http/middlewares/context.js +5 -7
- package/lib/service/worker/runtime/http/middlewares/error.js +1 -1
- package/lib/service/worker/runtime/http/middlewares/rateLimit.js +1 -1
- package/lib/service/worker/runtime/http/middlewares/setCookie.js +5 -5
- package/lib/service/worker/runtime/http/middlewares/settings.d.ts +1 -1
- package/lib/service/worker/runtime/http/middlewares/settings.js +9 -13
- package/lib/service/worker/runtime/http/middlewares/timings.js +3 -3
- package/lib/service/worker/runtime/http/router.js +2 -3
- package/lib/service/worker/runtime/http/routes.js +5 -8
- package/lib/service/worker/runtime/method.d.ts +2 -2
- package/lib/service/worker/runtime/method.js +1 -1
- package/lib/service/worker/runtime/statusTrack.d.ts +1 -1
- package/lib/service/worker/runtime/statusTrack.js +5 -10
- package/lib/service/worker/runtime/typings.d.ts +10 -10
- package/lib/service/worker/runtime/utils/compose.d.ts +2 -2
- package/lib/service/worker/runtime/utils/compose.js +2 -4
- package/lib/service/worker/runtime/utils/context.d.ts +2 -2
- package/lib/service/worker/runtime/utils/context.js +4 -5
- package/lib/service/worker/runtime/utils/recorder.js +1 -1
- package/lib/service/worker/runtime/utils/toArray.js +1 -2
- package/lib/tracing/UserLandTracer.js +2 -3
- package/lib/tracing/errorReporting/ErrorReport.js +13 -13
- package/lib/tracing/index.js +1 -1
- package/lib/tracing/utils.js +4 -5
- package/lib/utils/MineWinsConflictsResolver.d.ts +4 -4
- package/lib/utils/MineWinsConflictsResolver.js +10 -10
- package/lib/utils/app.js +23 -39
- package/lib/utils/appsStaleIfError.d.ts +0 -1
- package/lib/utils/appsStaleIfError.js +9 -17
- package/lib/utils/billingOptions.js +1 -2
- package/lib/utils/binding.js +2 -4
- package/lib/utils/buildFullPath.d.ts +11 -0
- package/lib/utils/buildFullPath.js +54 -0
- package/lib/utils/domain.js +1 -1
- package/lib/utils/error.js +4 -5
- package/lib/utils/index.js +2 -6
- package/lib/utils/log.js +2 -3
- package/lib/utils/message.js +5 -8
- package/lib/utils/renameBy.js +1 -2
- package/lib/utils/retry.js +6 -8
- package/lib/utils/status.js +1 -2
- package/lib/utils/tenant.js +2 -4
- package/lib/utils/time.d.ts +1 -1
- package/lib/utils/time.js +14 -23
- package/package.json +2 -2
|
@@ -12,18 +12,17 @@ const updateSchema_1 = require("./middlewares/updateSchema");
|
|
|
12
12
|
const upload_1 = require("./middlewares/upload");
|
|
13
13
|
const schema_1 = require("./schema");
|
|
14
14
|
exports.GRAPHQL_ROUTE = '__graphql';
|
|
15
|
-
|
|
16
|
-
const executableSchema =
|
|
15
|
+
exports.createGraphQLRoute = (graphql, clientsConfig, serviceRoute, routeId, globalLimiter) => {
|
|
16
|
+
const executableSchema = schema_1.makeSchema(graphql);
|
|
17
17
|
const pipeline = [
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
tracingMiddlewares_1.nameSpanOperationMiddleware('graphql-handler', exports.GRAPHQL_ROUTE),
|
|
19
|
+
updateSchema_1.updateSchema(graphql, executableSchema),
|
|
20
20
|
context_1.injectGraphqlContext,
|
|
21
21
|
response_1.response,
|
|
22
22
|
error_1.graphqlError,
|
|
23
23
|
upload_1.upload,
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
query_1.extractQuery(executableSchema),
|
|
25
|
+
run_1.run(executableSchema),
|
|
26
26
|
];
|
|
27
|
-
return
|
|
27
|
+
return http_1.createPrivateHttpRoute(clientsConfig, pipeline, serviceRoute, routeId, globalLimiter);
|
|
28
28
|
};
|
|
29
|
-
exports.createGraphQLRoute = createGraphQLRoute;
|
|
@@ -9,7 +9,7 @@ const logger_1 = require("../../../../logger");
|
|
|
9
9
|
const error_1 = require("../utils/error");
|
|
10
10
|
const pathname_1 = require("../utils/pathname");
|
|
11
11
|
const TWO_SECONDS_S = 2;
|
|
12
|
-
const uniqErrorsByPath = (errors) =>
|
|
12
|
+
const uniqErrorsByPath = (errors) => ramda_1.uniqBy(e => e.extensions && e.extensions.exception && e.extensions.exception.request
|
|
13
13
|
? e.extensions.exception.request.path
|
|
14
14
|
: e, errors);
|
|
15
15
|
const createLogErrorToSplunk = (vtex) => (err) => {
|
|
@@ -22,7 +22,7 @@ const createLogErrorToSplunk = (vtex) => (err) => {
|
|
|
22
22
|
}
|
|
23
23
|
// Add pathName to each error
|
|
24
24
|
if (err.path) {
|
|
25
|
-
err.pathName =
|
|
25
|
+
err.pathName = pathname_1.generatePathName(err.path);
|
|
26
26
|
}
|
|
27
27
|
const log = {
|
|
28
28
|
...err,
|
|
@@ -48,8 +48,8 @@ async function graphqlError(ctx, next) {
|
|
|
48
48
|
await next();
|
|
49
49
|
const response = ctx.graphql.graphqlResponse;
|
|
50
50
|
if (response && Array.isArray(response.errors)) {
|
|
51
|
-
const formatter =
|
|
52
|
-
graphQLErrors =
|
|
51
|
+
const formatter = error_1.createFormatError(ctx);
|
|
52
|
+
graphQLErrors = apollo_server_errors_1.formatApolloErrors(response.errors, { formatter });
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
catch (e) {
|
|
@@ -60,7 +60,7 @@ async function graphqlError(ctx, next) {
|
|
|
60
60
|
ctx.status = RequestCancelledError_1.cancelledRequestStatus;
|
|
61
61
|
return;
|
|
62
62
|
}
|
|
63
|
-
const formatError =
|
|
63
|
+
const formatError = error_1.createFormatError(ctx);
|
|
64
64
|
graphQLErrors = Array.isArray(e)
|
|
65
65
|
? e.map(formatError)
|
|
66
66
|
: [formatError(e)];
|
|
@@ -10,7 +10,7 @@ const documentStorage = new LRUCache_1.LRUCache({
|
|
|
10
10
|
max: 500,
|
|
11
11
|
});
|
|
12
12
|
const queryFromUrl = (url) => {
|
|
13
|
-
const parsedUrl =
|
|
13
|
+
const parsedUrl = url_1.parse(url, true);
|
|
14
14
|
const { query: querystringObj } = parsedUrl;
|
|
15
15
|
// Having a BODY_HASH means the query is in the body
|
|
16
16
|
if (querystringObj && querystringObj[constants_1.BODY_HASH]) {
|
|
@@ -24,24 +24,24 @@ const queryFromUrl = (url) => {
|
|
|
24
24
|
return querystringObj;
|
|
25
25
|
};
|
|
26
26
|
const parseAndValidateQueryToSchema = (query, schema) => {
|
|
27
|
-
const document =
|
|
28
|
-
const validation =
|
|
27
|
+
const document = graphql_1.parse(query);
|
|
28
|
+
const validation = graphql_1.validate(schema, document);
|
|
29
29
|
if (Array.isArray(validation) && validation.length > 0) {
|
|
30
30
|
throw validation;
|
|
31
31
|
}
|
|
32
32
|
return document;
|
|
33
33
|
};
|
|
34
|
-
|
|
34
|
+
exports.extractQuery = (executableSchema) => async function parseAndValidateQuery(ctx, next) {
|
|
35
35
|
const { request, req } = ctx;
|
|
36
36
|
let query;
|
|
37
37
|
if (request.is('multipart/form-data')) {
|
|
38
38
|
query = request.body;
|
|
39
39
|
}
|
|
40
40
|
else if (request.method.toUpperCase() === 'POST') {
|
|
41
|
-
query = await
|
|
41
|
+
query = await co_body_1.json(req, { limit: '3mb' });
|
|
42
42
|
}
|
|
43
43
|
else {
|
|
44
|
-
query = queryFromUrl(request.url) || (await
|
|
44
|
+
query = queryFromUrl(request.url) || (await co_body_1.json(req, { limit: '3mb' }));
|
|
45
45
|
}
|
|
46
46
|
// Assign the query before setting the query.document because if the
|
|
47
47
|
// validation fails we don't loose the query in our error log
|
|
@@ -51,4 +51,3 @@ const extractQuery = (executableSchema) => async function parseAndValidateQuery(
|
|
|
51
51
|
})));
|
|
52
52
|
await next();
|
|
53
53
|
};
|
|
54
|
-
exports.extractQuery = extractQuery;
|
|
@@ -23,7 +23,7 @@ async function response(ctx, next) {
|
|
|
23
23
|
var _a;
|
|
24
24
|
await next();
|
|
25
25
|
const { cacheControl, status, graphqlResponse, } = ctx.graphql;
|
|
26
|
-
const cacheControlHeader =
|
|
26
|
+
const cacheControlHeader = cacheControl_1.cacheControlHTTP(ctx);
|
|
27
27
|
ctx.set(constants_1.CACHE_CONTROL_HEADER, cacheControlHeader);
|
|
28
28
|
if (status === 'error') {
|
|
29
29
|
// Do not generate etag for errors
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.run = void 0;
|
|
4
4
|
const graphql_1 = require("graphql");
|
|
5
|
-
|
|
5
|
+
exports.run = (executableSchema) => async function runHttpQuery(ctx, next) {
|
|
6
6
|
const { graphql: { query }, } = ctx;
|
|
7
7
|
const { document, operationName, variables: variableValues } = query;
|
|
8
8
|
const schema = executableSchema.schema;
|
|
9
|
-
const response = await
|
|
9
|
+
const response = await graphql_1.execute({
|
|
10
10
|
contextValue: ctx,
|
|
11
11
|
document,
|
|
12
12
|
fieldResolver: (root, _, __, info) => root[info.fieldName],
|
|
@@ -18,4 +18,3 @@ const run = (executableSchema) => async function runHttpQuery(ctx, next) {
|
|
|
18
18
|
ctx.graphql.graphqlResponse = response;
|
|
19
19
|
await next();
|
|
20
20
|
};
|
|
21
|
-
exports.run = run;
|
|
@@ -4,7 +4,7 @@ exports.updateSchema = void 0;
|
|
|
4
4
|
const constants_1 = require("../../../../../constants");
|
|
5
5
|
const utils_1 = require("../../../../../utils");
|
|
6
6
|
const index_1 = require("../schema/index");
|
|
7
|
-
|
|
7
|
+
exports.updateSchema = (graphql, executableSchema) => async function updateRunnableSchema(ctx, next) {
|
|
8
8
|
const { clients: { apps }, vtex: { logger }, app, } = ctx;
|
|
9
9
|
if (!ctx.headers[constants_1.PROVIDER_HEADER]) {
|
|
10
10
|
await next();
|
|
@@ -13,11 +13,11 @@ const updateSchema = (graphql, executableSchema) => async function updateRunnabl
|
|
|
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
|
-
|
|
16
|
+
utils_1.majorEqualAndGreaterThan(utils_1.parseAppId(ctx.headers[constants_1.PROVIDER_HEADER]).version, utils_1.parseAppId(executableSchema.provider).version))) {
|
|
17
17
|
try {
|
|
18
18
|
const newSchema = (await apps.getAppFile(ctx.headers[constants_1.PROVIDER_HEADER], 'public/schema.graphql')).data.toString('utf-8');
|
|
19
19
|
graphql.schema = newSchema;
|
|
20
|
-
const newRunnableSchema =
|
|
20
|
+
const newRunnableSchema = index_1.makeSchema(graphql);
|
|
21
21
|
executableSchema.schema = newRunnableSchema.schema;
|
|
22
22
|
executableSchema.provider = ctx.headers[constants_1.PROVIDER_HEADER];
|
|
23
23
|
}
|
|
@@ -27,4 +27,3 @@ const updateSchema = (graphql, executableSchema) => async function updateRunnabl
|
|
|
27
27
|
}
|
|
28
28
|
await next();
|
|
29
29
|
};
|
|
30
|
-
exports.updateSchema = updateSchema;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.upload = void 0;
|
|
4
4
|
const graphql_upload_1 = require("graphql-upload");
|
|
5
|
-
const graphqlUpload =
|
|
5
|
+
const graphqlUpload = graphql_upload_1.graphqlUploadKoa({
|
|
6
6
|
maxFieldSize: 1e6,
|
|
7
7
|
maxFileSize: 4 * 1e6,
|
|
8
8
|
maxFiles: 10,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IOClients } from '../../../../../clients/IOClients';
|
|
2
2
|
import { GraphQLOptions, ParamsContext, RecorderState } from '../../typings';
|
|
3
|
-
export type SchemaMetaData = Record<string, boolean>;
|
|
3
|
+
export declare type SchemaMetaData = Record<string, boolean>;
|
|
4
4
|
export declare const makeSchema: <ClientsT extends IOClients = IOClients, StateT extends RecorderState = RecorderState, CustomT extends ParamsContext = ParamsContext>(options: GraphQLOptions<ClientsT, StateT, CustomT>) => {
|
|
5
5
|
schema: import("graphql").GraphQLSchema;
|
|
6
6
|
hasProvider: boolean;
|
|
@@ -6,18 +6,18 @@ const graphql_tools_1 = require("graphql-tools");
|
|
|
6
6
|
const ramda_1 = require("ramda");
|
|
7
7
|
const schemaDirectives_1 = require("./schemaDirectives");
|
|
8
8
|
const typeDefs_1 = require("./typeDefs");
|
|
9
|
-
const mergeTypeDefs = (appTypeDefs, schemaMetaData) => [appTypeDefs,
|
|
9
|
+
const mergeTypeDefs = (appTypeDefs, schemaMetaData) => [appTypeDefs, typeDefs_1.nativeTypeDefs(schemaMetaData), schemaDirectives_1.nativeSchemaDirectivesTypeDefs].join('\n\n');
|
|
10
10
|
const hasScalar = (typeDefs) => (scalar) => new RegExp(`scalar(\\s)+${scalar}(\\s\\n)+`).test(typeDefs);
|
|
11
11
|
const extractSchemaMetaData = (typeDefs) => {
|
|
12
|
-
const scalars =
|
|
13
|
-
const scalarsPresentInSchema =
|
|
14
|
-
return
|
|
12
|
+
const scalars = ramda_1.keys(typeDefs_1.nativeResolvers);
|
|
13
|
+
const scalarsPresentInSchema = ramda_1.map(hasScalar(typeDefs), scalars);
|
|
14
|
+
return ramda_1.zipObj(scalars, scalarsPresentInSchema);
|
|
15
15
|
};
|
|
16
|
-
|
|
16
|
+
exports.makeSchema = (options) => {
|
|
17
17
|
const { resolvers: appResolvers, schema: appSchema, schemaDirectives: appDirectives } = options;
|
|
18
|
-
const appTypeDefs = appSchema ||
|
|
18
|
+
const appTypeDefs = appSchema || fs_extra_1.readFileSync('./service/schema.graphql', 'utf8');
|
|
19
19
|
const schemaMetaData = extractSchemaMetaData(appTypeDefs);
|
|
20
|
-
const executableSchema =
|
|
20
|
+
const executableSchema = graphql_tools_1.makeExecutableSchema({
|
|
21
21
|
resolvers: {
|
|
22
22
|
...appResolvers,
|
|
23
23
|
...typeDefs_1.nativeResolvers,
|
|
@@ -30,4 +30,3 @@ const makeSchema = (options) => {
|
|
|
30
30
|
});
|
|
31
31
|
return { schema: executableSchema, hasProvider: appSchema ? true : false };
|
|
32
32
|
};
|
|
33
|
-
exports.makeSchema = makeSchema;
|
|
@@ -2,5 +2,5 @@ import DataLoader from 'dataloader';
|
|
|
2
2
|
import { Message } from '../../../../../clients/apps/MessagesGraphQL';
|
|
3
3
|
import { AppMetaInfo } from '../../../../../clients/infra/Apps';
|
|
4
4
|
import { IOClients } from './../../../../../clients/IOClients';
|
|
5
|
-
export declare const createMessagesLoader: ({ messagesGraphQL, assets }: IOClients, to: string, dependencies?: AppMetaInfo[]) => DataLoader<Message, string>;
|
|
6
|
-
export type MessagesLoaderV2 = ReturnType<typeof createMessagesLoader>;
|
|
5
|
+
export declare const createMessagesLoader: ({ messagesGraphQL, assets }: IOClients, to: string, dependencies?: AppMetaInfo[] | undefined) => DataLoader<Message, string>;
|
|
6
|
+
export declare type MessagesLoaderV2 = ReturnType<typeof createMessagesLoader>;
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.createMessagesLoader = void 0;
|
|
7
7
|
const dataloader_1 = __importDefault(require("dataloader"));
|
|
8
8
|
const ramda_1 = require("ramda");
|
|
9
|
-
const sortByContentAndFrom = (indexedMessages) =>
|
|
9
|
+
const sortByContentAndFrom = (indexedMessages) => ramda_1.sortBy(([_, { content, from }]) => `__from:${from}__content:${content}`, indexedMessages);
|
|
10
10
|
// O(n) counting sort implementation
|
|
11
11
|
const sortByIndex = (indexedTranslations) => indexedTranslations.reduce((acc, [index, data]) => {
|
|
12
12
|
acc[index] = data;
|
|
@@ -50,7 +50,7 @@ const filterFromEqualsTo = (indexedMessages, to) => indexedMessages.reduce((acc,
|
|
|
50
50
|
toTranslate: [],
|
|
51
51
|
});
|
|
52
52
|
const messageToKey = ({ content, context, from }) => `:content:${content}:context:${context}:from:${from}`;
|
|
53
|
-
|
|
53
|
+
exports.createMessagesLoader = ({ messagesGraphQL, assets }, to, dependencies) => {
|
|
54
54
|
const loweredTo = to.toLowerCase();
|
|
55
55
|
const messagesDeps = dependencies && assets.getFilteredDependencies('vtex.messages@1.x', dependencies);
|
|
56
56
|
const depTree = messagesDeps && JSON.stringify(messagesDeps);
|
|
@@ -68,7 +68,7 @@ const createMessagesLoader = ({ messagesGraphQL, assets }, to, dependencies) =>
|
|
|
68
68
|
const translations = depTree
|
|
69
69
|
? await messagesGraphQL.translateWithDependencies({ ...args, depTree })
|
|
70
70
|
: await messagesGraphQL.translate(args);
|
|
71
|
-
const indexedTranslations =
|
|
71
|
+
const indexedTranslations = ramda_1.zip(originalIndexes, translations);
|
|
72
72
|
const allIndexedTranslations = [...indexedTranslations, ...original];
|
|
73
73
|
return sortByIndex(allIndexedTranslations);
|
|
74
74
|
}, {
|
|
@@ -78,4 +78,3 @@ const createMessagesLoader = ({ messagesGraphQL, assets }, to, dependencies) =>
|
|
|
78
78
|
maxBatchSize: 200,
|
|
79
79
|
});
|
|
80
80
|
};
|
|
81
|
-
exports.createMessagesLoader = createMessagesLoader;
|
|
@@ -28,7 +28,7 @@ class Deprecated extends graphql_tools_1.SchemaDirectiveVisitor {
|
|
|
28
28
|
this.maybeLogToSplunk({
|
|
29
29
|
headers: ctx.request.headers,
|
|
30
30
|
name,
|
|
31
|
-
query: ((_a = ctx.graphql.query) === null || _a === void 0 ? void 0 : _a.document) &&
|
|
31
|
+
query: ((_a = ctx.graphql.query) === null || _a === void 0 ? void 0 : _a.document) && graphql_1.print((_b = ctx.graphql.query) === null || _b === void 0 ? void 0 : _b.document),
|
|
32
32
|
reason,
|
|
33
33
|
variables: (_c = ctx.graphql.query) === null || _c === void 0 ? void 0 : _c.variables,
|
|
34
34
|
}, ctx.vtex.logger);
|
|
@@ -9,7 +9,7 @@ const addSettings = async (settings, ctx) => {
|
|
|
9
9
|
return ctx;
|
|
10
10
|
}
|
|
11
11
|
const { clients: { apps, assets } } = ctx;
|
|
12
|
-
const dependenciesSettings = await
|
|
12
|
+
const dependenciesSettings = await settings_1.getDependenciesSettings(apps, assets);
|
|
13
13
|
if (!ctx.vtex) {
|
|
14
14
|
ctx.vtex = {};
|
|
15
15
|
}
|
|
@@ -19,12 +19,12 @@ class TranslatableV2 extends graphql_tools_1.SchemaDirectiveVisitor {
|
|
|
19
19
|
const dependencies = withAppsMetaInfo ? await ctx.clients.apps.getAppsMetaInfos() : undefined;
|
|
20
20
|
ctx.loaders = {
|
|
21
21
|
...ctx.loaders,
|
|
22
|
-
messagesV2:
|
|
22
|
+
messagesV2: messagesLoaderV2_1.createMessagesLoader(ctx.clients, to, dependencies),
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
25
|
const response = await resolve(root, args, ctx, info);
|
|
26
26
|
const { vtex, loaders: { messagesV2 } } = ctx;
|
|
27
|
-
const handler =
|
|
27
|
+
const handler = translations_1.handleSingleString(vtex, messagesV2, behavior, 'translatableV2');
|
|
28
28
|
return Array.isArray(response)
|
|
29
29
|
? Promise.all(response.map(handler))
|
|
30
30
|
: handler(response);
|
|
@@ -15,12 +15,12 @@ class TranslateTo extends graphql_tools_1.SchemaDirectiveVisitor {
|
|
|
15
15
|
const dependencies = await ctx.clients.apps.getAppsMetaInfos();
|
|
16
16
|
ctx.loaders = {
|
|
17
17
|
...ctx.loaders,
|
|
18
|
-
immutableMessagesV2:
|
|
18
|
+
immutableMessagesV2: messagesLoaderV2_1.createMessagesLoader(ctx.clients, language, dependencies),
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
const response = (await resolve(root, args, ctx, info));
|
|
22
22
|
const { vtex, loaders: { immutableMessagesV2 }, } = ctx;
|
|
23
|
-
const handler =
|
|
23
|
+
const handler = translations_1.handleSingleString(vtex, immutableMessagesV2, behavior, 'translateTo');
|
|
24
24
|
return Array.isArray(response) ? Promise.all(response.map(handler)) : handler(response);
|
|
25
25
|
};
|
|
26
26
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.nativeSchemaDirectivesTypeDefs = exports.nativeSchemaDirectives =
|
|
3
|
+
exports.nativeSchemaDirectivesTypeDefs = exports.nativeSchemaDirectives = void 0;
|
|
4
4
|
const Auth_1 = require("./Auth");
|
|
5
5
|
const CacheControl_1 = require("./CacheControl");
|
|
6
6
|
const Deprecated_1 = require("./Deprecated");
|
|
@@ -10,5 +10,4 @@ exports.nativeResolvers = {
|
|
|
10
10
|
'IOUpload': ioUpload_1.resolvers,
|
|
11
11
|
'Upload': graphql_upload_1.GraphQLUpload,
|
|
12
12
|
};
|
|
13
|
-
|
|
14
|
-
exports.nativeTypeDefs = nativeTypeDefs;
|
|
13
|
+
exports.nativeTypeDefs = (metaData) => ramda_1.reduce((acc, scalar) => !metaData[scalar] ? `${acc}\nscalar ${scalar}\n` : acc, '', ramda_1.keys(exports.nativeResolvers));
|
|
@@ -7,10 +7,10 @@ const defaultName = 'IOSanitizedString';
|
|
|
7
7
|
exports.scalar = defaultName;
|
|
8
8
|
const noop = (html) => html;
|
|
9
9
|
const serialize = (input, options) => {
|
|
10
|
-
return
|
|
10
|
+
return xss_1.filterXSS(input, options);
|
|
11
11
|
};
|
|
12
12
|
const parseValue = (value, options) => {
|
|
13
|
-
return
|
|
13
|
+
return xss_1.filterXSS(value, options);
|
|
14
14
|
};
|
|
15
15
|
class IOSanitizedStringType extends graphql_1.GraphQLScalarType {
|
|
16
16
|
constructor(options) {
|
|
@@ -6,8 +6,8 @@ export interface Query {
|
|
|
6
6
|
operationName?: string;
|
|
7
7
|
document: DocumentNode;
|
|
8
8
|
}
|
|
9
|
-
type TypeFromPromise<T> = T extends Promise<infer U> ? U : T;
|
|
10
|
-
export type GraphQLResponse = TypeFromPromise<ReturnType<typeof execute>>;
|
|
9
|
+
declare type TypeFromPromise<T> = T extends Promise<infer U> ? U : T;
|
|
10
|
+
export declare type GraphQLResponse = TypeFromPromise<ReturnType<typeof execute>>;
|
|
11
11
|
export interface GraphQLCacheControl {
|
|
12
12
|
maxAge: number;
|
|
13
13
|
scope: 'private' | 'public' | 'segment';
|
|
@@ -22,7 +22,7 @@ export interface GraphQLContext extends ParamsContext {
|
|
|
22
22
|
cacheControl: GraphQLCacheControl;
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
|
-
export type GraphQLServiceContext = ServiceContext<IOClients, RecorderState, GraphQLContext>;
|
|
25
|
+
export declare type GraphQLServiceContext = ServiceContext<IOClients, RecorderState, GraphQLContext>;
|
|
26
26
|
export interface ExecutableSchema {
|
|
27
27
|
schema: GraphQLSchema;
|
|
28
28
|
hasProvider: boolean;
|
|
@@ -13,7 +13,7 @@ const isPublicEndpoint = ({ request: { headers } }) => {
|
|
|
13
13
|
}
|
|
14
14
|
return domain_1.PUBLIC_DOMAINS.some(endpoint => publicRegExp(endpoint).test(host));
|
|
15
15
|
};
|
|
16
|
-
|
|
16
|
+
exports.cacheControlHTTP = (ctx) => {
|
|
17
17
|
const { graphql: { cacheControl: { maxAge, scope: scopeHint, noCache: noCacheHint, noStore: noStoreHint, }, }, vtex: { production, }, } = ctx;
|
|
18
18
|
const finalHeader = [];
|
|
19
19
|
const noCache = noCacheHint || !production || isPublicEndpoint(ctx);
|
|
@@ -31,4 +31,3 @@ const cacheControlHTTP = (ctx) => {
|
|
|
31
31
|
}
|
|
32
32
|
return finalHeader.join(',');
|
|
33
33
|
};
|
|
34
|
-
exports.cacheControlHTTP = cacheControlHTTP;
|
|
@@ -16,7 +16,7 @@ const trimVariables = (variables) => {
|
|
|
16
16
|
};
|
|
17
17
|
const detailsFromCtx = (ctx) => {
|
|
18
18
|
const { headers: { 'x-forwarded-host': forwardedHost, 'x-forwarded-proto': forwardedProto, 'x-vtex-platform': platform, }, vtex: { operationId, requestId, }, } = ctx;
|
|
19
|
-
const queryRest =
|
|
19
|
+
const queryRest = ramda_1.pick(QUERY_FIELDS, ctx.graphql.query || {});
|
|
20
20
|
const variables = ctx.request.is('multipart/form-data')
|
|
21
21
|
? '[GraphQL Upload]'
|
|
22
22
|
: trimVariables(queryRest.variables);
|
|
@@ -34,14 +34,14 @@ const detailsFromCtx = (ctx) => {
|
|
|
34
34
|
};
|
|
35
35
|
};
|
|
36
36
|
const formatError = (error, details) => {
|
|
37
|
-
const formattedError =
|
|
37
|
+
const formattedError = ramda_1.pick(ERROR_FIELD_WHITELIST, error);
|
|
38
38
|
if (!formattedError.extensions) {
|
|
39
39
|
formattedError.extensions = {
|
|
40
40
|
code: 'INTERNAL_SERVER_ERROR',
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
43
|
if (formattedError.originalError) {
|
|
44
|
-
formattedError.originalError =
|
|
44
|
+
formattedError.originalError = error_1.cleanError(formattedError.originalError);
|
|
45
45
|
if (formattedError.stack === formattedError.originalError.stack) {
|
|
46
46
|
delete formattedError.originalError.stack;
|
|
47
47
|
}
|
|
@@ -49,8 +49,8 @@ const formatError = (error, details) => {
|
|
|
49
49
|
formattedError.extensions.exception = {
|
|
50
50
|
message: formattedError.originalError.message,
|
|
51
51
|
name: formattedError.originalError.name,
|
|
52
|
-
...
|
|
53
|
-
sensitive:
|
|
52
|
+
...ramda_1.omit(error_1.SENSITIVE_EXCEPTION_FIELDS, formattedError.originalError),
|
|
53
|
+
sensitive: ramda_1.pick(error_1.SENSITIVE_EXCEPTION_FIELDS, formattedError.originalError),
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
56
|
else {
|
|
@@ -60,10 +60,10 @@ const formatError = (error, details) => {
|
|
|
60
60
|
const extendedException = {
|
|
61
61
|
message: formattedError.originalError.message,
|
|
62
62
|
name: formattedError.originalError.name,
|
|
63
|
-
...
|
|
64
|
-
sensitive:
|
|
63
|
+
...ramda_1.omit(error_1.SENSITIVE_EXCEPTION_FIELDS, mergedException),
|
|
64
|
+
sensitive: ramda_1.pick(error_1.SENSITIVE_EXCEPTION_FIELDS, mergedException),
|
|
65
65
|
};
|
|
66
|
-
formattedError.extensions.exception =
|
|
66
|
+
formattedError.extensions.exception = error_1.cleanError(extendedException);
|
|
67
67
|
}
|
|
68
68
|
// Make originalError not enumerable to prevent duplicated log and response information
|
|
69
69
|
Object.defineProperty(formattedError, 'originalError', { enumerable: false });
|
|
@@ -71,8 +71,7 @@ const formatError = (error, details) => {
|
|
|
71
71
|
Object.assign(formattedError, details);
|
|
72
72
|
return formattedError;
|
|
73
73
|
};
|
|
74
|
-
|
|
74
|
+
exports.createFormatError = (ctx) => {
|
|
75
75
|
const details = detailsFromCtx(ctx);
|
|
76
76
|
return (error) => formatError(error, details);
|
|
77
77
|
};
|
|
78
|
-
exports.createFormatError = createFormatError;
|
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generatePathName = void 0;
|
|
4
4
|
const ramda_1 = require("ramda");
|
|
5
|
-
|
|
6
|
-
const pathFieldNames =
|
|
5
|
+
exports.generatePathName = (rpath) => {
|
|
6
|
+
const pathFieldNames = ramda_1.filter(value => typeof value === 'string', rpath);
|
|
7
7
|
return pathFieldNames.join('.');
|
|
8
8
|
};
|
|
9
|
-
exports.generatePathName = generatePathName;
|
|
@@ -8,7 +8,7 @@ export interface TranslatableMessageV2 {
|
|
|
8
8
|
content: string;
|
|
9
9
|
context?: string;
|
|
10
10
|
}
|
|
11
|
-
export type TranslationDirectiveType = 'translatableV2' | 'translateTo';
|
|
11
|
+
export declare type TranslationDirectiveType = 'translatableV2' | 'translateTo';
|
|
12
12
|
export declare const parseTranslatableStringV2: (rawMessage: string) => TranslatableMessageV2;
|
|
13
13
|
export declare const formatTranslatableStringV2: ({ from, content, context }: TranslatableMessageV2) => string;
|
|
14
14
|
export declare const handleSingleString: (ctx: IOContext, loader: import("dataloader")<import("../../../../../clients").Message, string>, behavior: Behavior, directiveName: TranslationDirectiveType) => (rawMessage: string | null) => Promise<string | null>;
|
|
@@ -4,7 +4,7 @@ exports.handleSingleString = exports.formatTranslatableStringV2 = exports.parseT
|
|
|
4
4
|
exports.CONTEXT_REGEX = /\(\(\((?<context>(.)*)\)\)\)/;
|
|
5
5
|
exports.FROM_REGEX = /\<\<\<(?<from>(.)*)\>\>\>/;
|
|
6
6
|
exports.CONTENT_REGEX = /\(\(\((?<context>(.)*)\)\)\)|\<\<\<(?<from>(.)*)\>\>\>/g;
|
|
7
|
-
|
|
7
|
+
exports.parseTranslatableStringV2 = (rawMessage) => {
|
|
8
8
|
var _a, _b, _c, _d;
|
|
9
9
|
const context = (_b = (_a = rawMessage.match(exports.CONTEXT_REGEX)) === null || _a === void 0 ? void 0 : _a.groups) === null || _b === void 0 ? void 0 : _b.context;
|
|
10
10
|
const from = (_d = (_c = rawMessage.match(exports.FROM_REGEX)) === null || _c === void 0 ? void 0 : _c.groups) === null || _d === void 0 ? void 0 : _d.from;
|
|
@@ -15,15 +15,13 @@ const parseTranslatableStringV2 = (rawMessage) => {
|
|
|
15
15
|
from: from === null || from === void 0 ? void 0 : from.trim(),
|
|
16
16
|
};
|
|
17
17
|
};
|
|
18
|
-
exports.
|
|
19
|
-
|
|
20
|
-
exports.formatTranslatableStringV2 = formatTranslatableStringV2;
|
|
21
|
-
const handleSingleString = (ctx, loader, behavior, directiveName) => async (rawMessage) => {
|
|
18
|
+
exports.formatTranslatableStringV2 = ({ from, content, context }) => `${content} ${context ? `(((${context})))` : ''} ${from ? `<<<${from}>>>` : ''}`;
|
|
19
|
+
exports.handleSingleString = (ctx, loader, behavior, directiveName) => async (rawMessage) => {
|
|
22
20
|
// Messages only know how to process non empty strings.
|
|
23
21
|
if (rawMessage == null) {
|
|
24
22
|
return rawMessage;
|
|
25
23
|
}
|
|
26
|
-
const { content, context, from: maybeFrom } =
|
|
24
|
+
const { content, context, from: maybeFrom } = exports.parseTranslatableStringV2(rawMessage);
|
|
27
25
|
const { binding, tenant } = ctx;
|
|
28
26
|
if (content == null) {
|
|
29
27
|
throw new Error(`@${directiveName} directive needs a content to translate, but received ${JSON.stringify(rawMessage)}`);
|
|
@@ -39,4 +37,3 @@ const handleSingleString = (ctx, loader, behavior, directiveName) => async (rawM
|
|
|
39
37
|
from,
|
|
40
38
|
});
|
|
41
39
|
};
|
|
42
|
-
exports.handleSingleString = handleSingleString;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import TokenBucket from 'tokenbucket';
|
|
2
2
|
import { IOClients } from '../../../../clients/IOClients';
|
|
3
3
|
import { ClientsConfig, ParamsContext, RecorderState, RouteHandler, ServiceRoute } from '../typings';
|
|
4
|
-
export declare const createPrivateHttpRoute: <T extends IOClients, U extends RecorderState, V extends ParamsContext>(clientsConfig: ClientsConfig<T>, serviceHandler:
|
|
5
|
-
export declare const createPublicHttpRoute: <T extends IOClients, U extends RecorderState, V extends ParamsContext>(clientsConfig: ClientsConfig<T>, serviceHandler:
|
|
4
|
+
export declare const createPrivateHttpRoute: <T extends IOClients, U extends RecorderState, V extends ParamsContext>(clientsConfig: ClientsConfig<T>, serviceHandler: import("koa-compose").Middleware<import("../typings").ServiceContext<T, U, V>> | import("koa-compose").Middleware<import("../typings").ServiceContext<T, U, V>>[], serviceRoute: ServiceRoute, routeId: string, globalLimiter: TokenBucket | undefined) => import("koa-compose").ComposedMiddleware<import("../typings").ServiceContext<T, U, V>>;
|
|
5
|
+
export declare const createPublicHttpRoute: <T extends IOClients, U extends RecorderState, V extends ParamsContext>(clientsConfig: ClientsConfig<T>, serviceHandler: import("koa-compose").Middleware<import("../typings").ServiceContext<T, U, V>> | import("koa-compose").Middleware<import("../typings").ServiceContext<T, U, V>>[], serviceRoute: ServiceRoute, routeId: string, globalLimiter: TokenBucket | undefined) => import("koa-compose").ComposedMiddleware<import("../typings").ServiceContext<T, U, V>>;
|
|
@@ -14,48 +14,46 @@ const setCookie_1 = require("./middlewares/setCookie");
|
|
|
14
14
|
const settings_1 = require("./middlewares/settings");
|
|
15
15
|
const timings_1 = require("./middlewares/timings");
|
|
16
16
|
const vary_1 = require("./middlewares/vary");
|
|
17
|
-
|
|
17
|
+
exports.createPrivateHttpRoute = (clientsConfig, serviceHandler, serviceRoute, routeId, globalLimiter) => {
|
|
18
18
|
var _a, _b;
|
|
19
19
|
const { implementation, options } = clientsConfig;
|
|
20
|
-
const middlewares =
|
|
20
|
+
const middlewares = toArray_1.toArray(serviceHandler);
|
|
21
21
|
const pipeline = [
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
tracingMiddlewares_1.nameSpanOperationMiddleware('private-handler', routeId),
|
|
23
|
+
context_1.createPvtContextMiddleware(routeId, serviceRoute),
|
|
24
24
|
cancellationToken_1.cancellationToken,
|
|
25
25
|
requestStats_1.trackIncomingRequestStats,
|
|
26
26
|
vary_1.vary,
|
|
27
27
|
authTokens_1.authTokens,
|
|
28
|
-
|
|
29
|
-
...(serviceRoute.settingsType === 'workspace' || serviceRoute.settingsType === 'userAndWorkspace' ? [
|
|
28
|
+
clients_1.clients(implementation, options),
|
|
29
|
+
...(serviceRoute.settingsType === 'workspace' || serviceRoute.settingsType === 'userAndWorkspace' ? [settings_1.getServiceSettings()] : []),
|
|
30
30
|
timings_1.timings,
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
rateLimit_1.concurrentRateLimiter((_a = serviceRoute === null || serviceRoute === void 0 ? void 0 : serviceRoute.rateLimitPerReplica) === null || _a === void 0 ? void 0 : _a.concurrent),
|
|
32
|
+
rateLimit_1.perMinuteRateLimiter((_b = serviceRoute === null || serviceRoute === void 0 ? void 0 : serviceRoute.rateLimitPerReplica) === null || _b === void 0 ? void 0 : _b.perMinute, globalLimiter),
|
|
33
|
+
tracingMiddlewares_1.traceUserLandRemainingPipelineMiddleware(),
|
|
34
34
|
...middlewares,
|
|
35
35
|
];
|
|
36
|
-
return
|
|
36
|
+
return compose_1.compose(pipeline);
|
|
37
37
|
};
|
|
38
|
-
exports.
|
|
39
|
-
const createPublicHttpRoute = (clientsConfig, serviceHandler, serviceRoute, routeId, globalLimiter) => {
|
|
38
|
+
exports.createPublicHttpRoute = (clientsConfig, serviceHandler, serviceRoute, routeId, globalLimiter) => {
|
|
40
39
|
var _a, _b;
|
|
41
40
|
const { implementation, options } = clientsConfig;
|
|
42
|
-
const middlewares =
|
|
41
|
+
const middlewares = toArray_1.toArray(serviceHandler);
|
|
43
42
|
const pipeline = [
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
tracingMiddlewares_1.nameSpanOperationMiddleware('public-handler', routeId),
|
|
44
|
+
context_1.createPubContextMiddleware(routeId, serviceRoute),
|
|
46
45
|
cancellationToken_1.cancellationToken,
|
|
47
46
|
requestStats_1.trackIncomingRequestStats,
|
|
48
47
|
vary_1.vary,
|
|
49
48
|
authTokens_1.authTokens,
|
|
50
|
-
|
|
51
|
-
...(serviceRoute.settingsType === 'workspace' || serviceRoute.settingsType === 'userAndWorkspace' ? [
|
|
49
|
+
clients_1.clients(implementation, options),
|
|
50
|
+
...(serviceRoute.settingsType === 'workspace' || serviceRoute.settingsType === 'userAndWorkspace' ? [settings_1.getServiceSettings()] : []),
|
|
52
51
|
setCookie_1.removeSetCookie,
|
|
53
52
|
timings_1.timings,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
rateLimit_1.concurrentRateLimiter((_a = serviceRoute === null || serviceRoute === void 0 ? void 0 : serviceRoute.rateLimitPerReplica) === null || _a === void 0 ? void 0 : _a.concurrent),
|
|
54
|
+
rateLimit_1.perMinuteRateLimiter((_b = serviceRoute === null || serviceRoute === void 0 ? void 0 : serviceRoute.rateLimitPerReplica) === null || _b === void 0 ? void 0 : _b.perMinute, globalLimiter),
|
|
55
|
+
tracingMiddlewares_1.traceUserLandRemainingPipelineMiddleware(),
|
|
57
56
|
...middlewares,
|
|
58
57
|
];
|
|
59
|
-
return
|
|
58
|
+
return compose_1.compose(pipeline);
|
|
60
59
|
};
|
|
61
|
-
exports.createPublicHttpRoute = createPublicHttpRoute;
|
|
@@ -4,11 +4,11 @@ exports.createPubContextMiddleware = exports.createPvtContextMiddleware = void 0
|
|
|
4
4
|
const querystring_1 = require("querystring");
|
|
5
5
|
const constants_1 = require("../../../../../constants");
|
|
6
6
|
const context_1 = require("../../utils/context");
|
|
7
|
-
|
|
7
|
+
exports.createPvtContextMiddleware = (routeId, { smartcache }) => {
|
|
8
8
|
return async function pvtContext(ctx, next) {
|
|
9
9
|
const { params, request: { header }, } = ctx;
|
|
10
10
|
ctx.vtex = {
|
|
11
|
-
...
|
|
11
|
+
...context_1.prepareHandlerCtx(header, ctx.tracing),
|
|
12
12
|
...(smartcache && { recorder: ctx.state.recorder }),
|
|
13
13
|
route: {
|
|
14
14
|
id: routeId,
|
|
@@ -19,21 +19,19 @@ const createPvtContextMiddleware = (routeId, { smartcache }) => {
|
|
|
19
19
|
await next();
|
|
20
20
|
};
|
|
21
21
|
};
|
|
22
|
-
exports.
|
|
23
|
-
const createPubContextMiddleware = (routeId, { smartcache }) => {
|
|
22
|
+
exports.createPubContextMiddleware = (routeId, { smartcache }) => {
|
|
24
23
|
return async function pubContext(ctx, next) {
|
|
25
24
|
const { request: { header }, } = ctx;
|
|
26
25
|
ctx.vtex = {
|
|
27
|
-
...
|
|
26
|
+
...context_1.prepareHandlerCtx(header, ctx.tracing),
|
|
28
27
|
...(smartcache && { recorder: ctx.state.recorder }),
|
|
29
28
|
route: {
|
|
30
29
|
declarer: header[constants_1.COLOSSUS_ROUTE_DECLARER_HEADER],
|
|
31
30
|
id: routeId,
|
|
32
|
-
params:
|
|
31
|
+
params: querystring_1.parse(header[constants_1.COLOSSUS_PARAMS_HEADER]),
|
|
33
32
|
type: 'public',
|
|
34
33
|
},
|
|
35
34
|
};
|
|
36
35
|
await next();
|
|
37
36
|
};
|
|
38
37
|
};
|
|
39
|
-
exports.createPubContextMiddleware = createPubContextMiddleware;
|