@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
|
@@ -61,7 +61,7 @@ async function error(ctx, next) {
|
|
|
61
61
|
return;
|
|
62
62
|
}
|
|
63
63
|
console.error('[node-vtex-api error]', e);
|
|
64
|
-
const err =
|
|
64
|
+
const err = error_1.cleanError(e);
|
|
65
65
|
// Add response
|
|
66
66
|
if (e instanceof axios_1.AxiosError) {
|
|
67
67
|
ctx.status = (e === null || e === void 0 ? void 0 : e.status) && e.status >= 400 && e.status <= 599
|
|
@@ -12,7 +12,7 @@ function perMinuteRateLimiter(rateLimit, globalLimiter) {
|
|
|
12
12
|
if (!rateLimit && !globalLimiter) {
|
|
13
13
|
return noopMiddleware;
|
|
14
14
|
}
|
|
15
|
-
const tokenBucket =
|
|
15
|
+
const tokenBucket = tokenBucket_1.createTokenBucket(rateLimit, globalLimiter);
|
|
16
16
|
return function perMinuteRateMiddleware(ctx, next) {
|
|
17
17
|
if (!tokenBucket.removeTokensSync(1)) {
|
|
18
18
|
throw new errors_1.TooManyRequestsError(responseMessagePerMinute);
|
|
@@ -9,26 +9,26 @@ Cookies dropped:
|
|
|
9
9
|
|
|
10
10
|
${keys.join('\n\t')}
|
|
11
11
|
`;
|
|
12
|
-
const findStr = (target, set) =>
|
|
12
|
+
const findStr = (target, set) => ramda_1.find((a) => a.toLocaleLowerCase() === target, set);
|
|
13
13
|
const findScopeInCacheControl = (cacheControl) => {
|
|
14
14
|
const splitted = cacheControl && cacheControl.split(/\s*,\s*/g);
|
|
15
15
|
const scopePublic = splitted && findStr('public', splitted);
|
|
16
16
|
return scopePublic;
|
|
17
17
|
};
|
|
18
|
-
const cookieKey = (cookie) =>
|
|
19
|
-
const indexCookieByKeys = (setCookie) =>
|
|
18
|
+
const cookieKey = (cookie) => ramda_1.compose(ramda_1.head, ramda_1.split('='))(cookie);
|
|
19
|
+
const indexCookieByKeys = (setCookie) => ramda_1.map((cookie) => [cookieKey(cookie), cookie], setCookie);
|
|
20
20
|
async function removeSetCookie(ctx, next) {
|
|
21
21
|
const { vtex: { logger } } = ctx;
|
|
22
22
|
await next();
|
|
23
23
|
const setCookie = ctx.response.headers['set-cookie'];
|
|
24
|
-
if (!setCookie ||
|
|
24
|
+
if (!setCookie || ramda_1.isEmpty(setCookie)) {
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
27
27
|
const cacheControl = ctx.response.headers['cache-control'];
|
|
28
28
|
const scope = findScopeInCacheControl(cacheControl);
|
|
29
29
|
if (scope === 'public') {
|
|
30
30
|
const indexedCookies = indexCookieByKeys(setCookie);
|
|
31
|
-
const cookies =
|
|
31
|
+
const cookies = ramda_1.reduce((acc, [key, payload]) => {
|
|
32
32
|
if (BLACKLISTED_COOKIES.has(key)) {
|
|
33
33
|
acc.droppedKeys.push(key);
|
|
34
34
|
}
|
|
@@ -5,5 +5,5 @@ import { Assets } from './../../../../../clients/infra/Assets';
|
|
|
5
5
|
import { ParamsContext, RecorderState, ServiceContext } from './../../typings';
|
|
6
6
|
export declare const getFilteredDependencies: (appAtMajor: string, dependencies: AppMetaInfo[]) => AppMetaInfo[];
|
|
7
7
|
export declare const getDependenciesHash: (dependencies: AppMetaInfo[]) => string;
|
|
8
|
-
export declare const getDependenciesSettings: (apps: Apps, assets: Assets, tracingConfig?: RequestTracingConfig) => Promise<Record<string, any>[]>;
|
|
8
|
+
export declare const getDependenciesSettings: (apps: Apps, assets: Assets, tracingConfig?: RequestTracingConfig | undefined) => Promise<Record<string, any>[]>;
|
|
9
9
|
export declare const getServiceSettings: () => <T extends IOClients, U extends RecorderState, V extends ParamsContext>(ctx: ServiceContext<T, U, V>, next: () => Promise<void>) => Promise<void>;
|
|
@@ -5,7 +5,7 @@ const crypto_1 = require("crypto");
|
|
|
5
5
|
const ramda_1 = require("ramda");
|
|
6
6
|
const constants_1 = require("../../../../../constants");
|
|
7
7
|
const app_1 = require("./../../../../../utils/app");
|
|
8
|
-
const joinIds =
|
|
8
|
+
const joinIds = ramda_1.join('');
|
|
9
9
|
const dependsOnApp = (appAtMajor) => (a) => {
|
|
10
10
|
const [name, major] = appAtMajor.split('@');
|
|
11
11
|
const majorInt = major.includes('.') ? major.split('.')[0] : major;
|
|
@@ -16,34 +16,30 @@ const dependsOnApp = (appAtMajor) => (a) => {
|
|
|
16
16
|
const [depMajor] = version.split('.');
|
|
17
17
|
return majorInt === depMajor;
|
|
18
18
|
};
|
|
19
|
-
|
|
19
|
+
exports.getFilteredDependencies = (appAtMajor, dependencies) => {
|
|
20
20
|
const depends = dependsOnApp(appAtMajor);
|
|
21
21
|
return dependencies.filter(depends);
|
|
22
22
|
};
|
|
23
|
-
exports.
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
return (0, crypto_1.createHash)('md5')
|
|
23
|
+
exports.getDependenciesHash = (dependencies) => {
|
|
24
|
+
const dependingApps = ramda_1.pluck('id', dependencies);
|
|
25
|
+
return crypto_1.createHash('md5')
|
|
27
26
|
.update(joinIds(dependingApps))
|
|
28
27
|
.digest('hex');
|
|
29
28
|
};
|
|
30
|
-
exports.
|
|
31
|
-
const getDependenciesSettings = async (apps, assets, tracingConfig) => {
|
|
29
|
+
exports.getDependenciesSettings = async (apps, assets, tracingConfig) => {
|
|
32
30
|
const appId = constants_1.APP.ID;
|
|
33
31
|
const metaInfos = await apps.getAppsMetaInfos(undefined, undefined, tracingConfig);
|
|
34
|
-
const appAtMajor =
|
|
32
|
+
const appAtMajor = app_1.appIdToAppAtMajor(appId);
|
|
35
33
|
return await assets.getSettings(metaInfos, appAtMajor, undefined, tracingConfig);
|
|
36
34
|
};
|
|
37
|
-
exports.
|
|
38
|
-
const getServiceSettings = () => {
|
|
35
|
+
exports.getServiceSettings = () => {
|
|
39
36
|
return async function settingsContext(ctx, next) {
|
|
40
37
|
var _a;
|
|
41
38
|
const { clients: { apps, assets }, } = ctx;
|
|
42
39
|
const rootSpan = (_a = ctx.tracing) === null || _a === void 0 ? void 0 : _a.currentSpan;
|
|
43
|
-
const dependenciesSettings = await
|
|
40
|
+
const dependenciesSettings = await exports.getDependenciesSettings(apps, assets, { tracing: { rootSpan } });
|
|
44
41
|
// TODO: for now returning all settings, but the ideia is to do merge
|
|
45
42
|
ctx.vtex.settings = dependenciesSettings;
|
|
46
43
|
await next();
|
|
47
44
|
};
|
|
48
45
|
};
|
|
49
|
-
exports.getServiceSettings = getServiceSettings;
|
|
@@ -8,7 +8,7 @@ const chalk_1 = __importDefault(require("chalk"));
|
|
|
8
8
|
const constants_1 = require("../../../../../constants");
|
|
9
9
|
const status_1 = require("../../../../../utils/status");
|
|
10
10
|
const time_1 = require("../../../../../utils/time");
|
|
11
|
-
const APP_ELAPSED_TIME_LOCATOR =
|
|
11
|
+
const APP_ELAPSED_TIME_LOCATOR = time_1.shrinkTimings(time_1.formatTimingName({
|
|
12
12
|
hopNumber: 0,
|
|
13
13
|
source: process.env.VTEX_APP_NAME,
|
|
14
14
|
target: '',
|
|
@@ -36,10 +36,10 @@ async function timings(ctx, next) {
|
|
|
36
36
|
// Errors will be caught by the next middleware so we don't have to catch.
|
|
37
37
|
await next();
|
|
38
38
|
const { status: statusCode, vtex: { route: { id } }, timings: { total }, vtex } = ctx;
|
|
39
|
-
const totalMillis =
|
|
39
|
+
const totalMillis = time_1.hrToMillis(total);
|
|
40
40
|
console.log(log(ctx, totalMillis));
|
|
41
41
|
console.log(logBillingInfo(vtex, totalMillis));
|
|
42
|
-
const status =
|
|
42
|
+
const status = status_1.statusLabel(statusCode);
|
|
43
43
|
// Only batch successful responses so metrics don't consider errors
|
|
44
44
|
metrics.batch(`http-handler-${id}`, status === 'success' ? total : undefined, { [status]: 1 });
|
|
45
45
|
}
|
|
@@ -4,7 +4,7 @@ exports.routerFromPublicHttpHandlers = void 0;
|
|
|
4
4
|
const constants_1 = require("../../../../constants");
|
|
5
5
|
const logger_1 = require("../../../logger");
|
|
6
6
|
const console_1 = require("./../../../logger/console");
|
|
7
|
-
|
|
7
|
+
exports.routerFromPublicHttpHandlers = (routes) => {
|
|
8
8
|
return async (ctx, next) => {
|
|
9
9
|
var _a;
|
|
10
10
|
const routeId = ctx.get(constants_1.COLOSSUS_ROUTE_ID_HEADER);
|
|
@@ -16,10 +16,9 @@ const routerFromPublicHttpHandlers = (routes) => {
|
|
|
16
16
|
const msg = `Handler with id '${routeId}' not implemented.`;
|
|
17
17
|
ctx.status = 501;
|
|
18
18
|
ctx.body = msg;
|
|
19
|
-
|
|
19
|
+
console_1.logOnceToDevConsole(msg, logger_1.LogLevel.Error);
|
|
20
20
|
return;
|
|
21
21
|
}
|
|
22
22
|
await handler(ctx, next);
|
|
23
23
|
};
|
|
24
24
|
};
|
|
25
|
-
exports.routerFromPublicHttpHandlers = routerFromPublicHttpHandlers;
|
|
@@ -2,15 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.logAvailableRoutes = exports.formatPublicRoute = exports.formatPrivateRoute = void 0;
|
|
4
4
|
const constants_1 = require("../../../../constants");
|
|
5
|
-
|
|
6
|
-
exports.
|
|
7
|
-
const formatPublicRoute = ({ workspace, account, endpoint, path }) => `https://${workspace}--${account}.${endpoint}${path}`;
|
|
8
|
-
exports.formatPublicRoute = formatPublicRoute;
|
|
5
|
+
exports.formatPrivateRoute = ({ protocol = 'https', vendor, name, major, account, workspace, path }) => `${protocol}://app.io.vtex.com/${vendor}.${name}/v${major}/${account}/${workspace}${path || ''}`;
|
|
6
|
+
exports.formatPublicRoute = ({ workspace, account, endpoint, path }) => `https://${workspace}--${account}.${endpoint}${path}`;
|
|
9
7
|
const getPath = ({ public: publicRoute, path }) => publicRoute
|
|
10
|
-
?
|
|
11
|
-
:
|
|
12
|
-
|
|
8
|
+
? exports.formatPublicRoute({ workspace: constants_1.WORKSPACE, account: constants_1.ACCOUNT, endpoint: constants_1.PUBLIC_ENDPOINT, path })
|
|
9
|
+
: exports.formatPrivateRoute({ protocol: 'https', vendor: constants_1.APP.VENDOR, name: constants_1.APP.NAME, major: constants_1.APP.MAJOR, account: constants_1.ACCOUNT, workspace: constants_1.WORKSPACE, path });
|
|
10
|
+
exports.logAvailableRoutes = (service) => {
|
|
13
11
|
const available = Object.values(service.routes || {}).reduce((acc, route) => `${acc}\n${getPath(route)}`, 'Available service routes:');
|
|
14
12
|
console.info(available);
|
|
15
13
|
};
|
|
16
|
-
exports.logAvailableRoutes = logAvailableRoutes;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IOClients } from '../../../clients/IOClients';
|
|
2
2
|
import { ParamsContext, RecorderState, RouteHandler, ServiceContext } from './typings';
|
|
3
|
-
type HTTPMethods = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'PATCH' | 'DEFAULT';
|
|
4
|
-
type MethodOptions<ClientsT extends IOClients = IOClients, StateT extends RecorderState = RecorderState, CustomT extends ParamsContext = ParamsContext> = Partial<Record<HTTPMethods, RouteHandler<ClientsT, StateT, CustomT> | Array<RouteHandler<ClientsT, StateT, CustomT>>>>;
|
|
3
|
+
declare type HTTPMethods = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'PATCH' | 'DEFAULT';
|
|
4
|
+
declare type MethodOptions<ClientsT extends IOClients = IOClients, StateT extends RecorderState = RecorderState, CustomT extends ParamsContext = ParamsContext> = Partial<Record<HTTPMethods, RouteHandler<ClientsT, StateT, CustomT> | Array<RouteHandler<ClientsT, StateT, CustomT>>>>;
|
|
5
5
|
export declare function method<T extends IOClients, U extends RecorderState, V extends ParamsContext>(options: MethodOptions<T, U, V>): {
|
|
6
6
|
(ctx: ServiceContext<T, U, V>, next: () => Promise<void>): Promise<void>;
|
|
7
7
|
skipTimer: boolean;
|
|
@@ -9,7 +9,7 @@ function methodNotAllowed(ctx) {
|
|
|
9
9
|
ctx.set('cache-control', `public, max-age=${TEN_SECONDS_S}`);
|
|
10
10
|
}
|
|
11
11
|
function method(options) {
|
|
12
|
-
const handlers =
|
|
12
|
+
const handlers = ramda_1.mapObjIndexed(handler => compose_1.compose(Array.isArray(handler) ? handler : [handler]), options);
|
|
13
13
|
const inner = async function forMethod(ctx, next) {
|
|
14
14
|
const verb = ctx.method.toUpperCase();
|
|
15
15
|
const handler = handlers[verb] || handlers.DEFAULT || methodNotAllowed;
|
|
@@ -8,11 +8,9 @@ const cluster_1 = __importDefault(require("cluster"));
|
|
|
8
8
|
const constants_1 = require("../../../constants");
|
|
9
9
|
const BROADCAST_STATUS_TRACK = 'broadcastStatusTrack';
|
|
10
10
|
const STATUS_TRACK = 'statusTrack';
|
|
11
|
-
|
|
12
|
-
exports.
|
|
13
|
-
|
|
14
|
-
exports.isStatusTrackBroadcast = isStatusTrackBroadcast;
|
|
15
|
-
const statusTrackHandler = async (ctx) => {
|
|
11
|
+
exports.isStatusTrack = (message) => message === STATUS_TRACK;
|
|
12
|
+
exports.isStatusTrackBroadcast = (message) => message === BROADCAST_STATUS_TRACK;
|
|
13
|
+
exports.statusTrackHandler = async (ctx) => {
|
|
16
14
|
var _a, _b, _c;
|
|
17
15
|
(_b = (_a = ctx.tracing) === null || _a === void 0 ? void 0 : _a.currentSpan) === null || _b === void 0 ? void 0 : _b.setOperationName('builtin:status-track');
|
|
18
16
|
if (!constants_1.LINKED) {
|
|
@@ -21,15 +19,12 @@ const statusTrackHandler = async (ctx) => {
|
|
|
21
19
|
ctx.body = [];
|
|
22
20
|
return;
|
|
23
21
|
};
|
|
24
|
-
exports.
|
|
25
|
-
const trackStatus = () => {
|
|
22
|
+
exports.trackStatus = () => {
|
|
26
23
|
global.metrics.statusTrack().forEach(status => {
|
|
27
24
|
logStatus(status);
|
|
28
25
|
});
|
|
29
26
|
};
|
|
30
|
-
exports.
|
|
31
|
-
const broadcastStatusTrack = () => Object.values(cluster_1.default.workers).forEach(worker => worker === null || worker === void 0 ? void 0 : worker.send(STATUS_TRACK));
|
|
32
|
-
exports.broadcastStatusTrack = broadcastStatusTrack;
|
|
27
|
+
exports.broadcastStatusTrack = () => Object.values(cluster_1.default.workers).forEach(worker => worker === null || worker === void 0 ? void 0 : worker.send(STATUS_TRACK));
|
|
33
28
|
const logStatus = (status) => console.log(JSON.stringify({
|
|
34
29
|
__VTEX_IO_LOG: true,
|
|
35
30
|
account: constants_1.ACCOUNT,
|
|
@@ -17,8 +17,8 @@ import { Logger } from '../../logger';
|
|
|
17
17
|
import { MetricsLogger } from '../../logger/metricsLogger';
|
|
18
18
|
import { MessagesLoaderV2 } from './graphql/schema/messagesLoaderV2';
|
|
19
19
|
import { Recorder } from './utils/recorder';
|
|
20
|
-
type ServerTiming = Record<string, string>;
|
|
21
|
-
export type Maybe<T> = T | null | undefined;
|
|
20
|
+
declare type ServerTiming = Record<string, string>;
|
|
21
|
+
export declare type Maybe<T> = T | null | undefined;
|
|
22
22
|
export interface TracingContext {
|
|
23
23
|
tracer: Tracer;
|
|
24
24
|
currentSpan: Span | undefined;
|
|
@@ -44,7 +44,7 @@ export interface EventContext<T extends IOClients, StateT = any> {
|
|
|
44
44
|
sender: string;
|
|
45
45
|
subject: string;
|
|
46
46
|
}
|
|
47
|
-
type KnownKeys<T> = {
|
|
47
|
+
declare type KnownKeys<T> = {
|
|
48
48
|
[K in keyof T]: string extends K ? never : number extends K ? never : K;
|
|
49
49
|
} extends {
|
|
50
50
|
[_ in keyof T]: infer U;
|
|
@@ -54,13 +54,13 @@ interface Loaders {
|
|
|
54
54
|
messagesV2?: MessagesLoaderV2;
|
|
55
55
|
immutableMessagesV2?: MessagesLoaderV2;
|
|
56
56
|
}
|
|
57
|
-
export type ServiceContext<ClientsT extends IOClients = IOClients, StateT extends RecorderState = RecorderState, CustomT extends ParamsContext = ParamsContext> = Pick<ParameterizedContext<StateT, Context<ClientsT>>, KnownKeys<ParameterizedContext<StateT, Context<ClientsT>>>> & CustomT & {
|
|
57
|
+
export declare type ServiceContext<ClientsT extends IOClients = IOClients, StateT extends RecorderState = RecorderState, CustomT extends ParamsContext = ParamsContext> = Pick<ParameterizedContext<StateT, Context<ClientsT>>, KnownKeys<ParameterizedContext<StateT, Context<ClientsT>>>> & CustomT & {
|
|
58
58
|
loaders?: Loaders;
|
|
59
59
|
};
|
|
60
|
-
export type RouteHandler<ClientsT extends IOClients = IOClients, StateT extends RecorderState = RecorderState, CustomT extends ParamsContext = ParamsContext> = Middleware<ServiceContext<ClientsT, StateT, CustomT>>;
|
|
61
|
-
export type EventHandler<ClientsT extends IOClients = IOClients, StateT = void> = Middleware<EventContext<ClientsT, StateT>>;
|
|
62
|
-
export type Resolver<ClientsT extends IOClients = IOClients, StateT extends RecorderState = RecorderState, CustomT extends ParamsContext = ParamsContext> = GraphQLFieldResolver<any, ServiceContext<ClientsT, StateT, CustomT>, any> | GraphQLFieldConfig<any, ServiceContext<ClientsT, StateT, CustomT>, any>;
|
|
63
|
-
export type Handler = RouteHandler<IOClients, RecorderState, ParamsContext>;
|
|
60
|
+
export declare type RouteHandler<ClientsT extends IOClients = IOClients, StateT extends RecorderState = RecorderState, CustomT extends ParamsContext = ParamsContext> = Middleware<ServiceContext<ClientsT, StateT, CustomT>>;
|
|
61
|
+
export declare type EventHandler<ClientsT extends IOClients = IOClients, StateT = void> = Middleware<EventContext<ClientsT, StateT>>;
|
|
62
|
+
export declare type Resolver<ClientsT extends IOClients = IOClients, StateT extends RecorderState = RecorderState, CustomT extends ParamsContext = ParamsContext> = GraphQLFieldResolver<any, ServiceContext<ClientsT, StateT, CustomT>, any> | GraphQLFieldConfig<any, ServiceContext<ClientsT, StateT, CustomT>, any>;
|
|
63
|
+
export declare type Handler = RouteHandler<IOClients, RecorderState, ParamsContext>;
|
|
64
64
|
export interface HttpRoute {
|
|
65
65
|
handler: RouteHandler;
|
|
66
66
|
path: string;
|
|
@@ -132,7 +132,7 @@ export interface EventBody {
|
|
|
132
132
|
subject: string;
|
|
133
133
|
key: string;
|
|
134
134
|
}
|
|
135
|
-
export type RouteSettingsType = 'pure' | 'workspace' | 'userAndWorkspace';
|
|
135
|
+
export declare type RouteSettingsType = 'pure' | 'workspace' | 'userAndWorkspace';
|
|
136
136
|
export interface ServiceRoute {
|
|
137
137
|
path: string;
|
|
138
138
|
public?: boolean;
|
|
@@ -169,5 +169,5 @@ export interface RawServiceJSON {
|
|
|
169
169
|
export interface ServiceJSON extends RawServiceJSON {
|
|
170
170
|
workers: number;
|
|
171
171
|
}
|
|
172
|
-
export type JanusEnv = string;
|
|
172
|
+
export declare type JanusEnv = string;
|
|
173
173
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import koaCompose from 'koa-compose';
|
|
2
2
|
import { IOClients } from '../../../../clients/IOClients';
|
|
3
3
|
import { EventHandler, ParamsContext, RecorderState, RouteHandler } from '../typings';
|
|
4
|
-
export declare const compose: <ClientsT extends IOClients, StateT extends RecorderState, CustomT extends ParamsContext>(middlewares:
|
|
5
|
-
export declare const composeForEvents: <ClientsT extends IOClients, StateT extends RecorderState>(middlewares:
|
|
4
|
+
export declare const compose: <ClientsT extends IOClients, StateT extends RecorderState, CustomT extends ParamsContext>(middlewares: koaCompose.Middleware<import("../typings").ServiceContext<ClientsT, StateT, CustomT>>[]) => koaCompose.ComposedMiddleware<import("../typings").ServiceContext<ClientsT, StateT, CustomT>>;
|
|
5
|
+
export declare const composeForEvents: <ClientsT extends IOClients, StateT extends RecorderState>(middlewares: koaCompose.Middleware<import("../typings").EventContext<ClientsT, StateT>>[]) => koaCompose.ComposedMiddleware<import("../typings").EventContext<ClientsT, StateT>>;
|
|
@@ -8,7 +8,5 @@ const koa_compose_1 = __importDefault(require("koa-compose"));
|
|
|
8
8
|
const ramda_1 = require("ramda");
|
|
9
9
|
const cancel_1 = require("../../../../utils/cancel");
|
|
10
10
|
const time_1 = require("../../../../utils/time");
|
|
11
|
-
|
|
12
|
-
exports.
|
|
13
|
-
const composeForEvents = (middlewares) => (0, koa_compose_1.default)(middlewares.map(time_1.timerForEvents));
|
|
14
|
-
exports.composeForEvents = composeForEvents;
|
|
11
|
+
exports.compose = (middlewares) => koa_compose_1.default(middlewares.map(ramda_1.pipe(time_1.timer, cancel_1.cancel)));
|
|
12
|
+
exports.composeForEvents = (middlewares) => koa_compose_1.default(middlewares.map(time_1.timerForEvents));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Context } from 'koa';
|
|
2
2
|
import { IOContext, TracingContext } from '../typings';
|
|
3
|
-
type HandlerContext = Omit<IOContext, 'route'>;
|
|
4
|
-
export declare const prepareHandlerCtx: (header: Context['request']['header'], tracingContext?: TracingContext) => HandlerContext;
|
|
3
|
+
declare type HandlerContext = Omit<IOContext, 'route'>;
|
|
4
|
+
export declare const prepareHandlerCtx: (header: Context['request']['header'], tracingContext?: TracingContext | undefined) => HandlerContext;
|
|
5
5
|
export {};
|
|
@@ -13,15 +13,15 @@ const binding_1 = require("./../../../../utils/binding");
|
|
|
13
13
|
const getPlatform = (account) => {
|
|
14
14
|
return account.startsWith('gc-') ? 'gocommerce' : 'vtex';
|
|
15
15
|
};
|
|
16
|
-
|
|
16
|
+
exports.prepareHandlerCtx = (header, tracingContext) => {
|
|
17
17
|
var _a;
|
|
18
18
|
const partialContext = {
|
|
19
19
|
account: header[constants_1.ACCOUNT_HEADER],
|
|
20
20
|
authToken: header[constants_1.CREDENTIAL_HEADER],
|
|
21
|
-
binding: header[constants_1.BINDING_HEADER] ?
|
|
21
|
+
binding: header[constants_1.BINDING_HEADER] ? binding_1.parseBindingHeaderValue(header[constants_1.BINDING_HEADER]) : undefined,
|
|
22
22
|
host: header[constants_1.FORWARDED_HOST_HEADER],
|
|
23
23
|
locale: header[constants_1.LOCALE_HEADER],
|
|
24
|
-
operationId: header[constants_1.OPERATION_ID_HEADER] ||
|
|
24
|
+
operationId: header[constants_1.OPERATION_ID_HEADER] || v4_1.default(),
|
|
25
25
|
platform: header[constants_1.PLATFORM_HEADER] || getPlatform(header[constants_1.ACCOUNT_HEADER]),
|
|
26
26
|
product: header[constants_1.PRODUCT_HEADER],
|
|
27
27
|
production: ((_a = header[constants_1.WORKSPACE_IS_PRODUCTION_HEADER]) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'true' || false,
|
|
@@ -29,7 +29,7 @@ const prepareHandlerCtx = (header, tracingContext) => {
|
|
|
29
29
|
requestId: header[constants_1.REQUEST_ID_HEADER],
|
|
30
30
|
segmentToken: header[constants_1.SEGMENT_HEADER],
|
|
31
31
|
sessionToken: header[constants_1.SESSION_HEADER],
|
|
32
|
-
tenant: header[constants_1.TENANT_HEADER] ?
|
|
32
|
+
tenant: header[constants_1.TENANT_HEADER] ? tenant_1.parseTenantHeaderValue(header[constants_1.TENANT_HEADER]) : 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
35
|
workspace: header[constants_1.WORKSPACE_HEADER],
|
|
@@ -39,4 +39,3 @@ const prepareHandlerCtx = (header, tracingContext) => {
|
|
|
39
39
|
logger: new logger_1.Logger(partialContext),
|
|
40
40
|
};
|
|
41
41
|
};
|
|
42
|
-
exports.prepareHandlerCtx = prepareHandlerCtx;
|
|
@@ -27,7 +27,7 @@ class Recorder {
|
|
|
27
27
|
const newValueSet = new Set(this._record[headerName]);
|
|
28
28
|
const currentValue = ctx.response.get(headerName);
|
|
29
29
|
const parsedCurrentValue = typeof currentValue === 'string' ? currentValue.split(',') : currentValue;
|
|
30
|
-
parsedCurrentValue.forEach(cur => newValueSet.add(
|
|
30
|
+
parsedCurrentValue.forEach(cur => newValueSet.add(ramda_1.trim(cur)));
|
|
31
31
|
const deduped = Array.from(newValueSet).filter(x => !!x);
|
|
32
32
|
if (deduped.length > 0) {
|
|
33
33
|
ctx.set(headerName, deduped);
|
|
@@ -4,7 +4,7 @@ exports.UserLandTracer = exports.createTracingContextFromCarrier = void 0;
|
|
|
4
4
|
const opentracing_1 = require("opentracing");
|
|
5
5
|
const TracerSingleton_1 = require("../service/tracing/TracerSingleton");
|
|
6
6
|
const utils_1 = require("./utils");
|
|
7
|
-
|
|
7
|
+
exports.createTracingContextFromCarrier = (newSpanName, carrier) => {
|
|
8
8
|
const tracer = TracerSingleton_1.TracerSingleton.getTracer();
|
|
9
9
|
const rootSpan = tracer.extract(opentracing_1.FORMAT_HTTP_HEADERS, carrier);
|
|
10
10
|
if (rootSpan == null) {
|
|
@@ -15,13 +15,12 @@ const createTracingContextFromCarrier = (newSpanName, carrier) => {
|
|
|
15
15
|
userlandTracer.lockFallbackSpan();
|
|
16
16
|
return { span, tracer: userlandTracer };
|
|
17
17
|
};
|
|
18
|
-
exports.createTracingContextFromCarrier = createTracingContextFromCarrier;
|
|
19
18
|
class UserLandTracer {
|
|
20
19
|
constructor(tracer, fallbackSpan) {
|
|
21
20
|
this.tracer = tracer;
|
|
22
21
|
this.fallbackSpan = fallbackSpan;
|
|
23
22
|
this.fallbackSpanLock = false;
|
|
24
|
-
const { traceId, isSampled } =
|
|
23
|
+
const { traceId, isSampled } = utils_1.getTraceInfo(fallbackSpan);
|
|
25
24
|
this._traceId = traceId;
|
|
26
25
|
this._isSampled = isSampled;
|
|
27
26
|
}
|
|
@@ -27,7 +27,7 @@ class ErrorReport extends node_error_report_1.ErrorReportBase {
|
|
|
27
27
|
if (args.originalError instanceof ErrorReport) {
|
|
28
28
|
return args.originalError;
|
|
29
29
|
}
|
|
30
|
-
return new ErrorReport(
|
|
30
|
+
return new ErrorReport(node_error_report_1.createErrorReportBaseArgs(args));
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
33
|
* Inject information about the error wrapped by this ErrorReport
|
|
@@ -38,24 +38,24 @@ class ErrorReport extends node_error_report_1.ErrorReportBase {
|
|
|
38
38
|
var _a, _b, _c, _d;
|
|
39
39
|
span === null || span === void 0 ? void 0 : span.setTag(__1.TracingTags.ERROR, 'true');
|
|
40
40
|
const indexedLogs = {
|
|
41
|
-
["error.kind" /*
|
|
42
|
-
["error.id" /*
|
|
41
|
+
["error.kind" /* ERROR_KIND */]: this.kind,
|
|
42
|
+
["error.id" /* ERROR_ID */]: this.metadata.errorId,
|
|
43
43
|
};
|
|
44
|
-
if (
|
|
44
|
+
if (node_error_report_1.isRequestInfo(this.parsedInfo) &&
|
|
45
45
|
this.parsedInfo.response &&
|
|
46
|
-
|
|
47
|
-
indexedLogs["error.server.code" /*
|
|
48
|
-
indexedLogs["error.server.request_id" /*
|
|
46
|
+
node_error_report_1.isInfraErrorData((_a = this.parsedInfo.response) === null || _a === void 0 ? void 0 : _a.data)) {
|
|
47
|
+
indexedLogs["error.server.code" /* ERROR_SERVER_CODE */] = this.parsedInfo.response.data.code;
|
|
48
|
+
indexedLogs["error.server.request_id" /* ERROR_SERVER_REQUEST_ID */] = this.parsedInfo.response.data.requestId;
|
|
49
49
|
}
|
|
50
50
|
const serializableError = this.toObject();
|
|
51
51
|
span === null || span === void 0 ? void 0 : span.log({
|
|
52
52
|
event: 'error',
|
|
53
53
|
...indexedLogs,
|
|
54
|
-
["error.message" /*
|
|
55
|
-
["error.metadata.metrics.InstantiationTime" /*
|
|
56
|
-
["error.metadata.reportCount" /*
|
|
57
|
-
["error.stack" /*
|
|
58
|
-
["error.code" /*
|
|
54
|
+
["error.message" /* ERROR_MESSAGE */]: serializableError.message,
|
|
55
|
+
["error.metadata.metrics.InstantiationTime" /* ERROR_METADATA_METRICS_INSTANTIATION_TIME */]: (_b = serializableError.metadata) === null || _b === void 0 ? void 0 : _b.reportCount,
|
|
56
|
+
["error.metadata.reportCount" /* ERROR_METADATA_REPORT_COUNT */]: (_d = (_c = serializableError.metadata) === null || _c === void 0 ? void 0 : _c.metrics) === null || _d === void 0 ? void 0 : _d.instantiationTime,
|
|
57
|
+
["error.stack" /* ERROR_STACK */]: serializableError.stack,
|
|
58
|
+
["error.code" /* ERROR_CODE */]: serializableError.code,
|
|
59
59
|
});
|
|
60
60
|
if (logger && this.shouldLogToSplunk(span)) {
|
|
61
61
|
logger.error(serializableError);
|
|
@@ -65,7 +65,7 @@ class ErrorReport extends node_error_report_1.ErrorReportBase {
|
|
|
65
65
|
}
|
|
66
66
|
shouldLogToSplunk(span) {
|
|
67
67
|
var _a;
|
|
68
|
-
return !this.isErrorReported() && ((_a =
|
|
68
|
+
return !this.isErrorReported() && ((_a = utils_1.getTraceInfo(span)) === null || _a === void 0 ? void 0 : _a.isSampled);
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
exports.ErrorReport = ErrorReport;
|
package/lib/tracing/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FORMAT_HTTP_HEADERS = exports.Span =
|
|
3
|
+
exports.FORMAT_HTTP_HEADERS = exports.Span = void 0;
|
|
4
4
|
const opentracing_1 = require("opentracing");
|
|
5
5
|
Object.defineProperty(exports, "FORMAT_HTTP_HEADERS", { enumerable: true, get: function () { return opentracing_1.FORMAT_HTTP_HEADERS; } });
|
|
6
6
|
Object.defineProperty(exports, "Span", { enumerable: true, get: function () { return opentracing_1.Span; } });
|
package/lib/tracing/utils.js
CHANGED
|
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.cloneAndSanitizeHeaders = exports.getTraceInfo = void 0;
|
|
4
4
|
const node_error_report_1 = require("@vtex/node-error-report");
|
|
5
5
|
function getTraceInfo(span) {
|
|
6
|
-
var _a, _b;
|
|
6
|
+
var _a, _b, _c;
|
|
7
7
|
const spanContext = span === null || span === void 0 ? void 0 : span.context();
|
|
8
8
|
return {
|
|
9
|
-
isSampled: (_b = (_a = spanContext === null ||
|
|
9
|
+
isSampled: (_c = (_b = (_a = spanContext) === null || _a === void 0 ? void 0 : _a.isSampled) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : false,
|
|
10
10
|
traceId: spanContext === null || spanContext === void 0 ? void 0 : spanContext.toTraceId(),
|
|
11
11
|
};
|
|
12
12
|
}
|
|
@@ -17,7 +17,7 @@ exports.getTraceInfo = getTraceInfo;
|
|
|
17
17
|
* @param headersObj The headers object
|
|
18
18
|
* @param resultFieldsPrefix The prefix that will be added to each field on the result object
|
|
19
19
|
*/
|
|
20
|
-
|
|
20
|
+
exports.cloneAndSanitizeHeaders = (headersObj, resultFieldsPrefix = '') => {
|
|
21
21
|
const ret = {};
|
|
22
22
|
const entries = Object.entries(headersObj);
|
|
23
23
|
for (const [key, val] of entries) {
|
|
@@ -35,8 +35,7 @@ const cloneAndSanitizeHeaders = (headersObj, resultFieldsPrefix = '') => {
|
|
|
35
35
|
// },
|
|
36
36
|
// ```
|
|
37
37
|
// In those corner cases we probably won't have a sensitive string as key, so we don't treat them here
|
|
38
|
-
ret[`${resultFieldsPrefix}${key}`] = node_error_report_1.authFields.includes(key) ?
|
|
38
|
+
ret[`${resultFieldsPrefix}${key}`] = node_error_report_1.authFields.includes(key) ? node_error_report_1.sanitizeAuth(val) : val;
|
|
39
39
|
}
|
|
40
40
|
return ret;
|
|
41
41
|
};
|
|
42
|
-
exports.cloneAndSanitizeHeaders = cloneAndSanitizeHeaders;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Logger } from './../service/logger/logger';
|
|
2
2
|
import { ConflictsResolver, VBase } from '../clients/infra/VBase';
|
|
3
|
-
type Configuration = Record<string, ConfigurationData | ConfigurationData[] | object> | ConfigurationData[];
|
|
4
|
-
type ConfigurationData = Record<string, object>;
|
|
3
|
+
declare type Configuration = Record<string, ConfigurationData | ConfigurationData[] | object> | ConfigurationData[];
|
|
4
|
+
declare type ConfigurationData = Record<string, object>;
|
|
5
5
|
export declare class MineWinsConflictsResolver<T> implements ConflictsResolver<T> {
|
|
6
6
|
/***
|
|
7
7
|
* Take mine and merge with master keys that have no conflict
|
|
@@ -13,8 +13,8 @@ export declare class MineWinsConflictsResolver<T> implements ConflictsResolver<T
|
|
|
13
13
|
private comparableKeys;
|
|
14
14
|
constructor(client: VBase, bucket: string, filePath: string, comparableKeys?: string[]);
|
|
15
15
|
resolve(logger?: Logger): Promise<any>;
|
|
16
|
-
resolveAll(): Promise<
|
|
17
|
-
protected mergeMineWins(base: Configuration, master: Configuration, mine: Configuration):
|
|
16
|
+
resolveAll(): Promise<(Record<string, object | Record<string, object> | Record<string, object>[]> | Record<string, object>[])[]>;
|
|
17
|
+
protected mergeMineWins(base: Configuration, master: Configuration, mine: Configuration): Record<string, object | Record<string, object> | Record<string, object>[]> | Record<string, object>[];
|
|
18
18
|
private parseConflict;
|
|
19
19
|
private serializeContentByMimetype;
|
|
20
20
|
private parseContentByMimetype;
|
|
@@ -40,10 +40,10 @@ class MineWinsConflictsResolver {
|
|
|
40
40
|
return resolvedConflicts;
|
|
41
41
|
}
|
|
42
42
|
mergeMineWins(base, master, mine) {
|
|
43
|
-
if (
|
|
43
|
+
if (util_1.isArray(master)) {
|
|
44
44
|
return this.mergeMineWinsArray((base || []), master, (mine || []));
|
|
45
45
|
}
|
|
46
|
-
else if (
|
|
46
|
+
else if (util_1.isObject(master)) {
|
|
47
47
|
return this.mergeMineWinsObject((base || {}), master, (mine || {}));
|
|
48
48
|
}
|
|
49
49
|
return mine ? mine : master;
|
|
@@ -85,16 +85,16 @@ class MineWinsConflictsResolver {
|
|
|
85
85
|
mergeMineWinsObject(base, master, mine) {
|
|
86
86
|
const merged = { ...master, ...mine };
|
|
87
87
|
Object.entries(merged).forEach(([key, value]) => {
|
|
88
|
-
if (master[key] == null && base && base[key] != null &&
|
|
88
|
+
if (master[key] == null && base && base[key] != null && ramda_1.equals(value, base[key])) {
|
|
89
89
|
delete merged[key]; // value deleted from master with no conflict
|
|
90
90
|
}
|
|
91
91
|
else if (base[key] && master[key] && !mine[key]) {
|
|
92
92
|
delete merged[key]; // value deleted from mine
|
|
93
93
|
}
|
|
94
|
-
else if (
|
|
94
|
+
else if (util_1.isArray(value)) {
|
|
95
95
|
merged[key] = this.mergeMineWinsArray((base[key] || []), (master[key] || []), value);
|
|
96
96
|
}
|
|
97
|
-
else if (
|
|
97
|
+
else if (util_1.isObject(value)) {
|
|
98
98
|
merged[key] = this.mergeMineWins((base[key] || {}), (master[key] || {}), (value || {}));
|
|
99
99
|
}
|
|
100
100
|
});
|
|
@@ -109,7 +109,7 @@ class MineWinsConflictsResolver {
|
|
|
109
109
|
base.forEach((baseItem) => {
|
|
110
110
|
const foundInMaster = this.isObjectInArray(baseItem, master);
|
|
111
111
|
if (!foundInMaster) {
|
|
112
|
-
const foundInMine = mine.findIndex((mineItem) =>
|
|
112
|
+
const foundInMine = mine.findIndex((mineItem) => ramda_1.equals(mineItem, baseItem));
|
|
113
113
|
if (foundInMine > -1) {
|
|
114
114
|
mine.splice(foundInMine, 1);
|
|
115
115
|
}
|
|
@@ -117,7 +117,7 @@ class MineWinsConflictsResolver {
|
|
|
117
117
|
});
|
|
118
118
|
}
|
|
119
119
|
isObjectInArray(obj, array) {
|
|
120
|
-
return array.find((item) =>
|
|
120
|
+
return array.find((item) => ramda_1.equals(item, obj));
|
|
121
121
|
}
|
|
122
122
|
appendMasterAddedElements(base, master, mine) {
|
|
123
123
|
master.forEach((item) => {
|
|
@@ -128,10 +128,10 @@ class MineWinsConflictsResolver {
|
|
|
128
128
|
}
|
|
129
129
|
shouldAddToMine(item, base, mine) {
|
|
130
130
|
if (this.comparableKeys && Object.keys(item).some((key) => this.comparableKeys.includes(key))) {
|
|
131
|
-
return (!mine.some((mineItem) => this.comparableKeys.some((key) =>
|
|
132
|
-
!base.some((baseItem) =>
|
|
131
|
+
return (!mine.some((mineItem) => this.comparableKeys.some((key) => ramda_1.eqProps(key, item, mineItem))) &&
|
|
132
|
+
!base.some((baseItem) => ramda_1.equals(baseItem, item)));
|
|
133
133
|
}
|
|
134
|
-
return !mine.some((mineItem) =>
|
|
134
|
+
return !mine.some((mineItem) => ramda_1.equals(mineItem, item)) && !base.some((baseItem) => ramda_1.equals(baseItem, item));
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
137
|
exports.MineWinsConflictsResolver = MineWinsConflictsResolver;
|