@valiron/crawler-protection 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +217 -2
  2. package/dist/adapters.d.ts +29 -0
  3. package/dist/adapters.js +69 -0
  4. package/dist/admission.d.ts +62 -0
  5. package/dist/admission.js +188 -0
  6. package/dist/cache.d.ts +42 -0
  7. package/dist/cache.js +130 -0
  8. package/dist/configuration.d.ts +54 -0
  9. package/dist/configuration.js +223 -0
  10. package/dist/directory.d.ts +36 -0
  11. package/dist/directory.js +155 -0
  12. package/dist/gateway.d.ts +31 -0
  13. package/dist/gateway.js +341 -0
  14. package/dist/guard.d.ts +108 -0
  15. package/dist/guard.js +278 -0
  16. package/dist/index.d.ts +16 -0
  17. package/dist/index.js +32 -0
  18. package/dist/internal.d.ts +29 -0
  19. package/dist/internal.js +50 -0
  20. package/dist/ip.d.ts +18 -0
  21. package/dist/ip.js +81 -0
  22. package/dist/meta.d.ts +13 -0
  23. package/dist/meta.js +34 -0
  24. package/dist/onboarding.d.ts +56 -0
  25. package/dist/onboarding.js +60 -0
  26. package/dist/operations.d.ts +60 -0
  27. package/dist/operations.js +149 -0
  28. package/dist/reporting.d.ts +44 -0
  29. package/dist/reporting.js +72 -0
  30. package/dist/runtime.d.ts +44 -0
  31. package/dist/runtime.js +66 -0
  32. package/dist/telemetry.d.ts +16 -0
  33. package/dist/telemetry.js +61 -0
  34. package/dist/verification.d.ts +113 -0
  35. package/dist/verification.js +238 -0
  36. package/gateway/Dockerfile +21 -0
  37. package/gateway/README.md +107 -0
  38. package/gateway/admin.cjs +34 -0
  39. package/gateway/compose.yaml +40 -0
  40. package/gateway/directory.cjs +10 -0
  41. package/gateway/service.cjs +91 -0
  42. package/gateway/work-api.openapi.json +186 -0
  43. package/integrations/python/valiron_crawler_protection.py +90 -0
  44. package/package.json +57 -4
