@wildix/xbees-conversations-utils 1.1.87 → 1.1.89

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,70 @@ function hasResponseInterceptors(value) {
11
11
  }
12
12
  function resolveAxiosInstance(stream) {
13
13
  if (hasResponseInterceptors(stream)) {
14
- return stream;
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 maybeStream.axiosInstance;
24
+ return {
25
+ axiosInstance: maybeStream.axiosInstance,
26
+ source: 'stream.axiosInstance',
27
+ };
22
28
  }
23
29
  if (hasResponseInterceptors(maybeStream._client?.axiosInstance)) {
24
- return maybeStream._client?.axiosInstance;
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
+ streamType: typeof stream,
52
+ streamConstructorName: typeof stream === 'object' && stream !== null ? stream.constructor?.name : undefined,
53
+ streamKeysPreview: getOwnKeysPreview(stream),
54
+ hasAxiosInstanceField: typeof stream === 'object' && stream !== null && 'axiosInstance' in stream,
55
+ hasNestedClientField: typeof stream === 'object' && stream !== null && '_client' in stream,
56
+ nestedClientKeysPreview: typeof stream === 'object' && stream !== null
57
+ ? getOwnKeysPreview(stream._client)
58
+ : undefined,
59
+ });
35
60
  return;
36
61
  }
62
+ logger.info('Resolved axios instance for Stream interceptors', {
63
+ source,
64
+ streamConstructorName: typeof stream === 'object' && stream !== null ? stream.constructor?.name : undefined,
65
+ axiosConstructorName: typeof axiosInstance === 'object' && axiosInstance !== null ? axiosInstance.constructor?.name : undefined,
66
+ axiosKeysPreview: getOwnKeysPreview(axiosInstance),
67
+ });
37
68
  if (attachedInterceptors.has(axiosInstance)) {
69
+ logger.info('Stream interceptors already attached', {
70
+ source,
71
+ });
38
72
  return;
39
73
  }
40
74
  attachedInterceptors.add(axiosInstance);
75
+ logger.info('Attaching Stream response interceptors', {
76
+ source,
77
+ });
41
78
  axiosInstance.interceptors.response.use(async (response) => {
42
79
  try {
43
80
  await (0, processStreamBudgetHeaders_1.processStreamBudgetHeaders)(response?.headers, context);
@@ -57,5 +94,8 @@ function registerStreamInterceptors(stream, context) {
57
94
  }
58
95
  return Promise.reject(error);
59
96
  });
97
+ logger.info('Stream response interceptors attached', {
98
+ source,
99
+ });
60
100
  }
61
101
  exports.registerStreamInterceptors = registerStreamInterceptors;
@@ -8,33 +8,70 @@ function hasResponseInterceptors(value) {
8
8
  }
9
9
  function resolveAxiosInstance(stream) {
10
10
  if (hasResponseInterceptors(stream)) {
11
- return stream;
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 maybeStream.axiosInstance;
21
+ return {
22
+ axiosInstance: maybeStream.axiosInstance,
23
+ source: 'stream.axiosInstance',
24
+ };
19
25
  }
20
26
  if (hasResponseInterceptors(maybeStream._client?.axiosInstance)) {
21
- return maybeStream._client?.axiosInstance;
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
+ streamType: typeof stream,
49
+ streamConstructorName: typeof stream === 'object' && stream !== null ? stream.constructor?.name : undefined,
50
+ streamKeysPreview: getOwnKeysPreview(stream),
51
+ hasAxiosInstanceField: typeof stream === 'object' && stream !== null && 'axiosInstance' in stream,
52
+ hasNestedClientField: typeof stream === 'object' && stream !== null && '_client' in stream,
53
+ nestedClientKeysPreview: typeof stream === 'object' && stream !== null
54
+ ? getOwnKeysPreview(stream._client)
55
+ : undefined,
56
+ });
32
57
  return;
33
58
  }
59
+ logger.info('Resolved axios instance for Stream interceptors', {
60
+ source,
61
+ streamConstructorName: typeof stream === 'object' && stream !== null ? stream.constructor?.name : undefined,
62
+ axiosConstructorName: typeof axiosInstance === 'object' && axiosInstance !== null ? axiosInstance.constructor?.name : undefined,
63
+ axiosKeysPreview: getOwnKeysPreview(axiosInstance),
64
+ });
34
65
  if (attachedInterceptors.has(axiosInstance)) {
66
+ logger.info('Stream interceptors already attached', {
67
+ source,
68
+ });
35
69
  return;
36
70
  }
37
71
  attachedInterceptors.add(axiosInstance);
72
+ logger.info('Attaching Stream response interceptors', {
73
+ source,
74
+ });
38
75
  axiosInstance.interceptors.response.use(async (response) => {
39
76
  try {
40
77
  await processStreamBudgetHeaders(response?.headers, context);
@@ -54,4 +91,7 @@ export function registerStreamInterceptors(stream, context) {
54
91
  }
55
92
  return Promise.reject(error);
56
93
  });
94
+ logger.info('Stream response interceptors attached', {
95
+ source,
96
+ });
57
97
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wildix/xbees-conversations-utils",
3
- "version": "1.1.87",
3
+ "version": "1.1.89",
4
4
  "description": "",
5
5
  "main": "./dist-cjs/index.js",
6
6
  "module": "./dist-es/index.js",