@tramvai/module-http-client 6.68.6 → 6.77.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/lib/index.es.js +1 -0
- package/lib/index.js +1 -0
- package/lib/papi/papiService.d.ts +9 -1
- package/lib/papi/papiService.es.js +8 -2
- package/lib/papi/papiService.js +8 -2
- package/lib/papiClientModule.es.js +2 -0
- package/lib/papiClientModule.js +2 -0
- package/lib/test/unit/testApi.d.ts +2 -2
- package/package.json +18 -15
- package/tests.d.ts +2 -2
- package/tests.js +11 -4
package/lib/index.es.js
CHANGED
|
@@ -3,6 +3,7 @@ export { httpClientFactory } from './httpClient/httpClientFactory.es.js';
|
|
|
3
3
|
import '@tramvai/core';
|
|
4
4
|
import '@tramvai/tokens-server';
|
|
5
5
|
export * from '@tramvai/tokens-http-client';
|
|
6
|
+
import '@tramvai/tokens-common';
|
|
6
7
|
export { PapiService } from './papi/papiService.es.js';
|
|
7
8
|
export { fillHeaderIp, fillHeaders } from './utils/fillHeaders.es.js';
|
|
8
9
|
export * from '@tramvai/http-client';
|
package/lib/index.js
CHANGED
|
@@ -7,6 +7,7 @@ var httpClientFactory = require('./httpClient/httpClientFactory.js');
|
|
|
7
7
|
require('@tramvai/core');
|
|
8
8
|
require('@tramvai/tokens-server');
|
|
9
9
|
var tokensHttpClient = require('@tramvai/tokens-http-client');
|
|
10
|
+
require('@tramvai/tokens-common');
|
|
10
11
|
var papiService = require('./papi/papiService.js');
|
|
11
12
|
var fillHeaders = require('./utils/fillHeaders.js');
|
|
12
13
|
var httpClient = require('@tramvai/http-client');
|
|
@@ -3,14 +3,22 @@ import type { HttpClientRequest, HttpClientResponse } from '@tramvai/http-client
|
|
|
3
3
|
import { BaseHttpClient } from '@tramvai/http-client';
|
|
4
4
|
import type { ExtractDependencyType } from '@tinkoff/dippy';
|
|
5
5
|
import type { SERVER_MODULE_PAPI_PUBLIC_ROUTE } from '@tramvai/tokens-server';
|
|
6
|
+
import { ASYNC_LOCAL_STORAGE_TOKEN } from '@tramvai/tokens-common';
|
|
7
|
+
declare module '@tramvai/tokens-common' {
|
|
8
|
+
interface AsyncLocalStorageState {
|
|
9
|
+
tramvaiRequestDi?: ExtractDependencyType<typeof DI_TOKEN>;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
6
12
|
export interface Deps {
|
|
7
13
|
di: ExtractDependencyType<typeof DI_TOKEN>;
|
|
8
14
|
papi: ExtractDependencyType<typeof SERVER_MODULE_PAPI_PUBLIC_ROUTE> | null;
|
|
15
|
+
storage: ExtractDependencyType<typeof ASYNC_LOCAL_STORAGE_TOKEN>;
|
|
9
16
|
}
|
|
10
17
|
export declare class PapiService extends BaseHttpClient {
|
|
11
18
|
papi: Deps['papi'];
|
|
12
19
|
di: Deps['di'];
|
|
13
|
-
|
|
20
|
+
storage: Deps['storage'];
|
|
21
|
+
constructor({ papi, di, storage }: Deps);
|
|
14
22
|
request<R = any>({ path, query, body, headers, }: HttpClientRequest): Promise<HttpClientResponse<R>>;
|
|
15
23
|
}
|
|
16
24
|
//# sourceMappingURL=papiService.d.ts.map
|
|
@@ -12,10 +12,12 @@ import { getPathParams } from '../utils/getPathParams.es.js';
|
|
|
12
12
|
class PapiService extends BaseHttpClient {
|
|
13
13
|
papi;
|
|
14
14
|
di;
|
|
15
|
-
|
|
15
|
+
storage;
|
|
16
|
+
constructor({ papi, di, storage }) {
|
|
16
17
|
super();
|
|
17
18
|
this.papi = flatten(papi || []);
|
|
18
19
|
this.di = di;
|
|
20
|
+
this.storage = storage;
|
|
19
21
|
}
|
|
20
22
|
async request({ path, query, body, headers, }) {
|
|
21
23
|
const pathWithLeadingSlash = path?.startsWith('/') ? path : `/${path}`;
|
|
@@ -42,7 +44,11 @@ class PapiService extends BaseHttpClient {
|
|
|
42
44
|
},
|
|
43
45
|
]);
|
|
44
46
|
const papiExecutor = childDi.get(PAPI_EXECUTOR);
|
|
45
|
-
const payload = await
|
|
47
|
+
const payload = await this.storage.run({
|
|
48
|
+
tramvaiRequestDi: childDi,
|
|
49
|
+
}, () => {
|
|
50
|
+
return papiExecutor(papiRoute);
|
|
51
|
+
});
|
|
46
52
|
return { payload, status: 200, headers: {} };
|
|
47
53
|
}
|
|
48
54
|
}
|
package/lib/papi/papiService.js
CHANGED
|
@@ -21,10 +21,12 @@ var flatten__default = /*#__PURE__*/_interopDefaultLegacy(flatten);
|
|
|
21
21
|
class PapiService extends httpClient.BaseHttpClient {
|
|
22
22
|
papi;
|
|
23
23
|
di;
|
|
24
|
-
|
|
24
|
+
storage;
|
|
25
|
+
constructor({ papi, di, storage }) {
|
|
25
26
|
super();
|
|
26
27
|
this.papi = flatten__default["default"](papi || []);
|
|
27
28
|
this.di = di;
|
|
29
|
+
this.storage = storage;
|
|
28
30
|
}
|
|
29
31
|
async request({ path, query, body, headers, }) {
|
|
30
32
|
const pathWithLeadingSlash = path?.startsWith('/') ? path : `/${path}`;
|
|
@@ -51,7 +53,11 @@ class PapiService extends httpClient.BaseHttpClient {
|
|
|
51
53
|
},
|
|
52
54
|
]);
|
|
53
55
|
const papiExecutor = childDi.get(tokensServerPrivate.PAPI_EXECUTOR);
|
|
54
|
-
const payload = await
|
|
56
|
+
const payload = await this.storage.run({
|
|
57
|
+
tramvaiRequestDi: childDi,
|
|
58
|
+
}, () => {
|
|
59
|
+
return papiExecutor(papiRoute);
|
|
60
|
+
});
|
|
55
61
|
return { payload, status: 200, headers: {} };
|
|
56
62
|
}
|
|
57
63
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Module, provide, Scope, DI_TOKEN } from '@tramvai/core';
|
|
2
2
|
import { SERVER_MODULE_PAPI_PUBLIC_ROUTE } from '@tramvai/tokens-server';
|
|
3
3
|
import { PAPI_SERVICE } from '@tramvai/tokens-http-client';
|
|
4
|
+
import { ASYNC_LOCAL_STORAGE_TOKEN } from '@tramvai/tokens-common';
|
|
4
5
|
import { PapiService } from './papi/papiService.es.js';
|
|
5
6
|
export { PapiService } from './papi/papiService.es.js';
|
|
6
7
|
|
|
@@ -13,6 +14,7 @@ const PapiClientModule = /* @__PURE__ */ Module({
|
|
|
13
14
|
deps: {
|
|
14
15
|
di: DI_TOKEN,
|
|
15
16
|
papi: { token: SERVER_MODULE_PAPI_PUBLIC_ROUTE, optional: true },
|
|
17
|
+
storage: ASYNC_LOCAL_STORAGE_TOKEN,
|
|
16
18
|
},
|
|
17
19
|
}),
|
|
18
20
|
],
|
package/lib/papiClientModule.js
CHANGED
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var core = require('@tramvai/core');
|
|
6
6
|
var tokensServer = require('@tramvai/tokens-server');
|
|
7
7
|
var tokensHttpClient = require('@tramvai/tokens-http-client');
|
|
8
|
+
var tokensCommon = require('@tramvai/tokens-common');
|
|
8
9
|
var papiService = require('./papi/papiService.js');
|
|
9
10
|
|
|
10
11
|
const PapiClientModule = /* @__PURE__ */ core.Module({
|
|
@@ -16,6 +17,7 @@ const PapiClientModule = /* @__PURE__ */ core.Module({
|
|
|
16
17
|
deps: {
|
|
17
18
|
di: core.DI_TOKEN,
|
|
18
19
|
papi: { token: tokensServer.SERVER_MODULE_PAPI_PUBLIC_ROUTE, optional: true },
|
|
20
|
+
storage: tokensCommon.ASYNC_LOCAL_STORAGE_TOKEN,
|
|
19
21
|
},
|
|
20
22
|
}),
|
|
21
23
|
],
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
/// <reference types="jest" />
|
|
2
1
|
import { getDiWrapper } from '@tramvai/test-helpers';
|
|
3
2
|
import type { createMockEnvManager } from '@tramvai/test-mocks';
|
|
3
|
+
import type { Mock } from 'jest-mock';
|
|
4
4
|
type Options = Parameters<typeof getDiWrapper>[0] & {
|
|
5
5
|
env?: Parameters<typeof createMockEnvManager>[0];
|
|
6
6
|
};
|
|
7
7
|
export declare const testApi: (options: Options) => {
|
|
8
8
|
di: import("@tinkoff/dippy").Container;
|
|
9
|
-
fetchMock: jest.
|
|
9
|
+
fetchMock: Mock<import("jest-mock").UnknownFunction>;
|
|
10
10
|
mockJsonResponse: (body: Record<string, any>, { status, headers }?: {
|
|
11
11
|
status?: number | undefined;
|
|
12
12
|
headers?: Record<string, string> | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tramvai/module-http-client",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.77.2",
|
|
4
4
|
"initialVersion": "0.58.99",
|
|
5
5
|
"description": "",
|
|
6
6
|
"engines": {
|
|
@@ -28,27 +28,30 @@
|
|
|
28
28
|
"watch": "tsc -w"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@
|
|
32
|
-
"@tramvai/
|
|
33
|
-
"@tramvai/
|
|
34
|
-
"@tramvai/tokens-
|
|
35
|
-
"@tramvai/tokens-
|
|
36
|
-
"@tramvai/tokens-server
|
|
31
|
+
"@jest/globals": "^29.7.0",
|
|
32
|
+
"@tramvai/http-client": "0.6.1",
|
|
33
|
+
"@tramvai/tinkoff-request-http-client-adapter": "0.13.152",
|
|
34
|
+
"@tramvai/tokens-common": "6.77.2",
|
|
35
|
+
"@tramvai/tokens-http-client": "6.77.2",
|
|
36
|
+
"@tramvai/tokens-server": "6.77.2",
|
|
37
|
+
"@tramvai/tokens-server-private": "6.77.2",
|
|
38
|
+
"jest": "^29.7.0",
|
|
37
39
|
"undici": "^7.16.0"
|
|
38
40
|
},
|
|
39
41
|
"devDependencies": {
|
|
40
42
|
"@tinkoff/request-core": "^0.10.0",
|
|
41
|
-
"@tinkoff/request-plugin-protocol-http": "0.
|
|
43
|
+
"@tinkoff/request-plugin-protocol-http": "0.16.0",
|
|
44
|
+
"@tramvai/build": "7.2.1"
|
|
42
45
|
},
|
|
43
46
|
"peerDependencies": {
|
|
44
|
-
"@tinkoff/dippy": "0.12.
|
|
47
|
+
"@tinkoff/dippy": "0.12.6",
|
|
45
48
|
"@tinkoff/utils": "^2.1.2",
|
|
46
|
-
"@tramvai/core": "6.
|
|
47
|
-
"@tramvai/module-common": "6.
|
|
48
|
-
"@tramvai/papi": "6.
|
|
49
|
-
"@tramvai/test-helpers": "6.
|
|
50
|
-
"@tramvai/test-mocks": "6.
|
|
51
|
-
"@tramvai/test-unit": "6.
|
|
49
|
+
"@tramvai/core": "6.77.2",
|
|
50
|
+
"@tramvai/module-common": "6.77.2",
|
|
51
|
+
"@tramvai/papi": "6.77.2",
|
|
52
|
+
"@tramvai/test-helpers": "6.77.2",
|
|
53
|
+
"@tramvai/test-mocks": "6.77.2",
|
|
54
|
+
"@tramvai/test-unit": "6.77.2",
|
|
52
55
|
"tslib": "^2.4.0"
|
|
53
56
|
},
|
|
54
57
|
"license": "Apache-2.0",
|
package/tests.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
/// <reference types="jest" />
|
|
2
1
|
import { getDiWrapper } from "@tramvai/test-helpers";
|
|
3
2
|
import { createMockEnvManager } from "@tramvai/test-mocks";
|
|
3
|
+
import { Mock } from "jest-mock";
|
|
4
4
|
type Options = Parameters<typeof getDiWrapper>[0] & {
|
|
5
5
|
env?: Parameters<typeof createMockEnvManager>[0];
|
|
6
6
|
};
|
|
7
7
|
declare const testApi: (options: Options) => {
|
|
8
8
|
di: import("@tinkoff/dippy").Container;
|
|
9
|
-
fetchMock: jest.
|
|
9
|
+
fetchMock: Mock<import("jest-mock").UnknownFunction>;
|
|
10
10
|
mockJsonResponse: (body: Record<string, any>, { status, headers }?: {
|
|
11
11
|
status?: number | undefined;
|
|
12
12
|
headers?: Record<string, string> | undefined;
|
package/tests.js
CHANGED
|
@@ -7,6 +7,7 @@ var testMocks = require('@tramvai/test-mocks');
|
|
|
7
7
|
var core = require('@tramvai/core');
|
|
8
8
|
var tokensHttpClient = require('@tramvai/tokens-http-client');
|
|
9
9
|
var tokensServer = require('@tramvai/tokens-server');
|
|
10
|
+
var tokensCommon = require('@tramvai/tokens-common');
|
|
10
11
|
var find = require('@tinkoff/utils/array/find');
|
|
11
12
|
var flatten = require('@tinkoff/utils/array/flatten');
|
|
12
13
|
var httpClient = require('@tramvai/http-client');
|
|
@@ -15,10 +16,10 @@ var papi = require('@tramvai/papi');
|
|
|
15
16
|
var tokensServerPrivate = require('@tramvai/tokens-server-private');
|
|
16
17
|
var identity = require('@tinkoff/utils/function/identity');
|
|
17
18
|
var pick = require('@tinkoff/utils/object/pick');
|
|
18
|
-
var tokensCommon = require('@tramvai/tokens-common');
|
|
19
19
|
var isNil = require('@tinkoff/utils/is/nil');
|
|
20
20
|
var compose = require('@tinkoff/utils/function/compose');
|
|
21
21
|
var tinkoffRequestHttpClientAdapter = require('@tramvai/tinkoff-request-http-client-adapter');
|
|
22
|
+
var globals = require('@jest/globals');
|
|
22
23
|
|
|
23
24
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
24
25
|
|
|
@@ -67,10 +68,11 @@ const comparePathWithPattern = (path, pattern) => new RegExp(`^${pattern.replace
|
|
|
67
68
|
const getPathParams = (path, pattern) => path.match(new RegExp(`^${pattern.replace(/:(\w+)/g, '(?<$1>[^\\/]+)')}$`))?.groups ?? {};
|
|
68
69
|
|
|
69
70
|
class PapiService extends httpClient.BaseHttpClient {
|
|
70
|
-
constructor({ papi, di }) {
|
|
71
|
+
constructor({ papi, di, storage }) {
|
|
71
72
|
super();
|
|
72
73
|
this.papi = flatten__default["default"](papi || []);
|
|
73
74
|
this.di = di;
|
|
75
|
+
this.storage = storage;
|
|
74
76
|
}
|
|
75
77
|
async request({ path, query, body, headers, }) {
|
|
76
78
|
const pathWithLeadingSlash = path?.startsWith('/') ? path : `/${path}`;
|
|
@@ -97,7 +99,11 @@ class PapiService extends httpClient.BaseHttpClient {
|
|
|
97
99
|
},
|
|
98
100
|
]);
|
|
99
101
|
const papiExecutor = childDi.get(tokensServerPrivate.PAPI_EXECUTOR);
|
|
100
|
-
const payload = await
|
|
102
|
+
const payload = await this.storage.run({
|
|
103
|
+
tramvaiRequestDi: childDi,
|
|
104
|
+
}, () => {
|
|
105
|
+
return papiExecutor(papiRoute);
|
|
106
|
+
});
|
|
101
107
|
return { payload, status: 200, headers: {} };
|
|
102
108
|
}
|
|
103
109
|
}
|
|
@@ -111,6 +117,7 @@ const PapiClientModule = /* @__PURE__ */ core.Module({
|
|
|
111
117
|
deps: {
|
|
112
118
|
di: core.DI_TOKEN,
|
|
113
119
|
papi: { token: tokensServer.SERVER_MODULE_PAPI_PUBLIC_ROUTE, optional: true },
|
|
120
|
+
storage: tokensCommon.ASYNC_LOCAL_STORAGE_TOKEN,
|
|
114
121
|
},
|
|
115
122
|
}),
|
|
116
123
|
],
|
|
@@ -359,7 +366,7 @@ const HttpClientModule = /* @__PURE__ */ core.declareModule({
|
|
|
359
366
|
],
|
|
360
367
|
});
|
|
361
368
|
|
|
362
|
-
const fetch = jest.spyOn(require('undici'), 'fetch');
|
|
369
|
+
const fetch = globals.jest.spyOn(require('undici'), 'fetch');
|
|
363
370
|
const testApi = (options) => {
|
|
364
371
|
const caches = [];
|
|
365
372
|
const { modules = [], providers = [], env } = options;
|