@@ -0,0 +1,341 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createCrawlerGateway = createCrawlerGateway;
4
+ exports.createCrawlerWorkServer = createCrawlerWorkServer;
5
+ exports.authenticateGatewayOrigin = authenticateGatewayOrigin;
6
+ const node_http_1 = require("node:http");
7
+ const node_https_1 = require("node:https");
8
+ const node_crypto_1 = require("node:crypto");
9
+ const ip_1 = require("./ip");
10
+ const admission_1 = require("./admission");
11
+ const adapters_1 = require("./adapters");
12
+ const operations_1 = require("./operations");
13
+ const hopByHop = new Set(['connection', 'keep-alive', 'proxy-authenticate', 'proxy-authorization', 'proxy-connection', 'te', 'trailer', 'transfer-encoding', 'upgrade']);
14
+ function cleanHeaders(headers) {
15
+ const nominated = new Set((headers.connection ?? '').toLowerCase().split(',').map(v => v.trim()));
16
+ return Object.fromEntries(Object.entries(headers).filter(([name]) => !hopByHop.has(name) && !nominated.has(name) &&
17
+ !name.startsWith('x-valiron-') && !name.startsWith('x-forwarded-') && !name.startsWith('x-amzn-waf-') &&
18
+ !['forwarded', 'x-real-ip', 'client-ip', 'true-client-ip', 'cf-connecting-ip', 'fastly-client-ip', 'host', 'expect'].includes(name)));
19
+ }
20
+ function secret(value) {
21
+ if (typeof value !== 'string' || Buffer.byteLength(value) < 32 || value.length > 1024 || /[\r\n]/.test(value))
22
+ throw new Error('A private 32+ byte secret is required');
23
+ return Buffer.from(value);
24
+ }
25
+ function equal(supplied, expected) {
26
+ const actual = typeof supplied === 'string' ? Buffer.from(supplied) : Buffer.alloc(0);
27
+ return actual.length === expected.length && (0, node_crypto_1.timingSafeEqual)(actual, expected);
28
+ }
29
+ function fail(response, status, code) {
30
+ if (response.destroyed || response.writableEnded)
31
+ return;
32
+ if (response.headersSent) {
33
+ response.destroy();
34
+ return;
35
+ }
36
+ response.writeHead(status, { 'Content-Type': 'application/json', 'Cache-Control': 'no-store' });
37
+ response.end(JSON.stringify({ code }));
38
+ }
39
+ /** Fixed-origin HTTP reverse proxy. The origin's language/framework is not involved in admission. */
40
+ function createCrawlerGateway(input) {
41
+ const origin = new URL(input.origin);
42
+ secret(input.originSecret);
43
+ if (!['http:', 'https:'].includes(origin.protocol) || origin.username || origin.password || origin.pathname !== '/' || origin.search || origin.hash)
44
+ throw new Error('A fixed HTTP(S) origin without a path is required');
45
+ if (!input.publicHosts.length || input.publicHosts.some(h => !/^[a-zA-Z0-9.:[\]-]+$/.test(h) || h.length > 255))
46
+ throw new Error('Explicit public hosts required');
47
+ const hosts = new Set(input.publicHosts.map(h => h.toLowerCase()));
48
+ const maxBody = input.maxBodyBytes ?? 8 * 1024 * 1024;
49
+ const timeout = input.upstreamTimeoutMs ?? 30000;
50
+ const maxConnections = input.maxConnections ?? 256;
51
+ if (!Number.isSafeInteger(maxBody) || maxBody < 1 || maxBody > 1024 * 1024 * 1024 || !Number.isSafeInteger(timeout) || timeout < 1 || timeout > 300000 ||
52
+ !Number.isSafeInteger(maxConnections) || maxConnections < 1 || maxConnections > 10000)
53
+ throw new Error('Invalid gateway bounds');
54
+ const runtime = input.runtime;
55
+ const policy = runtime.compiled.policy;
56
+ let active = 0;
57
+ let bufferedBytes = 0;
58
+ const bufferCeiling = Math.max(maxBody, 32 * 1024 * 1024);
59
+ const server = (0, node_http_1.createServer)({ maxHeaderSize: 32768, requestTimeout: timeout, headersTimeout: Math.min(timeout, 10000) }, (request, response) => {
60
+ request.on('error', () => { });
61
+ response.on('error', () => response.destroy());
62
+ if (active >= maxConnections) {
63
+ fail(response, 503, 'GATEWAY_BUSY');
64
+ return;
65
+ }
66
+ active++;
67
+ let done = false;
68
+ let reservedBytes = 0;
69
+ const releaseBuffer = () => { bufferedBytes -= reservedBytes; reservedBytes = 0; };
70
+ const finish = () => { if (!done) {
71
+ done = true;
72
+ releaseBuffer();
73
+ active--;
74
+ } };
75
+ void (async () => {
76
+ const host = request.headers.host?.toLowerCase();
77
+ if (!host || !hosts.has(host) || !request.url?.startsWith('/') || request.url.startsWith('//') || request.headers.upgrade || request.method === 'CONNECT') {
78
+ fail(response, 400, 'INVALID_GATEWAY_REQUEST');
79
+ finish();
80
+ return;
81
+ }
82
+ const length = request.headers['content-length'];
83
+ if (length && (!/^\d+$/.test(length) || Number(length) > maxBody)) {
84
+ fail(response, 413, 'REQUEST_TOO_LARGE');
85
+ finish();
86
+ return;
87
+ }
88
+ let ip;
89
+ try {
90
+ ip = (0, ip_1.normalizeIp)(input.clientIp(request));
91
+ }
92
+ catch {
93
+ fail(response, 503, 'UNTRUSTED_INGRESS');
94
+ finish();
95
+ return;
96
+ }
97
+ // Finish bounded uploads before acquiring an origin hold. A slow/aborted viewer
98
+ // must never strand capacity for work that has not even been sent to the origin.
99
+ const payload = await new Promise((resolve, reject) => {
100
+ const chunks = [];
101
+ const cleanup = () => { clearTimeout(readTimer); request.off('data', data); request.off('end', ended); request.off('error', errored); request.off('aborted', aborted); };
102
+ const rejectBody = (code) => { cleanup(); request.resume(); reject(new Error(code)); };
103
+ const data = (chunk) => {
104
+ if (reservedBytes + chunk.length > maxBody) {
105
+ rejectBody('REQUEST_TOO_LARGE');
106
+ return;
107
+ }
108
+ if (bufferedBytes + chunk.length > bufferCeiling) {
109
+ rejectBody('GATEWAY_BODY_BUSY');
110
+ return;
111
+ }
112
+ reservedBytes += chunk.length;
113
+ bufferedBytes += chunk.length;
114
+ chunks.push(chunk);
115
+ };
116
+ const ended = () => { cleanup(); resolve(Buffer.concat(chunks)); };
117
+ const errored = () => rejectBody('INCOMPLETE_REQUEST');
118
+ const aborted = () => rejectBody('INCOMPLETE_REQUEST');
119
+ const readTimer = setTimeout(() => rejectBody('REQUEST_BODY_TIMEOUT'), timeout);
120
+ request.on('data', data);
121
+ request.once('end', ended);
122
+ request.once('error', errored);
123
+ request.once('aborted', aborted);
124
+ });
125
+ await new Promise((resolve, reject) => {
126
+ const closed = () => resolve();
127
+ response.once('finish', closed);
128
+ response.once('close', closed);
129
+ runtime.nodeMiddleware(request, response, error => {
130
+ response.off('finish', closed);
131
+ response.off('close', closed);
132
+ if (error)
133
+ reject(error);
134
+ else
135
+ resolve();
136
+ });
137
+ });
138
+ if (response.writableEnded || response.destroyed) {
139
+ finish();
140
+ return;
141
+ }
142
+ const context = request.valironCrawler;
143
+ let permit;
144
+ if (context) {
145
+ const slots = [{ key: 'gateway:global', limit: policy.globalWorkLimit }];
146
+ if (policy.customers) {
147
+ if (context.lane !== 'checkout')
148
+ slots.push({ key: 'gateway:non-checkout', limit: policy.globalWorkLimit - policy.customers.checkoutReserve });
149
+ if (context.lane !== 'checkout' && context.lane !== 'shopper')
150
+ slots.push({ key: 'gateway:catalog', limit: policy.globalWorkLimit - policy.customers.checkoutReserve - policy.customers.shopperReserve });
151
+ }
152
+ if (context.lane === 'catalog') {
153
+ const evidence = context.evidence;
154
+ const verified = evidence.state === 'verified' && Boolean(policy.providers[evidence.provider]?.classes[evidence.crawlerClass]);
155
+ slots.push(verified ? { key: 'gateway:provider:' + evidence.provider, limit: policy.providerWorkLimit } : { key: 'gateway:unknown', limit: policy.unknownWorkLimit });
156
+ }
157
+ permit = await runtime.store.acquirePermit(slots, { requestId: context.requestId, lane: context.lane === 'catalog' ? 'gateway' : context.lane });
158
+ if (!permit) {
159
+ runtime.report.gateway(context.routeGroup, 'rejected');
160
+ fail(response, 503, 'ORIGIN_CAPACITY_EXHAUSTED');
161
+ finish();
162
+ return;
163
+ }
164
+ }
165
+ if (context)
166
+ runtime.report.gateway(context.routeGroup, 'admitted');
167
+ const headers = cleanHeaders(request.headers);
168
+ headers.host = host;
169
+ headers['x-forwarded-host'] = host;
170
+ headers['x-forwarded-for'] = ip;
171
+ headers['content-length'] = String(payload.length);
172
+ headers['x-forwarded-proto'] = input.publicProtocol ?? 'https';
173
+ headers['x-valiron-origin-auth'] = input.originSecret;
174
+ if (context && input.requestChannel)
175
+ headers['x-valiron-request-token'] = runtime.guard.forward(context, input.requestChannel, { method: request.method, path: request.url });
176
+ const orphan = (reason) => {
177
+ if (permit) {
178
+ runtime.report.gateway(context.routeGroup, 'orphan');
179
+ try {
180
+ input.onOrphan?.({ requestId: context.requestId, reason });
181
+ }
182
+ catch { /* reporting must not release uncertain work */ }
183
+ }
184
+ };
185
+ // Use a fixed hostname and an origin-form path, never resolve a viewer-supplied URL.
186
+ const upstream = (origin.protocol === 'https:' ? node_https_1.request : node_http_1.request)({ protocol: origin.protocol, hostname: origin.hostname.replace(/^\[|\]$/g, ''),
187
+ port: origin.port || undefined, method: request.method, path: request.url, headers, agent: false });
188
+ upstream.once('finish', releaseBuffer);
189
+ let settled = false;
190
+ const failed = (reason, status = 502) => {
191
+ if (settled)
192
+ return;
193
+ settled = true;
194
+ clearTimeout(timer);
195
+ orphan(reason);
196
+ upstream.destroy();
197
+ fail(response, status, reason);
198
+ request.resume();
199
+ finish();
200
+ };
201
+ const timer = setTimeout(() => failed('ORIGIN_TIMEOUT', 504), timeout);
202
+ upstream.on('error', () => failed('ORIGIN_CONNECTION_FAILED'));
203
+ upstream.once('response', originResponse => {
204
+ const forwarded = cleanHeaders(originResponse.headers);
205
+ if (!response.destroyed)
206
+ response.writeHead(originResponse.statusCode ?? 502, forwarded);
207
+ // Continue draining the origin after a viewer disconnect. Disconnect never releases a hold.
208
+ originResponse.on('data', chunk => {
209
+ if (!settled && !response.destroyed && !response.writableEnded && !response.write(chunk))
210
+ originResponse.pause();
211
+ });
212
+ response.on('drain', () => originResponse.resume());
213
+ response.on('close', () => originResponse.resume());
214
+ originResponse.once('error', () => failed('INCOMPLETE_ORIGIN_RESPONSE'));
215
+ originResponse.once('aborted', () => failed('INCOMPLETE_ORIGIN_RESPONSE'));
216
+ originResponse.once('end', () => {
217
+ if (settled)
218
+ return;
219
+ if (!originResponse.complete || !upstream.writableFinished || !request.complete) {
220
+ failed('INCOMPLETE_ORIGIN_RESPONSE');
221
+ return;
222
+ }
223
+ settled = true;
224
+ clearTimeout(timer);
225
+ // This bounds completed HTTP work only. DB/background work requires operation admission.
226
+ if (context)
227
+ runtime.report.gateway(context.routeGroup, 'completed');
228
+ void (permit ? runtime.store.releasePermit(permit) : Promise.resolve()).catch(() => orphan('ORIGIN_RELEASE_FAILED')).finally(() => {
229
+ response.end();
230
+ finish();
231
+ });
232
+ });
233
+ });
234
+ upstream.end(payload);
235
+ })().catch(error => {
236
+ if (error instanceof admission_1.AdmissionError)
237
+ (0, adapters_1.sendDenial)(response, error.decision);
238
+ else {
239
+ const status = { REQUEST_TOO_LARGE: 413, GATEWAY_BODY_BUSY: 503, INCOMPLETE_REQUEST: 400, REQUEST_BODY_TIMEOUT: 408 };
240
+ const code = error instanceof Error && Object.hasOwn(status, error.message) ? error.message : 'GATEWAY_UNAVAILABLE';
241
+ fail(response, status[code] ?? 503, code);
242
+ }
243
+ finish();
244
+ });
245
+ });
246
+ server.maxConnections = maxConnections;
247
+ server.on('connect', (_request, socket) => socket.destroy());
248
+ server.on('upgrade', (_request, socket) => socket.end('HTTP/1.1 426 Upgrade Required\r\nConnection: close\r\n\r\n'));
249
+ server.on('checkContinue', (request, response) => { fail(response, 417, 'EXPECT_NOT_SUPPORTED'); });
250
+ return server;
251
+ }
252
+ /** Private language-neutral operation admission. Deploy on a private listener, never route through the public gateway. */
253
+ function createCrawlerWorkServer(input) {
254
+ const auth = Buffer.concat([Buffer.from('Bearer '), secret(input.apiSecret)]);
255
+ const runtime = input.runtime;
256
+ const policy = (0, operations_1.policyFingerprint)(runtime.compiled.policy);
257
+ const server = (0, node_http_1.createServer)({ maxHeaderSize: 16384, requestTimeout: 5000, headersTimeout: 5000 }, (request, response) => {
258
+ void (async () => {
259
+ if (!equal(request.headers.authorization, auth)) {
260
+ fail(response, 401, 'AUTHENTICATION_REQUIRED');
261
+ return;
262
+ }
263
+ if (request.method !== 'POST' || !['/v1/work/acquire', '/v1/work/release'].includes(request.url ?? '')) {
264
+ fail(response, 404, 'NOT_FOUND');
265
+ return;
266
+ }
267
+ if (!/^application\/json(?:;|$)/i.test(request.headers['content-type'] ?? '')) {
268
+ fail(response, 415, 'JSON_REQUIRED');
269
+ return;
270
+ }
271
+ const chunks = [];
272
+ let size = 0;
273
+ for await (const chunk of request) {
274
+ size += chunk.length;
275
+ if (size > 16384) {
276
+ fail(response, 413, 'REQUEST_TOO_LARGE');
277
+ return;
278
+ }
279
+ chunks.push(chunk);
280
+ }
281
+ let body;
282
+ try {
283
+ body = JSON.parse(Buffer.concat(chunks).toString());
284
+ if (!body || Array.isArray(body) || typeof body !== 'object')
285
+ throw Error();
286
+ }
287
+ catch {
288
+ fail(response, 400, 'INVALID_JSON');
289
+ return;
290
+ }
291
+ let result;
292
+ if (request.url === '/v1/work/acquire') {
293
+ if (Object.keys(body).some(k => !['requestToken', 'method', 'path'].includes(k))) {
294
+ fail(response, 400, 'INVALID_FIELDS');
295
+ return;
296
+ }
297
+ let claims;
298
+ try {
299
+ claims = input.channel.verify(body.requestToken, { method: body.method, path: body.path }, policy);
300
+ }
301
+ catch {
302
+ fail(response, 403, 'INVALID_REQUEST_CAPABILITY');
303
+ return;
304
+ }
305
+ // Generate a unique child; Redis atomically applies the parent's total fanout across all broker replicas.
306
+ const target = { method: 'POST', path: '/v1/work/acquire' };
307
+ const child = input.channel.sign(claims.context, policy, target);
308
+ const context = runtime.guard.acceptInternal(child, input.channel, target);
309
+ try {
310
+ result = { permit: await runtime.guard.acquireRemoteDatabaseAdmission(context) };
311
+ runtime.report.databasePermit(context.routeGroup, 'admitted');
312
+ }
313
+ catch (error) {
314
+ runtime.report.databasePermit(context.routeGroup, 'rejected');
315
+ throw error;
316
+ }
317
+ }
318
+ else {
319
+ if (body.settled !== true || Object.keys(body).some(k => !['permit', 'settled'].includes(k))) {
320
+ fail(response, 400, 'SETTLEMENT_REQUIRED');
321
+ return;
322
+ }
323
+ await runtime.store.releasePermit(body.permit);
324
+ result = { released: true };
325
+ }
326
+ response.writeHead(200, { 'Content-Type': 'application/json', 'Cache-Control': 'no-store' });
327
+ response.end(JSON.stringify(result));
328
+ })().catch(error => {
329
+ if (error instanceof admission_1.AdmissionError)
330
+ (0, adapters_1.sendDenial)(response, error.decision);
331
+ else
332
+ fail(response, 503, 'WORK_ADMISSION_UNAVAILABLE');
333
+ });
334
+ });
335
+ server.maxConnections = input.maxConnections ?? 128;
336
+ return server;
337
+ }
338
+ /** Origin middleware can compare this header in any language; network-restrict the origin as well. */
339
+ function authenticateGatewayOrigin(request, originSecret) {
340
+ return equal(request.headers['x-valiron-origin-auth'], secret(originSecret));
341
+ }
@@ -0,0 +1,108 @@
1
+ import { InternalAdmission, type InternalTarget } from './internal';
2
+ import { BingVerifier, CrawlerRegistry, type CrawlerEvidence } from './verification';
3
+ import { RedisAdmission, type Decision, type WorkPermit } from './admission';
4
+ type Rate = Readonly<{
5
+ capacity: number;
6
+ refillPerSecond: number;
7
+ }>;
8
+ export type GuardPolicy = Readonly<{
9
+ version: string;
10
+ expiresAt: number;
11
+ /** Binds the full compiled deployment configuration to managed policy activation. */
12
+ configurationId?: string;
13
+ rollout?: Readonly<{
14
+ mode: 'observe' | 'enforce';
15
+ enforceGroups: readonly string[];
16
+ safetyRate: Rate;
17
+ safetyPerIpRate: Rate;
18
+ }>;
19
+ globalRate: Rate;
20
+ unknownRate: Rate;
21
+ perIpRate: Rate;
22
+ providers: Readonly<Record<string, Readonly<{
23
+ rate: Rate;
24
+ classes: Readonly<Record<string, Rate>>;
25
+ }>>>;
26
+ globalWorkLimit: number;
27
+ unknownWorkLimit: number;
28
+ providerWorkLimit: number;
29
+ localWorkLimit: number;
30
+ /** Reserved capacity is usable only by a server-validated customer flow. */
31
+ customers?: Readonly<{
32
+ shopperReserve: number;
33
+ checkoutReserve: number;
34
+ shopperRate: Rate;
35
+ checkoutRate: Rate;
36
+ }>;
37
+ maxOperationsPerRequest: number;
38
+ maxContextAgeMs: number;
39
+ routes: Readonly<Record<string, Readonly<{
40
+ cost: number;
41
+ rate: Rate;
42
+ customerLane?: 'checkout';
43
+ }>>>;
44
+ }>;
45
+ export type RequestContext = Readonly<{
46
+ ip: string;
47
+ routeGroup: string;
48
+ cost: number;
49
+ requestId: string;
50
+ evidence: CrawlerEvidence;
51
+ expiresAt: number;
52
+ lane?: 'catalog' | 'shopper' | 'checkout';
53
+ principal?: string;
54
+ }>;
55
+ export type DecisionDetails = Readonly<{
56
+ routeGroup?: string;
57
+ lane?: string;
58
+ mode?: 'observe' | 'enforce';
59
+ proposedAction?: Decision['action'];
60
+ }>;
61
+ export type AdmissionResult = {
62
+ decision: Decision;
63
+ context?: RequestContext;
64
+ };
65
+ /** Shared runtime validation used by the guard and configuration compiler. */
66
+ export declare function validateGuardPolicy(p: GuardPolicy): void;
67
+ export declare class CrawlerGuard {
68
+ private readonly config;
69
+ private readonly policy;
70
+ private localWork;
71
+ private localRender;
72
+ private readonly contexts;
73
+ private readonly children;
74
+ private readonly operations;
75
+ constructor(config: {
76
+ policy: GuardPolicy;
77
+ registry: CrawlerRegistry;
78
+ bing: BingVerifier;
79
+ store: RedisAdmission;
80
+ now?: () => number;
81
+ /** Must validate a real server-side session/cart/checkout grant. No UA or cookie presence shortcuts. */
82
+ customer?: (request: unknown, routeGroup: string) => Promise<{
83
+ lane: 'shopper' | 'checkout';
84
+ principal: string;
85
+ } | undefined>;
86
+ trustedEvidence?: (request: unknown, ip: string, userAgent: string) => CrawlerEvidence | undefined;
87
+ crawlerAccess?: (evidence: CrawlerEvidence, routeGroup: string) => 'budget' | 'deny';
88
+ onDecision?: (decision: Readonly<Decision>, evidence?: CrawlerEvidence, details?: DecisionDetails) => void;
89
+ });
90
+ private now;
91
+ private emit;
92
+ admit(input: {
93
+ ip: string;
94
+ userAgent: string;
95
+ routeGroup: string;
96
+ cost: number;
97
+ request?: unknown;
98
+ }): Promise<AdmissionResult>;
99
+ forward(context: RequestContext, channel: InternalAdmission, target: InternalTarget): string;
100
+ acceptInternal(token: string, channel: InternalAdmission, target: InternalTarget): RequestContext;
101
+ /** Bound SSR separately from DB operations; retain the hold until the render/fetches settle. */
102
+ withRenderingAdmission<T>(context: RequestContext, operation: () => Promise<T>): Promise<T>;
103
+ private databaseSlots;
104
+ /** HTTP work broker: shared Redis caps replace a process-affine callback/local counter. */
105
+ acquireRemoteDatabaseAdmission(context: RequestContext): Promise<WorkPermit>;
106
+ withDatabaseAdmission<T>(context: RequestContext, operation: () => Promise<T>): Promise<T>;
107
+ }
108
+ export {};