@wildix/xbees-conversations-client 1.2.6 → 1.2.7
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/dist-cjs/ConversationsClient.js +34 -0
- package/dist-es/ConversationsClient.js +34 -0
- package/dist-types/ConversationsClient.d.ts +5 -0
- package/dist-types/runtimeConfig.browser.d.ts +1 -0
- package/dist-types/runtimeConfig.d.ts +1 -0
- package/dist-types/runtimeConfig.native.d.ts +1 -0
- package/package.json +1 -1
|
@@ -32,6 +32,40 @@ class ConversationsClient extends smithy_client_1.Client {
|
|
|
32
32
|
this.middlewareStack.add(smithy_utils_1.authorizationMiddleware.bind(this, configuration.token), { step: "build" });
|
|
33
33
|
this.middlewareStack.use((0, middleware_user_agent_1.getUserAgentPlugin)(this.config));
|
|
34
34
|
this.middlewareStack.use((0, middleware_retry_1.getRetryPlugin)(this.config));
|
|
35
|
+
if (configuration?.retryLogging) {
|
|
36
|
+
this.middlewareStack.add((next) => async (args) => {
|
|
37
|
+
const request = args.request;
|
|
38
|
+
const attemptHeader = request?.headers?.["amz-sdk-request"] ?? request?.headers?.["x-amz-sdk-request"];
|
|
39
|
+
const attemptMatch = typeof attemptHeader === "string" ? attemptHeader.match(/attempt=(\d+)/) : null;
|
|
40
|
+
const attempt = attemptMatch ? Number(attemptMatch[1]) : 1;
|
|
41
|
+
const maxAttempts = await this.config.maxAttempts();
|
|
42
|
+
const startedAt = new Date().toISOString();
|
|
43
|
+
if (attempt > 1) {
|
|
44
|
+
console.warn(`[ConversationsClient] Retry attempt ${attempt}/${maxAttempts} started at ${startedAt}`);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
console.info(`[ConversationsClient] Request attempt ${attempt}/${maxAttempts} started at ${startedAt}`);
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
return await next(args);
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
const statusCode = error?.$metadata?.httpStatusCode ?? error?.$response?.statusCode;
|
|
54
|
+
const willRetry = attempt < maxAttempts && this.config.retryDecider(error);
|
|
55
|
+
if (willRetry) {
|
|
56
|
+
console.warn(`[ConversationsClient] Retry decision: will retry after attempt ${attempt}/${maxAttempts} (status=${statusCode ?? "unknown"}, time=${new Date().toISOString()})`);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
console.warn(`[ConversationsClient] Retry decision: stop after attempt ${attempt}/${maxAttempts} (status=${statusCode ?? "unknown"}, time=${new Date().toISOString()})`);
|
|
60
|
+
}
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
}, {
|
|
64
|
+
name: "retryLoggingMiddleware",
|
|
65
|
+
step: "finalizeRequest",
|
|
66
|
+
priority: "low",
|
|
67
|
+
});
|
|
68
|
+
}
|
|
35
69
|
this.middlewareStack.use((0, middleware_content_length_1.getContentLengthPlugin)(this.config));
|
|
36
70
|
}
|
|
37
71
|
destroy() {
|
|
@@ -29,6 +29,40 @@ export class ConversationsClient extends __Client {
|
|
|
29
29
|
this.middlewareStack.add(authorizationMiddleware.bind(this, configuration.token), { step: "build" });
|
|
30
30
|
this.middlewareStack.use(getUserAgentPlugin(this.config));
|
|
31
31
|
this.middlewareStack.use(getRetryPlugin(this.config));
|
|
32
|
+
if (configuration?.retryLogging) {
|
|
33
|
+
this.middlewareStack.add((next) => async (args) => {
|
|
34
|
+
const request = args.request;
|
|
35
|
+
const attemptHeader = request?.headers?.["amz-sdk-request"] ?? request?.headers?.["x-amz-sdk-request"];
|
|
36
|
+
const attemptMatch = typeof attemptHeader === "string" ? attemptHeader.match(/attempt=(\d+)/) : null;
|
|
37
|
+
const attempt = attemptMatch ? Number(attemptMatch[1]) : 1;
|
|
38
|
+
const maxAttempts = await this.config.maxAttempts();
|
|
39
|
+
const startedAt = new Date().toISOString();
|
|
40
|
+
if (attempt > 1) {
|
|
41
|
+
console.warn(`[ConversationsClient] Retry attempt ${attempt}/${maxAttempts} started at ${startedAt}`);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
console.info(`[ConversationsClient] Request attempt ${attempt}/${maxAttempts} started at ${startedAt}`);
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
return await next(args);
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
const statusCode = error?.$metadata?.httpStatusCode ?? error?.$response?.statusCode;
|
|
51
|
+
const willRetry = attempt < maxAttempts && this.config.retryDecider(error);
|
|
52
|
+
if (willRetry) {
|
|
53
|
+
console.warn(`[ConversationsClient] Retry decision: will retry after attempt ${attempt}/${maxAttempts} (status=${statusCode ?? "unknown"}, time=${new Date().toISOString()})`);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
console.warn(`[ConversationsClient] Retry decision: stop after attempt ${attempt}/${maxAttempts} (status=${statusCode ?? "unknown"}, time=${new Date().toISOString()})`);
|
|
57
|
+
}
|
|
58
|
+
throw error;
|
|
59
|
+
}
|
|
60
|
+
}, {
|
|
61
|
+
name: "retryLoggingMiddleware",
|
|
62
|
+
step: "finalizeRequest",
|
|
63
|
+
priority: "low",
|
|
64
|
+
});
|
|
65
|
+
}
|
|
32
66
|
this.middlewareStack.use(getContentLengthPlugin(this.config));
|
|
33
67
|
}
|
|
34
68
|
destroy() {
|
|
@@ -151,6 +151,11 @@ export interface ClientDefaults extends Partial<__SmithyConfiguration<__HttpHand
|
|
|
151
151
|
* Custom retry decider override.
|
|
152
152
|
*/
|
|
153
153
|
retryDecider?: (error: any) => boolean;
|
|
154
|
+
/**
|
|
155
|
+
* Enables console logging for retry attempts and retry decisions.
|
|
156
|
+
* Defaults to `false`.
|
|
157
|
+
*/
|
|
158
|
+
retryLogging?: boolean;
|
|
154
159
|
/**
|
|
155
160
|
* Value for how many times a request will be made at most in case of retry.
|
|
156
161
|
*/
|
|
@@ -30,6 +30,7 @@ export declare const getRuntimeConfig: (config: ConversationsClientConfig) => {
|
|
|
30
30
|
utf8Encoder: (input: string | Uint8Array) => string;
|
|
31
31
|
disableHostPrefix: boolean;
|
|
32
32
|
retryOn429?: boolean | undefined;
|
|
33
|
+
retryLogging?: boolean | undefined;
|
|
33
34
|
logger: import("@smithy/types").Logger;
|
|
34
35
|
extensions: import("./runtimeExtensions").RuntimeExtension[];
|
|
35
36
|
customUserAgent?: string | import("@smithy/types").UserAgent | undefined;
|
|
@@ -31,6 +31,7 @@ export declare const getRuntimeConfig: (config: ConversationsClientConfig) => {
|
|
|
31
31
|
utf8Encoder: (input: string | Uint8Array) => string;
|
|
32
32
|
disableHostPrefix: boolean;
|
|
33
33
|
retryOn429?: boolean | undefined;
|
|
34
|
+
retryLogging?: boolean | undefined;
|
|
34
35
|
logger: import("@smithy/types").Logger;
|
|
35
36
|
extensions: import("./runtimeExtensions").RuntimeExtension[];
|
|
36
37
|
customUserAgent?: string | import("@smithy/types").UserAgent | undefined;
|
|
@@ -26,6 +26,7 @@ export declare const getRuntimeConfig: (config: ConversationsClientConfig) => {
|
|
|
26
26
|
defaultUserAgentProvider: (config?: import("@aws-sdk/util-user-agent-browser").PreviouslyResolved | undefined) => Promise<import("@smithy/types").UserAgent>;
|
|
27
27
|
retryOn429?: boolean | undefined;
|
|
28
28
|
retryDecider: (error: any) => boolean;
|
|
29
|
+
retryLogging?: boolean | undefined;
|
|
29
30
|
maxAttempts: number | import("@smithy/types").Provider<number>;
|
|
30
31
|
retryMode: string | import("@smithy/types").Provider<string>;
|
|
31
32
|
logger: import("@smithy/types").Logger;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wildix/xbees-conversations-client",
|
|
3
3
|
"description": "@wildix/xbees-conversations-client client",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.7",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
|
|
7
7
|
"build:cjs": "tsc -p tsconfig.cjs.json",
|