@vtex/api 6.48.0 → 6.48.1-beta.2
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/gen/manifest.schema +2 -3
- package/lib/HttpClient/GraphQLClient.d.ts +1 -1
- package/lib/HttpClient/GraphQLClient.js +1 -0
- package/lib/HttpClient/HttpClient.d.ts +4 -3
- package/lib/HttpClient/HttpClient.js +15 -14
- package/lib/HttpClient/agents.d.ts +5 -2
- package/lib/HttpClient/agents.js +23 -4
- package/lib/HttpClient/index.js +22 -10
- package/lib/HttpClient/middlewares/cache.d.ts +1 -1
- package/lib/HttpClient/middlewares/cache.js +48 -42
- package/lib/HttpClient/middlewares/cancellationToken.d.ts +1 -1
- package/lib/HttpClient/middlewares/cancellationToken.js +3 -1
- package/lib/HttpClient/middlewares/inflight.d.ts +1 -1
- package/lib/HttpClient/middlewares/inflight.js +7 -3
- package/lib/HttpClient/middlewares/memoization.d.ts +1 -1
- package/lib/HttpClient/middlewares/memoization.js +10 -8
- package/lib/HttpClient/middlewares/metrics.js +13 -7
- package/lib/HttpClient/middlewares/notFound.d.ts +1 -1
- package/lib/HttpClient/middlewares/notFound.js +5 -2
- package/lib/HttpClient/middlewares/recorder.js +7 -1
- package/lib/HttpClient/middlewares/request/HttpAgentSingleton.js +2 -1
- package/lib/HttpClient/middlewares/request/index.d.ts +1 -1
- package/lib/HttpClient/middlewares/request/index.js +13 -9
- package/lib/HttpClient/middlewares/request/setupAxios/index.js +6 -4
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/exponentialBackoff.js +7 -5
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/index.js +4 -3
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/index.js +9 -6
- package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/spanSetup.js +10 -7
- package/lib/HttpClient/middlewares/tracing.js +16 -10
- package/lib/HttpClient/typings.d.ts +3 -3
- package/lib/HttpClient/typings.js +1 -0
- package/lib/caches/DiskCache.d.ts +1 -1
- package/lib/caches/DiskCache.js +3 -2
- package/lib/caches/LRUCache.d.ts +3 -3
- package/lib/caches/LRUCache.js +1 -0
- package/lib/caches/LRUDiskCache.d.ts +2 -2
- package/lib/caches/LRUDiskCache.js +3 -2
- package/lib/caches/MultilayeredCache.d.ts +2 -2
- package/lib/caches/MultilayeredCache.js +8 -7
- package/lib/caches/index.js +20 -7
- package/lib/caches/typings.d.ts +5 -5
- package/lib/clients/IOClient.d.ts +1 -1
- package/lib/clients/IOClient.js +1 -0
- package/lib/clients/IOClients.d.ts +1 -1
- package/lib/clients/IOClients.js +1 -0
- package/lib/clients/IOGraphQLClient.js +1 -0
- package/lib/clients/apps/AppClient.js +2 -1
- package/lib/clients/apps/AppGraphQLClient.js +2 -1
- package/lib/clients/apps/Billing.d.ts +1 -1
- package/lib/clients/apps/Billing.js +1 -0
- package/lib/clients/apps/Builder.d.ts +7 -7
- package/lib/clients/apps/Builder.js +2 -1
- package/lib/clients/apps/MessagesGraphQL.d.ts +1 -1
- package/lib/clients/apps/MessagesGraphQL.js +4 -3
- package/lib/clients/apps/Settings.js +4 -3
- package/lib/clients/apps/catalogGraphQL/brand.js +1 -0
- package/lib/clients/apps/catalogGraphQL/category.js +1 -0
- package/lib/clients/apps/catalogGraphQL/index.d.ts +4 -4
- package/lib/clients/apps/catalogGraphQL/index.js +5 -4
- package/lib/clients/apps/catalogGraphQL/product.js +1 -0
- package/lib/clients/apps/catalogGraphQL/sku.js +1 -0
- package/lib/clients/apps/index.js +21 -10
- package/lib/clients/external/ExternalClient.js +1 -0
- package/lib/clients/external/ID.d.ts +4 -4
- package/lib/clients/external/ID.js +1 -0
- package/lib/clients/external/Masterdata.js +1 -0
- package/lib/clients/external/PaymentProvider.d.ts +2 -2
- package/lib/clients/external/PaymentProvider.js +1 -0
- package/lib/clients/external/index.js +18 -7
- package/lib/clients/index.js +22 -10
- package/lib/clients/infra/Apps.d.ts +32 -27
- package/lib/clients/infra/Apps.js +19 -16
- package/lib/clients/infra/Assets.d.ts +6 -5
- package/lib/clients/infra/Assets.js +12 -11
- package/lib/clients/infra/BillingMetrics.d.ts +1 -1
- package/lib/clients/infra/BillingMetrics.js +1 -0
- package/lib/clients/infra/Events.d.ts +1 -1
- package/lib/clients/infra/Events.js +2 -1
- package/lib/clients/infra/Housekeeper.d.ts +3 -3
- package/lib/clients/infra/Housekeeper.js +1 -0
- package/lib/clients/infra/InfraClient.js +1 -0
- package/lib/clients/infra/Registry.d.ts +23 -17
- package/lib/clients/infra/Registry.js +5 -3
- package/lib/clients/infra/Router.d.ts +8 -8
- package/lib/clients/infra/Router.js +1 -0
- package/lib/clients/infra/Sphinx.d.ts +2 -2
- package/lib/clients/infra/Sphinx.js +1 -0
- package/lib/clients/infra/VBase.d.ts +15 -14
- package/lib/clients/infra/VBase.js +4 -3
- package/lib/clients/infra/Workspaces.d.ts +7 -7
- package/lib/clients/infra/Workspaces.js +1 -0
- package/lib/clients/infra/index.js +25 -14
- package/lib/clients/janus/JanusClient.d.ts +1 -1
- package/lib/clients/janus/JanusClient.js +1 -0
- package/lib/clients/janus/LicenseManager.js +2 -1
- package/lib/clients/janus/Segment.d.ts +3 -3
- package/lib/clients/janus/Segment.js +3 -2
- package/lib/clients/janus/Session.d.ts +2 -2
- package/lib/clients/janus/Session.js +1 -0
- package/lib/clients/janus/Tenant.d.ts +1 -1
- package/lib/clients/janus/Tenant.js +1 -0
- package/lib/clients/janus/index.js +19 -8
- package/lib/constants.d.ts +1 -1
- package/lib/constants.js +2 -1
- package/lib/errors/AuthenticationError.js +1 -0
- package/lib/errors/ForbiddenError.js +1 -0
- package/lib/errors/NotFoundError.js +1 -0
- package/lib/errors/RequestCancelledError.js +1 -0
- package/lib/errors/ResolverError.js +2 -1
- package/lib/errors/ResolverWarning.js +1 -0
- package/lib/errors/TooManyRequestsError.js +1 -0
- package/lib/errors/UserInputError.js +1 -0
- package/lib/errors/index.js +22 -11
- package/lib/index.js +31 -18
- package/lib/metrics/MetricsAccumulator.d.ts +2 -2
- package/lib/metrics/MetricsAccumulator.js +10 -9
- package/lib/responses.d.ts +4 -4
- package/lib/service/index.js +11 -6
- package/lib/service/loaders.js +9 -6
- package/lib/service/logger/console.js +8 -4
- package/lib/service/logger/index.js +16 -5
- package/lib/service/logger/logger.js +3 -2
- package/lib/service/logger/metricsLogger.js +11 -10
- package/lib/service/master.js +8 -6
- package/lib/service/metrics/requestMetricsMiddleware.d.ts +1 -1
- package/lib/service/metrics/requestMetricsMiddleware.js +15 -13
- package/lib/service/tracing/TracerSingleton.js +10 -9
- package/lib/service/tracing/metrics/MetricNames.js +13 -12
- package/lib/service/tracing/metrics/instruments.js +15 -7
- package/lib/service/tracing/metrics/measurers/EventLoopLagMeasurer.js +6 -5
- package/lib/service/tracing/tracingMiddlewares.d.ts +3 -3
- package/lib/service/tracing/tracingMiddlewares.js +25 -15
- package/lib/service/worker/index.js +25 -23
- package/lib/service/worker/listeners.js +3 -1
- package/lib/service/worker/runtime/Service.js +2 -1
- package/lib/service/worker/runtime/builtIn/handlers.d.ts +3 -3
- package/lib/service/worker/runtime/builtIn/handlers.js +7 -3
- package/lib/service/worker/runtime/builtIn/middlewares.d.ts +2 -2
- package/lib/service/worker/runtime/builtIn/middlewares.js +6 -3
- package/lib/service/worker/runtime/events/index.d.ts +2 -2
- package/lib/service/worker/runtime/events/index.js +12 -10
- package/lib/service/worker/runtime/events/middlewares/body.js +6 -2
- package/lib/service/worker/runtime/events/middlewares/context.js +2 -1
- package/lib/service/worker/runtime/events/router.d.ts +2 -2
- package/lib/service/worker/runtime/events/router.js +4 -2
- package/lib/service/worker/runtime/graphql/index.js +9 -7
- package/lib/service/worker/runtime/graphql/middlewares/context.js +1 -0
- package/lib/service/worker/runtime/graphql/middlewares/error.js +9 -5
- package/lib/service/worker/runtime/graphql/middlewares/query.d.ts +2 -1
- package/lib/service/worker/runtime/graphql/middlewares/query.js +8 -6
- package/lib/service/worker/runtime/graphql/middlewares/response.js +2 -1
- package/lib/service/worker/runtime/graphql/middlewares/run.d.ts +2 -2
- package/lib/service/worker/runtime/graphql/middlewares/run.js +4 -2
- package/lib/service/worker/runtime/graphql/middlewares/updateSchema.d.ts +2 -1
- package/lib/service/worker/runtime/graphql/middlewares/updateSchema.js +5 -3
- package/lib/service/worker/runtime/graphql/middlewares/upload.js +2 -1
- package/lib/service/worker/runtime/graphql/schema/index.d.ts +1 -1
- package/lib/service/worker/runtime/graphql/schema/index.js +9 -7
- package/lib/service/worker/runtime/graphql/schema/messagesLoaderV2.d.ts +2 -2
- package/lib/service/worker/runtime/graphql/schema/messagesLoaderV2.js +5 -3
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Auth.js +2 -1
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/CacheControl.js +1 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Deprecated.js +2 -1
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Metric.js +1 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Sanitize.js +1 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Settings.js +2 -1
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/SmartCacheDirective.js +1 -0
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/TranslatableV2.js +3 -2
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/TranslateTo.js +3 -2
- package/lib/service/worker/runtime/graphql/schema/schemaDirectives/index.js +3 -2
- package/lib/service/worker/runtime/graphql/schema/typeDefs/index.d.ts +2 -1
- package/lib/service/worker/runtime/graphql/schema/typeDefs/index.js +3 -1
- package/lib/service/worker/runtime/graphql/schema/typeDefs/ioUpload.js +1 -0
- package/lib/service/worker/runtime/graphql/schema/typeDefs/sanitizedString.js +3 -2
- package/lib/service/worker/runtime/graphql/typings.d.ts +3 -3
- package/lib/service/worker/runtime/graphql/utils/cacheControl.d.ts +2 -1
- package/lib/service/worker/runtime/graphql/utils/cacheControl.js +3 -1
- package/lib/service/worker/runtime/graphql/utils/error.d.ts +2 -1
- package/lib/service/worker/runtime/graphql/utils/error.js +11 -9
- package/lib/service/worker/runtime/graphql/utils/pathname.js +4 -2
- package/lib/service/worker/runtime/graphql/utils/translations.d.ts +1 -1
- package/lib/service/worker/runtime/graphql/utils/translations.js +8 -4
- package/lib/service/worker/runtime/http/index.d.ts +3 -3
- package/lib/service/worker/runtime/http/index.js +23 -20
- package/lib/service/worker/runtime/http/middlewares/authTokens.js +1 -0
- package/lib/service/worker/runtime/http/middlewares/cancellationToken.js +1 -0
- package/lib/service/worker/runtime/http/middlewares/clients.js +1 -0
- package/lib/service/worker/runtime/http/middlewares/context.js +8 -5
- package/lib/service/worker/runtime/http/middlewares/error.js +10 -6
- package/lib/service/worker/runtime/http/middlewares/rateLimit.js +2 -1
- package/lib/service/worker/runtime/http/middlewares/requestStats.js +1 -0
- package/lib/service/worker/runtime/http/middlewares/setCookie.js +6 -5
- package/lib/service/worker/runtime/http/middlewares/settings.d.ts +1 -1
- package/lib/service/worker/runtime/http/middlewares/settings.js +14 -9
- package/lib/service/worker/runtime/http/middlewares/timings.js +4 -3
- package/lib/service/worker/runtime/http/middlewares/vary.js +1 -0
- package/lib/service/worker/runtime/http/router.d.ts +1 -1
- package/lib/service/worker/runtime/http/router.js +4 -2
- package/lib/service/worker/runtime/http/routes.js +9 -5
- package/lib/service/worker/runtime/method.d.ts +2 -2
- package/lib/service/worker/runtime/method.js +2 -1
- package/lib/service/worker/runtime/statusTrack.d.ts +2 -2
- package/lib/service/worker/runtime/statusTrack.js +11 -5
- package/lib/service/worker/runtime/typings.d.ts +10 -10
- package/lib/service/worker/runtime/utils/compose.d.ts +3 -3
- package/lib/service/worker/runtime/utils/compose.js +5 -2
- package/lib/service/worker/runtime/utils/context.d.ts +4 -1
- package/lib/service/worker/runtime/utils/context.js +6 -4
- package/lib/service/worker/runtime/utils/diff.js +1 -0
- package/lib/service/worker/runtime/utils/recorder.js +2 -1
- package/lib/service/worker/runtime/utils/toArray.js +3 -1
- package/lib/service/worker/runtime/utils/tokenBucket.js +1 -0
- package/lib/tracing/Tags.js +2 -1
- package/lib/tracing/UserLandTracer.js +4 -2
- package/lib/tracing/errorReporting/ErrorReport.js +14 -13
- package/lib/tracing/index.js +10 -9
- package/lib/tracing/spanReference/SpanReferenceTypes.js +1 -0
- package/lib/tracing/spanReference/createSpanReference.js +1 -0
- package/lib/tracing/utils.js +6 -4
- package/lib/utils/MineWinsConflictsResolver.d.ts +4 -4
- package/lib/utils/MineWinsConflictsResolver.js +11 -10
- package/lib/utils/app.js +40 -23
- package/lib/utils/appsStaleIfError.d.ts +1 -0
- package/lib/utils/appsStaleIfError.js +33 -12
- package/lib/utils/billingOptions.js +3 -1
- package/lib/utils/binding.js +5 -2
- package/lib/utils/cancel.js +1 -0
- package/lib/utils/conflicts.mock.js +1 -0
- package/lib/utils/domain.js +2 -1
- package/lib/utils/error.js +6 -4
- package/lib/utils/index.js +23 -12
- package/lib/utils/json.js +1 -0
- package/lib/utils/log.js +4 -2
- package/lib/utils/message.js +9 -5
- package/lib/utils/renameBy.js +3 -1
- package/lib/utils/retry.js +10 -7
- package/lib/utils/status.js +3 -1
- package/lib/utils/tenant.js +5 -2
- package/lib/utils/throwOnGraphQLErrors.js +1 -0
- package/lib/utils/time.d.ts +3 -5
- package/lib/utils/time.js +24 -14
- package/package.json +4 -4
- package/CHANGELOG.md +0 -1858
package/gen/manifest.schema
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
"definitions": {
|
|
4
4
|
"BILLING_TYPE": {
|
|
5
5
|
"enum": [
|
|
6
|
-
"billable",
|
|
7
6
|
"free",
|
|
7
|
+
"billable",
|
|
8
8
|
"sponsored"
|
|
9
9
|
],
|
|
10
10
|
"type": "string"
|
|
@@ -172,8 +172,7 @@
|
|
|
172
172
|
},
|
|
173
173
|
"type": "array"
|
|
174
174
|
},
|
|
175
|
-
"settingsSchema": {
|
|
176
|
-
},
|
|
175
|
+
"settingsSchema": {},
|
|
177
176
|
"title": {
|
|
178
177
|
"type": "string"
|
|
179
178
|
},
|
|
@@ -13,7 +13,7 @@ interface MutateOptions<Variables extends object> {
|
|
|
13
13
|
variables: Variables;
|
|
14
14
|
throwOnError?: boolean;
|
|
15
15
|
}
|
|
16
|
-
export
|
|
16
|
+
export type Serializable = object | boolean | string | number;
|
|
17
17
|
export interface GraphQLResponse<T extends Serializable> {
|
|
18
18
|
data?: T;
|
|
19
19
|
errors?: GraphQLError[];
|
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.GraphQLClient = void 0;
|
|
6
7
|
const customGraphQLError_1 = __importDefault(require("../errors/customGraphQLError"));
|
|
7
8
|
const inflight_1 = require("./middlewares/inflight");
|
|
8
9
|
const throwOnGraphQLErrors = (message, response) => {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
import { AxiosResponse } from 'axios';
|
|
3
4
|
import { IncomingMessage } from 'http';
|
|
4
5
|
import { IOContext } from '../service/worker/runtime/typings';
|
|
5
6
|
import { InstanceOptions, IOResponse, RequestConfig } from './typings';
|
|
6
|
-
|
|
7
|
+
type ClientOptions = IOContext & Partial<InstanceOptions>;
|
|
7
8
|
export declare class HttpClient {
|
|
8
9
|
name: string;
|
|
9
10
|
private logger;
|
|
@@ -25,8 +26,8 @@ export declare class HttpClient {
|
|
|
25
26
|
postRaw: <T = void>(url: string, data?: any, config?: RequestConfig) => Promise<IOResponse<T>>;
|
|
26
27
|
patch: <T = void>(url: string, data?: any, config?: RequestConfig) => Promise<T>;
|
|
27
28
|
head: (url: string, config?: RequestConfig) => Promise<IOResponse<void>>;
|
|
28
|
-
delete: <T = void>(url: string, config?: RequestConfig
|
|
29
|
-
protected request: (config: RequestConfig) => Promise<AxiosResponse
|
|
29
|
+
delete: <T = void>(url: string, config?: RequestConfig) => Promise<IOResponse<T>>;
|
|
30
|
+
protected request: (config: RequestConfig) => Promise<AxiosResponse>;
|
|
30
31
|
private getConfig;
|
|
31
32
|
}
|
|
32
33
|
export {};
|
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.HttpClient = void 0;
|
|
6
7
|
const crypto_1 = require("crypto");
|
|
7
8
|
const koa_compose_1 = __importDefault(require("koa-compose"));
|
|
8
9
|
const p_limit_1 = __importDefault(require("p-limit"));
|
|
@@ -43,7 +44,7 @@ class HttpClient {
|
|
|
43
44
|
return v;
|
|
44
45
|
}
|
|
45
46
|
};
|
|
46
|
-
const bodyHash = crypto_1.createHash('md5').update(JSON.stringify(data, deterministicReplacer)).digest('hex');
|
|
47
|
+
const bodyHash = (0, crypto_1.createHash)('md5').update(JSON.stringify(data, deterministicReplacer)).digest('hex');
|
|
47
48
|
const cacheableConfig = this.getConfig(url, {
|
|
48
49
|
...config,
|
|
49
50
|
data,
|
|
@@ -106,14 +107,14 @@ class HttpClient {
|
|
|
106
107
|
this.logger = logger;
|
|
107
108
|
this.cacheableType = cacheableType;
|
|
108
109
|
this.memoizable = memoizable;
|
|
109
|
-
const limit = concurrency && concurrency > 0 && p_limit_1.default(concurrency) || undefined;
|
|
110
|
+
const limit = concurrency && concurrency > 0 && (0, p_limit_1.default)(concurrency) || undefined;
|
|
110
111
|
const headers = {
|
|
111
112
|
...defaultHeaders,
|
|
112
113
|
'Accept-Encoding': 'gzip',
|
|
113
114
|
'User-Agent': userAgent,
|
|
114
115
|
...host ? { [constants_1.FORWARDED_HOST_HEADER]: host } : null,
|
|
115
|
-
...tenant ? { [constants_1.TENANT_HEADER]: tenant_1.formatTenantHeaderValue(tenant) } : null,
|
|
116
|
-
...binding ? { [constants_1.BINDING_HEADER]: binding_1.formatBindingHeaderValue(binding) } : null,
|
|
116
|
+
...tenant ? { [constants_1.TENANT_HEADER]: (0, tenant_1.formatTenantHeaderValue)(tenant) } : null,
|
|
117
|
+
...binding ? { [constants_1.BINDING_HEADER]: (0, binding_1.formatBindingHeaderValue)(binding) } : null,
|
|
117
118
|
...locale ? { [constants_1.LOCALE_HEADER]: locale } : null,
|
|
118
119
|
...operationId ? { 'x-vtex-operation-id': operationId } : null,
|
|
119
120
|
...product ? { [constants_1.PRODUCT_HEADER]: product } : null,
|
|
@@ -124,21 +125,21 @@ class HttpClient {
|
|
|
124
125
|
headers['Authorization'] = `${authType} ${authToken}`; // tslint:disable-line
|
|
125
126
|
}
|
|
126
127
|
const memoizedCache = new Map();
|
|
127
|
-
this.runMiddlewares = koa_compose_1.default([
|
|
128
|
-
tracing_1.createHttpClientTracingMiddleware({ tracer, logger, clientName: this.name, hasDiskCacheMiddleware: !!diskCache, hasMemoryCacheMiddleware: !!memoryCache }),
|
|
128
|
+
this.runMiddlewares = (0, koa_compose_1.default)([
|
|
129
|
+
(0, tracing_1.createHttpClientTracingMiddleware)({ tracer, logger, clientName: this.name, hasDiskCacheMiddleware: !!diskCache, hasMemoryCacheMiddleware: !!memoryCache }),
|
|
129
130
|
...(opts.middlewares || []),
|
|
130
|
-
request_1.defaultsMiddleware({ baseURL, rawHeaders: headers, params, timeout, retries, verbose, exponentialTimeoutCoefficient, initialBackoffDelay, exponentialBackoffCoefficient, httpsAgent }),
|
|
131
|
-
metrics_1.metricsMiddleware({ metrics, serverTiming, name }),
|
|
132
|
-
memoization_1.memoizationMiddleware({ memoizedCache }),
|
|
133
|
-
...recorder ? [recorder_1.recorderMiddleware(recorder)] : [],
|
|
134
|
-
cancellationToken_1.cancellationToken(cancellation),
|
|
131
|
+
(0, request_1.defaultsMiddleware)({ baseURL, rawHeaders: headers, params, timeout, retries, verbose, exponentialTimeoutCoefficient, initialBackoffDelay, exponentialBackoffCoefficient, httpsAgent }),
|
|
132
|
+
(0, metrics_1.metricsMiddleware)({ metrics, serverTiming, name }),
|
|
133
|
+
(0, memoization_1.memoizationMiddleware)({ memoizedCache }),
|
|
134
|
+
...recorder ? [(0, recorder_1.recorderMiddleware)(recorder)] : [],
|
|
135
|
+
(0, cancellationToken_1.cancellationToken)(cancellation),
|
|
135
136
|
inflight_1.singleFlightMiddleware,
|
|
136
137
|
notFound_1.acceptNotFoundMiddleware,
|
|
137
|
-
...memoryCache ? [cache_1.cacheMiddleware({ type: cache_1.CacheType.Memory, storage: memoryCache, asyncSet: asyncSetCache })] : [],
|
|
138
|
-
...diskCache ? [cache_1.cacheMiddleware({ type: cache_1.CacheType.Disk, storage: diskCache, asyncSet: asyncSetCache })] : [],
|
|
138
|
+
...memoryCache ? [(0, cache_1.cacheMiddleware)({ type: cache_1.CacheType.Memory, storage: memoryCache, asyncSet: asyncSetCache })] : [],
|
|
139
|
+
...diskCache ? [(0, cache_1.cacheMiddleware)({ type: cache_1.CacheType.Disk, storage: diskCache, asyncSet: asyncSetCache })] : [],
|
|
139
140
|
notFound_1.notFoundFallbackMiddleware,
|
|
140
141
|
request_1.routerCacheMiddleware,
|
|
141
|
-
request_1.requestMiddleware(limit),
|
|
142
|
+
(0, request_1.requestMiddleware)(limit),
|
|
142
143
|
]);
|
|
143
144
|
}
|
|
144
145
|
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import HttpAgent, { HttpOptions as AgentHttpOptions, HttpsAgent, HttpsOptions as AgentHttpsOptions } from 'agentkeepalive';
|
|
2
|
-
|
|
3
|
-
export declare const
|
|
2
|
+
type HttpOptions = Omit<AgentHttpOptions, 'freeSocketTimeout' | 'keepAlive' | 'maxFreeSockets'>;
|
|
3
|
+
export declare const createHttpAgent: (opts?: HttpOptions) => HttpAgent;
|
|
4
|
+
type HttpsOptions = Omit<AgentHttpsOptions, 'freeSocketTimeout' | 'keepAlive' | 'maxFreeSockets'>;
|
|
5
|
+
export declare const createHttpsAgent: (opts?: HttpsOptions) => HttpsAgent;
|
|
6
|
+
export {};
|
package/lib/HttpClient/agents.js
CHANGED
|
@@ -1,24 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
2
18
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
3
19
|
if (mod && mod.__esModule) return mod;
|
|
4
20
|
var result = {};
|
|
5
|
-
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result
|
|
6
|
-
result
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
7
23
|
return result;
|
|
8
24
|
};
|
|
9
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.createHttpsAgent = exports.createHttpAgent = void 0;
|
|
10
27
|
const agentkeepalive_1 = __importStar(require("agentkeepalive"));
|
|
11
|
-
|
|
28
|
+
const createHttpAgent = (opts) => new agentkeepalive_1.default({
|
|
12
29
|
...opts,
|
|
13
30
|
freeSocketTimeout: 30 * 1000,
|
|
14
31
|
keepAlive: true,
|
|
15
32
|
maxFreeSockets: 256,
|
|
16
33
|
socketActiveTTL: 120 * 1000,
|
|
17
34
|
});
|
|
18
|
-
exports.
|
|
35
|
+
exports.createHttpAgent = createHttpAgent;
|
|
36
|
+
const createHttpsAgent = (opts) => new agentkeepalive_1.HttpsAgent({
|
|
19
37
|
...opts,
|
|
20
38
|
freeSocketTimeout: 30 * 1000,
|
|
21
39
|
keepAlive: true,
|
|
22
40
|
maxFreeSockets: 256,
|
|
23
41
|
socketActiveTTL: 120 * 1000,
|
|
24
42
|
});
|
|
43
|
+
exports.createHttpsAgent = createHttpsAgent;
|
package/lib/HttpClient/index.js
CHANGED
|
@@ -1,14 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
5
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
17
|
+
exports.inflightUrlWithQuery = exports.inflightURL = exports.CacheType = void 0;
|
|
18
|
+
__exportStar(require("./HttpClient"), exports);
|
|
19
|
+
__exportStar(require("./typings"), exports);
|
|
20
|
+
__exportStar(require("./GraphQLClient"), exports);
|
|
21
|
+
__exportStar(require("./agents"), exports);
|
|
10
22
|
var cache_1 = require("./middlewares/cache");
|
|
11
|
-
exports
|
|
23
|
+
Object.defineProperty(exports, "CacheType", { enumerable: true, get: function () { return cache_1.CacheType; } });
|
|
12
24
|
var inflight_1 = require("./middlewares/inflight");
|
|
13
|
-
exports
|
|
14
|
-
exports
|
|
25
|
+
Object.defineProperty(exports, "inflightURL", { enumerable: true, get: function () { return inflight_1.inflightURL; } });
|
|
26
|
+
Object.defineProperty(exports, "inflightUrlWithQuery", { enumerable: true, get: function () { return inflight_1.inflightUrlWithQuery; } });
|
|
@@ -28,7 +28,7 @@ export interface Cached {
|
|
|
28
28
|
responseType?: string;
|
|
29
29
|
responseEncoding?: BufferEncoding;
|
|
30
30
|
}
|
|
31
|
-
export
|
|
31
|
+
export type CacheableRequestConfig = RequestConfig & {
|
|
32
32
|
url: string;
|
|
33
33
|
cacheable: CacheType;
|
|
34
34
|
memoizable: boolean;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cacheMiddleware = exports.CacheType = exports.isLocallyCacheable = exports.cacheKey = void 0;
|
|
3
4
|
const constants_1 = require("../../constants");
|
|
4
5
|
const tracing_1 = require("../../tracing");
|
|
5
6
|
const RANGE_HEADER_QS_KEY = '__range_header';
|
|
6
7
|
const cacheableStatusCodes = [200, 203, 204, 206, 300, 301, 404, 405, 410, 414, 501]; // https://tools.ietf.org/html/rfc7231#section-6.1
|
|
7
|
-
|
|
8
|
+
const cacheKey = (config) => {
|
|
8
9
|
const { baseURL = '', url = '', params, headers } = config;
|
|
9
|
-
const locale = headers[constants_1.LOCALE_HEADER];
|
|
10
|
+
const locale = headers === null || headers === void 0 ? void 0 : headers[constants_1.LOCALE_HEADER];
|
|
10
11
|
const encodedBaseURL = baseURL.replace(/\//g, '\\');
|
|
11
12
|
const encodedURL = url.replace(/\//g, '\\');
|
|
12
13
|
let key = `${locale}--${encodedBaseURL}--${encodedURL}?`;
|
|
@@ -18,6 +19,7 @@ exports.cacheKey = (config) => {
|
|
|
18
19
|
}
|
|
19
20
|
return key;
|
|
20
21
|
};
|
|
22
|
+
exports.cacheKey = cacheKey;
|
|
21
23
|
const parseCacheHeaders = (headers) => {
|
|
22
24
|
const { 'cache-control': cacheControl = '', etag, age: ageStr } = headers;
|
|
23
25
|
const cacheDirectives = cacheControl.split(',').map(d => d.trim());
|
|
@@ -52,26 +54,26 @@ const CacheTypeNames = {
|
|
|
52
54
|
[CacheType.Disk]: 'disk',
|
|
53
55
|
[CacheType.Any]: 'any',
|
|
54
56
|
};
|
|
55
|
-
|
|
56
|
-
const CACHE_RESULT_TAG = type === CacheType.Disk ? "http.cache.disk" /* HTTP_DISK_CACHE_RESULT */ : "http.cache.memory" /* HTTP_MEMORY_CACHE_RESULT */;
|
|
57
|
+
const cacheMiddleware = ({ type, storage, asyncSet }) => {
|
|
58
|
+
const CACHE_RESULT_TAG = type === CacheType.Disk ? "http.cache.disk" /* CustomHttpTags.HTTP_DISK_CACHE_RESULT */ : "http.cache.memory" /* CustomHttpTags.HTTP_MEMORY_CACHE_RESULT */;
|
|
57
59
|
const cacheType = CacheTypeNames[type];
|
|
58
60
|
return async (ctx, next) => {
|
|
59
|
-
var _a;
|
|
61
|
+
var _a, _b;
|
|
60
62
|
if (!isLocallyCacheable(ctx.config, type)) {
|
|
61
63
|
return await next();
|
|
62
64
|
}
|
|
63
65
|
const { rootSpan: span, tracer, logger } = (_a = ctx.tracing) !== null && _a !== void 0 ? _a : {};
|
|
64
|
-
const key = exports.cacheKey(ctx.config);
|
|
65
|
-
const segmentToken = ctx.config.headers[constants_1.SEGMENT_HEADER];
|
|
66
|
+
const key = (0, exports.cacheKey)(ctx.config);
|
|
67
|
+
const segmentToken = (_b = ctx.config.headers) === null || _b === void 0 ? void 0 : _b[constants_1.SEGMENT_HEADER];
|
|
66
68
|
const keyWithSegment = key + segmentToken;
|
|
67
69
|
span === null || span === void 0 ? void 0 : span.log({
|
|
68
|
-
event: "cache-key-created" /* CACHE_KEY_CREATE */,
|
|
69
|
-
["cache-type" /* CACHE_TYPE */]: cacheType,
|
|
70
|
-
["key" /* KEY */]: key,
|
|
71
|
-
["key-with-segment" /* KEY_WITH_SEGMENT */]: keyWithSegment,
|
|
70
|
+
event: "cache-key-created" /* HttpLogEvents.CACHE_KEY_CREATE */,
|
|
71
|
+
["cache-type" /* HttpCacheLogFields.CACHE_TYPE */]: cacheType,
|
|
72
|
+
["key" /* HttpCacheLogFields.KEY */]: key,
|
|
73
|
+
["key-with-segment" /* HttpCacheLogFields.KEY_WITH_SEGMENT */]: keyWithSegment,
|
|
72
74
|
});
|
|
73
75
|
const cacheReadSpan = createCacheSpan(cacheType, 'read', tracer, span);
|
|
74
|
-
let cached;
|
|
76
|
+
let cached = undefined;
|
|
75
77
|
try {
|
|
76
78
|
const cacheHasWithSegment = await storage.has(keyWithSegment);
|
|
77
79
|
cached = cacheHasWithSegment ? await storage.get(keyWithSegment) : await storage.get(key);
|
|
@@ -90,12 +92,12 @@ exports.cacheMiddleware = ({ type, storage, asyncSet }) => {
|
|
|
90
92
|
}
|
|
91
93
|
const now = Date.now();
|
|
92
94
|
span === null || span === void 0 ? void 0 : span.log({
|
|
93
|
-
event: "local-cache-hit-info" /* LOCAL_CACHE_HIT_INFO */,
|
|
94
|
-
["cache-type" /* CACHE_TYPE */]: cacheType,
|
|
95
|
-
["etag" /* ETAG */]: cachedEtag,
|
|
96
|
-
["expiration-time" /* EXPIRATION_TIME */]: (expiration - now) / 1000,
|
|
97
|
-
["response-type" /* RESPONSE_TYPE */]: responseType,
|
|
98
|
-
["response-encoding" /* RESPONSE_ENCONDING */]: responseEncoding,
|
|
95
|
+
event: "local-cache-hit-info" /* HttpLogEvents.LOCAL_CACHE_HIT_INFO */,
|
|
96
|
+
["cache-type" /* HttpCacheLogFields.CACHE_TYPE */]: cacheType,
|
|
97
|
+
["etag" /* HttpCacheLogFields.ETAG */]: cachedEtag,
|
|
98
|
+
["expiration-time" /* HttpCacheLogFields.EXPIRATION_TIME */]: (expiration - now) / 1000,
|
|
99
|
+
["response-type" /* HttpCacheLogFields.RESPONSE_TYPE */]: responseType,
|
|
100
|
+
["response-encoding" /* HttpCacheLogFields.RESPONSE_ENCONDING */]: responseEncoding,
|
|
99
101
|
});
|
|
100
102
|
if (expiration > now) {
|
|
101
103
|
ctx.response = response;
|
|
@@ -104,18 +106,21 @@ exports.cacheMiddleware = ({ type, storage, asyncSet }) => {
|
|
|
104
106
|
revalidated: 0,
|
|
105
107
|
router: 0,
|
|
106
108
|
};
|
|
107
|
-
span === null || span === void 0 ? void 0 : span.setTag(CACHE_RESULT_TAG, "HIT" /* HIT */);
|
|
109
|
+
span === null || span === void 0 ? void 0 : span.setTag(CACHE_RESULT_TAG, "HIT" /* CacheResult.HIT */);
|
|
108
110
|
return;
|
|
109
111
|
}
|
|
110
|
-
span === null || span === void 0 ? void 0 : span.setTag(CACHE_RESULT_TAG, "STALE" /* STALE */);
|
|
112
|
+
span === null || span === void 0 ? void 0 : span.setTag(CACHE_RESULT_TAG, "STALE" /* CacheResult.STALE */);
|
|
111
113
|
const validateStatus = addNotModified(ctx.config.validateStatus);
|
|
112
114
|
if (cachedEtag && validateStatus(response.status)) {
|
|
113
|
-
ctx.config.headers
|
|
115
|
+
ctx.config.headers = {
|
|
116
|
+
...ctx.config.headers,
|
|
117
|
+
'if-none-match': cachedEtag
|
|
118
|
+
};
|
|
114
119
|
ctx.config.validateStatus = validateStatus;
|
|
115
120
|
}
|
|
116
121
|
}
|
|
117
122
|
else {
|
|
118
|
-
span === null || span === void 0 ? void 0 : span.setTag(CACHE_RESULT_TAG, "MISS" /* MISS */);
|
|
123
|
+
span === null || span === void 0 ? void 0 : span.setTag(CACHE_RESULT_TAG, "MISS" /* CacheResult.MISS */);
|
|
119
124
|
}
|
|
120
125
|
await next();
|
|
121
126
|
if (!ctx.response) {
|
|
@@ -135,19 +140,19 @@ exports.cacheMiddleware = ({ type, storage, asyncSet }) => {
|
|
|
135
140
|
const { forceMaxAge } = ctx.config;
|
|
136
141
|
const maxAge = forceMaxAge && cacheableStatusCodes.includes(status) ? Math.max(forceMaxAge, headerMaxAge) : headerMaxAge;
|
|
137
142
|
span === null || span === void 0 ? void 0 : span.log({
|
|
138
|
-
event: "cache-config" /* CACHE_CONFIG */,
|
|
139
|
-
["cache-type" /* CACHE_TYPE */]: cacheType,
|
|
140
|
-
["age" /* AGE */]: age,
|
|
141
|
-
["calculated-max-age" /* CALCULATED_MAX_AGE */]: maxAge,
|
|
142
|
-
["max-age" /* MAX_AGE */]: headerMaxAge,
|
|
143
|
-
["force-max-age" /* FORCE_MAX_AGE */]: forceMaxAge,
|
|
144
|
-
["etag" /* ETAG */]: etag,
|
|
145
|
-
["no-cache" /* NO_CACHE */]: noCache,
|
|
146
|
-
["no-store" /* NO_STORE */]: noStore,
|
|
143
|
+
event: "cache-config" /* HttpLogEvents.CACHE_CONFIG */,
|
|
144
|
+
["cache-type" /* HttpCacheLogFields.CACHE_TYPE */]: cacheType,
|
|
145
|
+
["age" /* HttpCacheLogFields.AGE */]: age,
|
|
146
|
+
["calculated-max-age" /* HttpCacheLogFields.CALCULATED_MAX_AGE */]: maxAge,
|
|
147
|
+
["max-age" /* HttpCacheLogFields.MAX_AGE */]: headerMaxAge,
|
|
148
|
+
["force-max-age" /* HttpCacheLogFields.FORCE_MAX_AGE */]: forceMaxAge,
|
|
149
|
+
["etag" /* HttpCacheLogFields.ETAG */]: etag,
|
|
150
|
+
["no-cache" /* HttpCacheLogFields.NO_CACHE */]: noCache,
|
|
151
|
+
["no-store" /* HttpCacheLogFields.NO_STORE */]: noStore,
|
|
147
152
|
});
|
|
148
153
|
// Indicates this should NOT be cached and this request will not be considered a miss.
|
|
149
154
|
if (!forceMaxAge && (noStore || (noCache && !etag))) {
|
|
150
|
-
span === null || span === void 0 ? void 0 : span.log({ event: "no-local-cache-save" /* NO_LOCAL_CACHE_SAVE */, ["cache-type" /* CACHE_TYPE */]: cacheType });
|
|
155
|
+
span === null || span === void 0 ? void 0 : span.log({ event: "no-local-cache-save" /* HttpLogEvents.NO_LOCAL_CACHE_SAVE */, ["cache-type" /* HttpCacheLogFields.CACHE_TYPE */]: cacheType });
|
|
151
156
|
return;
|
|
152
157
|
}
|
|
153
158
|
const shouldCache = maxAge || etag;
|
|
@@ -175,7 +180,7 @@ exports.cacheMiddleware = ({ type, storage, asyncSet }) => {
|
|
|
175
180
|
etag,
|
|
176
181
|
expiration,
|
|
177
182
|
response: { data: cacheableData, headers, status },
|
|
178
|
-
responseEncoding,
|
|
183
|
+
responseEncoding: responseEncoding,
|
|
179
184
|
responseType,
|
|
180
185
|
});
|
|
181
186
|
if (asyncSet) {
|
|
@@ -184,14 +189,14 @@ exports.cacheMiddleware = ({ type, storage, asyncSet }) => {
|
|
|
184
189
|
else {
|
|
185
190
|
await storageSet();
|
|
186
191
|
span === null || span === void 0 ? void 0 : span.log({
|
|
187
|
-
event: "local-cache-saved" /* LOCAL_CACHE_SAVED */,
|
|
188
|
-
["cache-type" /* CACHE_TYPE */]: cacheType,
|
|
189
|
-
["key-set" /* KEY_SET */]: setKey,
|
|
190
|
-
["age" /* AGE */]: currentAge,
|
|
191
|
-
["etag" /* ETAG */]: etag,
|
|
192
|
-
["expiration-time" /* EXPIRATION_TIME */]: (expiration - Date.now()) / 1000,
|
|
193
|
-
["response-encoding" /* RESPONSE_ENCONDING */]: responseEncoding,
|
|
194
|
-
["response-type" /* RESPONSE_TYPE */]: responseType,
|
|
192
|
+
event: "local-cache-saved" /* HttpLogEvents.LOCAL_CACHE_SAVED */,
|
|
193
|
+
["cache-type" /* HttpCacheLogFields.CACHE_TYPE */]: cacheType,
|
|
194
|
+
["key-set" /* HttpCacheLogFields.KEY_SET */]: setKey,
|
|
195
|
+
["age" /* HttpCacheLogFields.AGE */]: currentAge,
|
|
196
|
+
["etag" /* HttpCacheLogFields.ETAG */]: etag,
|
|
197
|
+
["expiration-time" /* HttpCacheLogFields.EXPIRATION_TIME */]: (expiration - Date.now()) / 1000,
|
|
198
|
+
["response-encoding" /* HttpCacheLogFields.RESPONSE_ENCONDING */]: responseEncoding,
|
|
199
|
+
["response-type" /* HttpCacheLogFields.RESPONSE_TYPE */]: responseType,
|
|
195
200
|
});
|
|
196
201
|
}
|
|
197
202
|
}
|
|
@@ -204,9 +209,10 @@ exports.cacheMiddleware = ({ type, storage, asyncSet }) => {
|
|
|
204
209
|
}
|
|
205
210
|
return;
|
|
206
211
|
}
|
|
207
|
-
span === null || span === void 0 ? void 0 : span.log({ event: "no-local-cache-save" /* NO_LOCAL_CACHE_SAVE */, ["cache-type" /* CACHE_TYPE */]: cacheType });
|
|
212
|
+
span === null || span === void 0 ? void 0 : span.log({ event: "no-local-cache-save" /* HttpLogEvents.NO_LOCAL_CACHE_SAVE */, ["cache-type" /* HttpCacheLogFields.CACHE_TYPE */]: cacheType });
|
|
208
213
|
};
|
|
209
214
|
};
|
|
215
|
+
exports.cacheMiddleware = cacheMiddleware;
|
|
210
216
|
const createCacheSpan = (cacheType, operation, tracer, parentSpan) => {
|
|
211
217
|
if (tracer && tracer.isTraceSampled && cacheType === 'disk') {
|
|
212
218
|
return tracer.startSpan(`${operation}-disk-cache`, { childOf: parentSpan });
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Cancellation } from '../../service/worker/runtime/typings';
|
|
2
2
|
import { MiddlewareContext } from '../typings';
|
|
3
|
-
export declare const cancellationToken: (cancellation?: Cancellation
|
|
3
|
+
export declare const cancellationToken: (cancellation?: Cancellation) => (ctx: MiddlewareContext, next: () => Promise<void>) => Promise<void>;
|
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.cancellationToken = void 0;
|
|
6
7
|
const axios_1 = __importDefault(require("axios"));
|
|
7
8
|
const constants_1 = require("../../constants");
|
|
8
9
|
const production = process.env.VTEX_PRODUCTION === 'true';
|
|
@@ -42,7 +43,7 @@ const handleCancellation = (ctx, cancellation) => {
|
|
|
42
43
|
},
|
|
43
44
|
};
|
|
44
45
|
};
|
|
45
|
-
|
|
46
|
+
const cancellationToken = (cancellation) => async (ctx, next) => {
|
|
46
47
|
const { config: { method } } = ctx;
|
|
47
48
|
if (!cancellation) {
|
|
48
49
|
return await next();
|
|
@@ -70,3 +71,4 @@ exports.cancellationToken = (cancellation) => async (ctx, next) => {
|
|
|
70
71
|
onRequestFinish();
|
|
71
72
|
}
|
|
72
73
|
};
|
|
74
|
+
exports.cancellationToken = cancellationToken;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { InflightKeyGenerator, MiddlewareContext } from '../typings';
|
|
2
|
-
export
|
|
2
|
+
export type Inflight = Required<Pick<MiddlewareContext, 'cacheHit' | 'response'>>;
|
|
3
3
|
export declare const singleFlightMiddleware: (ctx: MiddlewareContext, next: () => Promise<void>) => Promise<void>;
|
|
4
4
|
export declare const inflightURL: InflightKeyGenerator;
|
|
5
5
|
export declare const inflightUrlWithQuery: InflightKeyGenerator;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.inflightUrlWithQuery = exports.inflightURL = exports.singleFlightMiddleware = void 0;
|
|
3
4
|
const qs_1 = require("qs");
|
|
4
5
|
const inflight = new Map();
|
|
5
6
|
let metricsAdded = false;
|
|
6
|
-
|
|
7
|
+
const singleFlightMiddleware = async (ctx, next) => {
|
|
7
8
|
const { inflightKey } = ctx.config;
|
|
8
9
|
if (!inflightKey) {
|
|
9
10
|
return await next();
|
|
@@ -46,5 +47,8 @@ exports.singleFlightMiddleware = async (ctx, next) => {
|
|
|
46
47
|
await promise;
|
|
47
48
|
}
|
|
48
49
|
};
|
|
49
|
-
exports.
|
|
50
|
-
|
|
50
|
+
exports.singleFlightMiddleware = singleFlightMiddleware;
|
|
51
|
+
const inflightURL = ({ baseURL, url }) => baseURL + url;
|
|
52
|
+
exports.inflightURL = inflightURL;
|
|
53
|
+
const inflightUrlWithQuery = ({ baseURL, url, params }) => baseURL + url + (0, qs_1.stringify)(params, { arrayFormat: 'repeat', addQueryPrefix: true });
|
|
54
|
+
exports.inflightUrlWithQuery = inflightUrlWithQuery;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MiddlewareContext } from '../typings';
|
|
2
|
-
export
|
|
2
|
+
export type Memoized = Required<Pick<MiddlewareContext, 'cacheHit' | 'response'>>;
|
|
3
3
|
interface MemoizationOptions {
|
|
4
4
|
memoizedCache: Map<string, Promise<Memoized>>;
|
|
5
5
|
}
|
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.memoizationMiddleware = void 0;
|
|
3
4
|
const cache_1 = require("./cache");
|
|
4
|
-
|
|
5
|
+
const memoizationMiddleware = ({ memoizedCache }) => {
|
|
5
6
|
return async (ctx, next) => {
|
|
6
7
|
var _a;
|
|
7
|
-
if (!cache_1.isLocallyCacheable(ctx.config, cache_1.CacheType.Any) || !ctx.config.memoizable) {
|
|
8
|
+
if (!(0, cache_1.isLocallyCacheable)(ctx.config, cache_1.CacheType.Any) || !ctx.config.memoizable) {
|
|
8
9
|
return next();
|
|
9
10
|
}
|
|
10
11
|
const span = (_a = ctx.tracing) === null || _a === void 0 ? void 0 : _a.rootSpan;
|
|
11
|
-
const key = cache_1.cacheKey(ctx.config);
|
|
12
|
+
const key = (0, cache_1.cacheKey)(ctx.config);
|
|
12
13
|
const isMemoized = !!memoizedCache.has(key);
|
|
13
|
-
span === null || span === void 0 ? void 0 : span.log({ event: "cache-key-created" /* CACHE_KEY_CREATE */, ["cache-type" /* CACHE_TYPE */]: 'memoization', ["key" /* KEY */]: key });
|
|
14
|
+
span === null || span === void 0 ? void 0 : span.log({ event: "cache-key-created" /* HttpLogEvents.CACHE_KEY_CREATE */, ["cache-type" /* HttpCacheLogFields.CACHE_TYPE */]: 'memoization', ["key" /* HttpCacheLogFields.KEY */]: key });
|
|
14
15
|
if (isMemoized) {
|
|
15
|
-
span === null || span === void 0 ? void 0 : span.setTag("http.cache.memoization" /* HTTP_MEMOIZATION_CACHE_RESULT */, "HIT" /* HIT */);
|
|
16
|
+
span === null || span === void 0 ? void 0 : span.setTag("http.cache.memoization" /* CustomHttpTags.HTTP_MEMOIZATION_CACHE_RESULT */, "HIT" /* CacheResult.HIT */);
|
|
16
17
|
const memoized = await memoizedCache.get(key);
|
|
17
18
|
ctx.memoizedHit = isMemoized;
|
|
18
19
|
ctx.response = memoized.response;
|
|
19
20
|
return;
|
|
20
21
|
}
|
|
21
22
|
else {
|
|
22
|
-
span === null || span === void 0 ? void 0 : span.setTag("http.cache.memoization" /* HTTP_MEMOIZATION_CACHE_RESULT */, "MISS" /* MISS */);
|
|
23
|
+
span === null || span === void 0 ? void 0 : span.setTag("http.cache.memoization" /* CustomHttpTags.HTTP_MEMOIZATION_CACHE_RESULT */, "MISS" /* CacheResult.MISS */);
|
|
23
24
|
const promise = new Promise(async (resolve, reject) => {
|
|
24
25
|
try {
|
|
25
26
|
await next();
|
|
@@ -27,11 +28,11 @@ exports.memoizationMiddleware = ({ memoizedCache }) => {
|
|
|
27
28
|
cacheHit: ctx.cacheHit,
|
|
28
29
|
response: ctx.response,
|
|
29
30
|
});
|
|
30
|
-
span === null || span === void 0 ? void 0 : span.log({ event: "memoization-cache-saved" /* MEMOIZATION_CACHE_SAVED */, ["key-set" /* KEY_SET */]: key });
|
|
31
|
+
span === null || span === void 0 ? void 0 : span.log({ event: "memoization-cache-saved" /* HttpLogEvents.MEMOIZATION_CACHE_SAVED */, ["key-set" /* HttpCacheLogFields.KEY_SET */]: key });
|
|
31
32
|
}
|
|
32
33
|
catch (err) {
|
|
33
34
|
reject(err);
|
|
34
|
-
span === null || span === void 0 ? void 0 : span.log({ event: "memoization-cache-saved-error" /* MEMOIZATION_CACHE_SAVED_ERROR */, ["key-set" /* KEY_SET */]: key });
|
|
35
|
+
span === null || span === void 0 ? void 0 : span.log({ event: "memoization-cache-saved-error" /* HttpLogEvents.MEMOIZATION_CACHE_SAVED_ERROR */, ["key-set" /* HttpCacheLogFields.KEY_SET */]: key });
|
|
35
36
|
}
|
|
36
37
|
});
|
|
37
38
|
memoizedCache.set(key, promise);
|
|
@@ -39,3 +40,4 @@ exports.memoizationMiddleware = ({ memoizedCache }) => {
|
|
|
39
40
|
}
|
|
40
41
|
};
|
|
41
42
|
};
|
|
43
|
+
exports.memoizationMiddleware = memoizationMiddleware;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.metricsMiddleware = void 0;
|
|
3
4
|
const RequestCancelledError_1 = require("../../errors/RequestCancelledError");
|
|
4
5
|
const requestStats_1 = require("../../service/worker/runtime/http/middlewares/requestStats");
|
|
5
6
|
const utils_1 = require("../../utils");
|
|
6
7
|
const retry_1 = require("../../utils/retry");
|
|
7
8
|
const status_1 = require("../../utils/status");
|
|
8
|
-
|
|
9
|
+
const axios_1 = require("axios");
|
|
10
|
+
const metricsMiddleware = ({ metrics, serverTiming, name }) => {
|
|
9
11
|
const serverTimingStart = process.hrtime();
|
|
10
|
-
const serverTimingLabel = utils_1.shrinkTimings(utils_1.formatTimingName({
|
|
12
|
+
const serverTimingLabel = (0, utils_1.shrinkTimings)((0, utils_1.formatTimingName)({
|
|
11
13
|
hopNumber: 0,
|
|
12
14
|
source: process.env.VTEX_APP_NAME,
|
|
13
15
|
target: name || 'unknown',
|
|
@@ -23,10 +25,13 @@ exports.metricsMiddleware = ({ metrics, serverTiming, name }) => {
|
|
|
23
25
|
}
|
|
24
26
|
await next();
|
|
25
27
|
if (ctx.config.metric && ctx.response && ctx.response.status) {
|
|
26
|
-
status = status_1.statusLabel(ctx.response.status);
|
|
28
|
+
status = (0, status_1.statusLabel)(ctx.response.status);
|
|
27
29
|
}
|
|
28
30
|
}
|
|
29
31
|
catch (err) {
|
|
32
|
+
if (!(err instanceof axios_1.AxiosError)) {
|
|
33
|
+
throw err;
|
|
34
|
+
}
|
|
30
35
|
const isCancelled = (err.message === requestStats_1.cancelMessage);
|
|
31
36
|
if (ctx.config.metric) {
|
|
32
37
|
errorCode = err.code;
|
|
@@ -38,7 +43,7 @@ exports.metricsMiddleware = ({ metrics, serverTiming, name }) => {
|
|
|
38
43
|
status = 'timeout';
|
|
39
44
|
}
|
|
40
45
|
else if (err.response && err.response.status) {
|
|
41
|
-
status = status_1.statusLabel(err.response.status);
|
|
46
|
+
status = (0, status_1.statusLabel)(err.response.status);
|
|
42
47
|
}
|
|
43
48
|
else if (isCancelled) {
|
|
44
49
|
status = 'cancelled';
|
|
@@ -84,9 +89,9 @@ exports.metricsMiddleware = ({ metrics, serverTiming, name }) => {
|
|
|
84
89
|
...extensions,
|
|
85
90
|
...errorCode || errorStatus ? { errorCode, errorStatus } : null,
|
|
86
91
|
millis: end
|
|
87
|
-
? utils_1.hrToMillis(end)
|
|
92
|
+
? (0, utils_1.hrToMillis)(end)
|
|
88
93
|
: extensions.revalidated || extensions.router || status !== 'success'
|
|
89
|
-
? utils_1.hrToMillis(process.hrtime(start))
|
|
94
|
+
? (0, utils_1.hrToMillis)(process.hrtime(start))
|
|
90
95
|
: '(from cache)',
|
|
91
96
|
status: ctx.response && ctx.response.status,
|
|
92
97
|
headers: ctx.response && ctx.response.headers,
|
|
@@ -100,7 +105,7 @@ exports.metricsMiddleware = ({ metrics, serverTiming, name }) => {
|
|
|
100
105
|
}
|
|
101
106
|
if (serverTiming) {
|
|
102
107
|
// Timings in the client's perspective
|
|
103
|
-
const dur = utils_1.hrToMillis(process.hrtime(serverTimingStart));
|
|
108
|
+
const dur = (0, utils_1.hrToMillis)(process.hrtime(serverTimingStart));
|
|
104
109
|
if (!serverTiming[serverTimingLabel] || Number(serverTiming[serverTimingLabel]) < dur) {
|
|
105
110
|
serverTiming[serverTimingLabel] = `${dur}`;
|
|
106
111
|
}
|
|
@@ -108,3 +113,4 @@ exports.metricsMiddleware = ({ metrics, serverTiming, name }) => {
|
|
|
108
113
|
}
|
|
109
114
|
};
|
|
110
115
|
};
|
|
116
|
+
exports.metricsMiddleware = metricsMiddleware;
|
|
@@ -2,6 +2,6 @@ import { AxiosRequestConfig } from 'axios';
|
|
|
2
2
|
import { MiddlewareContext } from '../typings';
|
|
3
3
|
export declare const acceptNotFoundMiddleware: (ctx: MiddlewareContext, next: () => Promise<void>) => Promise<void>;
|
|
4
4
|
export declare const notFoundFallbackMiddleware: (ctx: MiddlewareContext, next: () => Promise<void>) => Promise<void>;
|
|
5
|
-
export
|
|
5
|
+
export type IgnoreNotFoundRequestConfig = AxiosRequestConfig & {
|
|
6
6
|
nullIfNotFound?: boolean;
|
|
7
7
|
};
|