@wildix/xbees-conversations-utils 1.1.87 → 1.1.88
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.
|
@@ -11,33 +11,69 @@ function hasResponseInterceptors(value) {
|
|
|
11
11
|
}
|
|
12
12
|
function resolveAxiosInstance(stream) {
|
|
13
13
|
if (hasResponseInterceptors(stream)) {
|
|
14
|
-
return
|
|
14
|
+
return {
|
|
15
|
+
axiosInstance: stream,
|
|
16
|
+
source: 'stream',
|
|
17
|
+
};
|
|
15
18
|
}
|
|
16
19
|
if (typeof stream !== 'object' || stream === null) {
|
|
17
|
-
return;
|
|
20
|
+
return {};
|
|
18
21
|
}
|
|
19
22
|
const maybeStream = stream;
|
|
20
23
|
if (hasResponseInterceptors(maybeStream.axiosInstance)) {
|
|
21
|
-
return
|
|
24
|
+
return {
|
|
25
|
+
axiosInstance: maybeStream.axiosInstance,
|
|
26
|
+
source: 'stream.axiosInstance',
|
|
27
|
+
};
|
|
22
28
|
}
|
|
23
29
|
if (hasResponseInterceptors(maybeStream._client?.axiosInstance)) {
|
|
24
|
-
return
|
|
30
|
+
return {
|
|
31
|
+
axiosInstance: maybeStream._client?.axiosInstance,
|
|
32
|
+
source: 'stream._client.axiosInstance',
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
return {};
|
|
36
|
+
}
|
|
37
|
+
function getOwnKeysPreview(value) {
|
|
38
|
+
if (typeof value !== 'object' || value === null) {
|
|
39
|
+
return;
|
|
25
40
|
}
|
|
41
|
+
return Object.keys(value).slice(0, 20);
|
|
26
42
|
}
|
|
27
43
|
function resolveRequestUrl(responseOrError) {
|
|
28
44
|
return responseOrError.config?.url ?? responseOrError.response?.config?.url;
|
|
29
45
|
}
|
|
30
46
|
function registerStreamInterceptors(stream, context) {
|
|
31
47
|
const { logger } = context;
|
|
32
|
-
const axiosInstance = resolveAxiosInstance(stream);
|
|
48
|
+
const { axiosInstance, source } = resolveAxiosInstance(stream);
|
|
33
49
|
if (!axiosInstance || !axiosInstance.interceptors?.response?.use) {
|
|
34
|
-
logger.warn('Unable to register stream budget & rate limit interceptors: axios instance not found'
|
|
50
|
+
logger.warn('Unable to register stream budget & rate limit interceptors: axios instance not found', {
|
|
51
|
+
streamConstructorName: typeof stream === 'object' && stream !== null ? stream.constructor?.name : undefined,
|
|
52
|
+
streamKeysPreview: getOwnKeysPreview(stream),
|
|
53
|
+
hasAxiosInstanceField: typeof stream === 'object' && stream !== null && 'axiosInstance' in stream,
|
|
54
|
+
hasNestedClientField: typeof stream === 'object' && stream !== null && '_client' in stream,
|
|
55
|
+
nestedClientKeysPreview: typeof stream === 'object' && stream !== null
|
|
56
|
+
? getOwnKeysPreview(stream._client)
|
|
57
|
+
: undefined,
|
|
58
|
+
});
|
|
35
59
|
return;
|
|
36
60
|
}
|
|
61
|
+
logger.info('Resolved axios instance for Stream interceptors', {
|
|
62
|
+
source,
|
|
63
|
+
streamConstructorName: typeof stream === 'object' && stream !== null ? stream.constructor?.name : undefined,
|
|
64
|
+
axiosConstructorName: typeof axiosInstance === 'object' && axiosInstance !== null ? axiosInstance.constructor?.name : undefined,
|
|
65
|
+
axiosKeysPreview: getOwnKeysPreview(axiosInstance),
|
|
66
|
+
});
|
|
37
67
|
if (attachedInterceptors.has(axiosInstance)) {
|
|
68
|
+
logger.info('Stream interceptors already attached', {
|
|
69
|
+
source,
|
|
70
|
+
});
|
|
38
71
|
return;
|
|
39
72
|
}
|
|
40
73
|
attachedInterceptors.add(axiosInstance);
|
|
74
|
+
logger.info('Attaching Stream response interceptors', {
|
|
75
|
+
source,
|
|
76
|
+
});
|
|
41
77
|
axiosInstance.interceptors.response.use(async (response) => {
|
|
42
78
|
try {
|
|
43
79
|
await (0, processStreamBudgetHeaders_1.processStreamBudgetHeaders)(response?.headers, context);
|
|
@@ -57,5 +93,8 @@ function registerStreamInterceptors(stream, context) {
|
|
|
57
93
|
}
|
|
58
94
|
return Promise.reject(error);
|
|
59
95
|
});
|
|
96
|
+
logger.info('Stream response interceptors attached', {
|
|
97
|
+
source,
|
|
98
|
+
});
|
|
60
99
|
}
|
|
61
100
|
exports.registerStreamInterceptors = registerStreamInterceptors;
|
|
@@ -8,33 +8,69 @@ function hasResponseInterceptors(value) {
|
|
|
8
8
|
}
|
|
9
9
|
function resolveAxiosInstance(stream) {
|
|
10
10
|
if (hasResponseInterceptors(stream)) {
|
|
11
|
-
return
|
|
11
|
+
return {
|
|
12
|
+
axiosInstance: stream,
|
|
13
|
+
source: 'stream',
|
|
14
|
+
};
|
|
12
15
|
}
|
|
13
16
|
if (typeof stream !== 'object' || stream === null) {
|
|
14
|
-
return;
|
|
17
|
+
return {};
|
|
15
18
|
}
|
|
16
19
|
const maybeStream = stream;
|
|
17
20
|
if (hasResponseInterceptors(maybeStream.axiosInstance)) {
|
|
18
|
-
return
|
|
21
|
+
return {
|
|
22
|
+
axiosInstance: maybeStream.axiosInstance,
|
|
23
|
+
source: 'stream.axiosInstance',
|
|
24
|
+
};
|
|
19
25
|
}
|
|
20
26
|
if (hasResponseInterceptors(maybeStream._client?.axiosInstance)) {
|
|
21
|
-
return
|
|
27
|
+
return {
|
|
28
|
+
axiosInstance: maybeStream._client?.axiosInstance,
|
|
29
|
+
source: 'stream._client.axiosInstance',
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
return {};
|
|
33
|
+
}
|
|
34
|
+
function getOwnKeysPreview(value) {
|
|
35
|
+
if (typeof value !== 'object' || value === null) {
|
|
36
|
+
return;
|
|
22
37
|
}
|
|
38
|
+
return Object.keys(value).slice(0, 20);
|
|
23
39
|
}
|
|
24
40
|
function resolveRequestUrl(responseOrError) {
|
|
25
41
|
return responseOrError.config?.url ?? responseOrError.response?.config?.url;
|
|
26
42
|
}
|
|
27
43
|
export function registerStreamInterceptors(stream, context) {
|
|
28
44
|
const { logger } = context;
|
|
29
|
-
const axiosInstance = resolveAxiosInstance(stream);
|
|
45
|
+
const { axiosInstance, source } = resolveAxiosInstance(stream);
|
|
30
46
|
if (!axiosInstance || !axiosInstance.interceptors?.response?.use) {
|
|
31
|
-
logger.warn('Unable to register stream budget & rate limit interceptors: axios instance not found'
|
|
47
|
+
logger.warn('Unable to register stream budget & rate limit interceptors: axios instance not found', {
|
|
48
|
+
streamConstructorName: typeof stream === 'object' && stream !== null ? stream.constructor?.name : undefined,
|
|
49
|
+
streamKeysPreview: getOwnKeysPreview(stream),
|
|
50
|
+
hasAxiosInstanceField: typeof stream === 'object' && stream !== null && 'axiosInstance' in stream,
|
|
51
|
+
hasNestedClientField: typeof stream === 'object' && stream !== null && '_client' in stream,
|
|
52
|
+
nestedClientKeysPreview: typeof stream === 'object' && stream !== null
|
|
53
|
+
? getOwnKeysPreview(stream._client)
|
|
54
|
+
: undefined,
|
|
55
|
+
});
|
|
32
56
|
return;
|
|
33
57
|
}
|
|
58
|
+
logger.info('Resolved axios instance for Stream interceptors', {
|
|
59
|
+
source,
|
|
60
|
+
streamConstructorName: typeof stream === 'object' && stream !== null ? stream.constructor?.name : undefined,
|
|
61
|
+
axiosConstructorName: typeof axiosInstance === 'object' && axiosInstance !== null ? axiosInstance.constructor?.name : undefined,
|
|
62
|
+
axiosKeysPreview: getOwnKeysPreview(axiosInstance),
|
|
63
|
+
});
|
|
34
64
|
if (attachedInterceptors.has(axiosInstance)) {
|
|
65
|
+
logger.info('Stream interceptors already attached', {
|
|
66
|
+
source,
|
|
67
|
+
});
|
|
35
68
|
return;
|
|
36
69
|
}
|
|
37
70
|
attachedInterceptors.add(axiosInstance);
|
|
71
|
+
logger.info('Attaching Stream response interceptors', {
|
|
72
|
+
source,
|
|
73
|
+
});
|
|
38
74
|
axiosInstance.interceptors.response.use(async (response) => {
|
|
39
75
|
try {
|
|
40
76
|
await processStreamBudgetHeaders(response?.headers, context);
|
|
@@ -54,4 +90,7 @@ export function registerStreamInterceptors(stream, context) {
|
|
|
54
90
|
}
|
|
55
91
|
return Promise.reject(error);
|
|
56
92
|
});
|
|
93
|
+
logger.info('Stream response interceptors attached', {
|
|
94
|
+
source,
|
|
95
|
+
});
|
|
57
96
|
}
|