@koi-design/callkit 2.0.0-beta.1 → 2.0.0-beta.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/dist/index.d.ts +1 -1
- package/dist/index.global.js +14 -255
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +2 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -20
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -473,7 +473,7 @@ declare class CallKit {
|
|
|
473
473
|
* set userstatus
|
|
474
474
|
* @param status
|
|
475
475
|
*/
|
|
476
|
-
setUserStatus(status: number): void
|
|
476
|
+
setUserStatus(status: number): Promise<void>;
|
|
477
477
|
reset(): Promise<void>;
|
|
478
478
|
on(event: kitEventType, callback: (...args: any[]) => void): void;
|
|
479
479
|
off(event: kitEventType, callback?: (...args: any[]) => void): void;
|
package/dist/index.global.js
CHANGED
|
@@ -1083,16 +1083,16 @@ var WebCall = (() => {
|
|
|
1083
1083
|
createDebug.names = [];
|
|
1084
1084
|
createDebug.skips = [];
|
|
1085
1085
|
createDebug.formatters = {};
|
|
1086
|
-
function selectColor(
|
|
1086
|
+
function selectColor(namespace) {
|
|
1087
1087
|
let hash = 0;
|
|
1088
|
-
for (let i = 0; i <
|
|
1089
|
-
hash = (hash << 5) - hash +
|
|
1088
|
+
for (let i = 0; i < namespace.length; i++) {
|
|
1089
|
+
hash = (hash << 5) - hash + namespace.charCodeAt(i);
|
|
1090
1090
|
hash |= 0;
|
|
1091
1091
|
}
|
|
1092
1092
|
return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
|
|
1093
1093
|
}
|
|
1094
1094
|
createDebug.selectColor = selectColor;
|
|
1095
|
-
function createDebug(
|
|
1095
|
+
function createDebug(namespace) {
|
|
1096
1096
|
let prevTime;
|
|
1097
1097
|
let enableOverride = null;
|
|
1098
1098
|
let namespacesCache;
|
|
@@ -1131,9 +1131,9 @@ var WebCall = (() => {
|
|
|
1131
1131
|
const logFn = self.log || createDebug.log;
|
|
1132
1132
|
logFn.apply(self, args);
|
|
1133
1133
|
}
|
|
1134
|
-
debug.namespace =
|
|
1134
|
+
debug.namespace = namespace;
|
|
1135
1135
|
debug.useColors = createDebug.useColors();
|
|
1136
|
-
debug.color = createDebug.selectColor(
|
|
1136
|
+
debug.color = createDebug.selectColor(namespace);
|
|
1137
1137
|
debug.extend = extend;
|
|
1138
1138
|
debug.destroy = createDebug.destroy;
|
|
1139
1139
|
Object.defineProperty(debug, "enabled", {
|
|
@@ -1145,7 +1145,7 @@ var WebCall = (() => {
|
|
|
1145
1145
|
}
|
|
1146
1146
|
if (namespacesCache !== createDebug.namespaces) {
|
|
1147
1147
|
namespacesCache = createDebug.namespaces;
|
|
1148
|
-
enabledCache = createDebug.enabled(
|
|
1148
|
+
enabledCache = createDebug.enabled(namespace);
|
|
1149
1149
|
}
|
|
1150
1150
|
return enabledCache;
|
|
1151
1151
|
},
|
|
@@ -1158,8 +1158,8 @@ var WebCall = (() => {
|
|
|
1158
1158
|
}
|
|
1159
1159
|
return debug;
|
|
1160
1160
|
}
|
|
1161
|
-
function extend(
|
|
1162
|
-
const newDebug = createDebug(this.namespace + (typeof delimiter === "undefined" ? ":" : delimiter) +
|
|
1161
|
+
function extend(namespace, delimiter) {
|
|
1162
|
+
const newDebug = createDebug(this.namespace + (typeof delimiter === "undefined" ? ":" : delimiter) + namespace);
|
|
1163
1163
|
newDebug.log = this.log;
|
|
1164
1164
|
return newDebug;
|
|
1165
1165
|
}
|
|
@@ -1208,7 +1208,7 @@ var WebCall = (() => {
|
|
|
1208
1208
|
function disable() {
|
|
1209
1209
|
const namespaces = [
|
|
1210
1210
|
...createDebug.names,
|
|
1211
|
-
...createDebug.skips.map((
|
|
1211
|
+
...createDebug.skips.map((namespace) => "-" + namespace)
|
|
1212
1212
|
].join(",");
|
|
1213
1213
|
createDebug.enable("");
|
|
1214
1214
|
return namespaces;
|
|
@@ -3161,47 +3161,6 @@ var WebCall = (() => {
|
|
|
3161
3161
|
}
|
|
3162
3162
|
});
|
|
3163
3163
|
|
|
3164
|
-
// node_modules/.pnpm/is-retry-allowed@2.2.0/node_modules/is-retry-allowed/index.js
|
|
3165
|
-
var require_is_retry_allowed = __commonJS({
|
|
3166
|
-
"node_modules/.pnpm/is-retry-allowed@2.2.0/node_modules/is-retry-allowed/index.js"(exports, module) {
|
|
3167
|
-
"use strict";
|
|
3168
|
-
var denyList = /* @__PURE__ */ new Set([
|
|
3169
|
-
"ENOTFOUND",
|
|
3170
|
-
"ENETUNREACH",
|
|
3171
|
-
// SSL errors from https://github.com/nodejs/node/blob/fc8e3e2cdc521978351de257030db0076d79e0ab/src/crypto/crypto_common.cc#L301-L328
|
|
3172
|
-
"UNABLE_TO_GET_ISSUER_CERT",
|
|
3173
|
-
"UNABLE_TO_GET_CRL",
|
|
3174
|
-
"UNABLE_TO_DECRYPT_CERT_SIGNATURE",
|
|
3175
|
-
"UNABLE_TO_DECRYPT_CRL_SIGNATURE",
|
|
3176
|
-
"UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY",
|
|
3177
|
-
"CERT_SIGNATURE_FAILURE",
|
|
3178
|
-
"CRL_SIGNATURE_FAILURE",
|
|
3179
|
-
"CERT_NOT_YET_VALID",
|
|
3180
|
-
"CERT_HAS_EXPIRED",
|
|
3181
|
-
"CRL_NOT_YET_VALID",
|
|
3182
|
-
"CRL_HAS_EXPIRED",
|
|
3183
|
-
"ERROR_IN_CERT_NOT_BEFORE_FIELD",
|
|
3184
|
-
"ERROR_IN_CERT_NOT_AFTER_FIELD",
|
|
3185
|
-
"ERROR_IN_CRL_LAST_UPDATE_FIELD",
|
|
3186
|
-
"ERROR_IN_CRL_NEXT_UPDATE_FIELD",
|
|
3187
|
-
"OUT_OF_MEM",
|
|
3188
|
-
"DEPTH_ZERO_SELF_SIGNED_CERT",
|
|
3189
|
-
"SELF_SIGNED_CERT_IN_CHAIN",
|
|
3190
|
-
"UNABLE_TO_GET_ISSUER_CERT_LOCALLY",
|
|
3191
|
-
"UNABLE_TO_VERIFY_LEAF_SIGNATURE",
|
|
3192
|
-
"CERT_CHAIN_TOO_LONG",
|
|
3193
|
-
"CERT_REVOKED",
|
|
3194
|
-
"INVALID_CA",
|
|
3195
|
-
"PATH_LENGTH_EXCEEDED",
|
|
3196
|
-
"INVALID_PURPOSE",
|
|
3197
|
-
"CERT_UNTRUSTED",
|
|
3198
|
-
"CERT_REJECTED",
|
|
3199
|
-
"HOSTNAME_MISMATCH"
|
|
3200
|
-
]);
|
|
3201
|
-
module.exports = (error) => !denyList.has(error && error.code);
|
|
3202
|
-
}
|
|
3203
|
-
});
|
|
3204
|
-
|
|
3205
3164
|
// node_modules/.pnpm/json-stringify-safe@5.0.1/node_modules/json-stringify-safe/stringify.js
|
|
3206
3165
|
var require_stringify = __commonJS({
|
|
3207
3166
|
"node_modules/.pnpm/json-stringify-safe@5.0.1/node_modules/json-stringify-safe/stringify.js"(exports, module) {
|
|
@@ -3242,189 +3201,6 @@ var WebCall = (() => {
|
|
|
3242
3201
|
|
|
3243
3202
|
// package/axios.ts
|
|
3244
3203
|
var import_axios = __toESM(require_axios2());
|
|
3245
|
-
|
|
3246
|
-
// node_modules/.pnpm/axios-retry@4.5.0_axios@0.26.1/node_modules/axios-retry/dist/esm/index.js
|
|
3247
|
-
var import_is_retry_allowed = __toESM(require_is_retry_allowed(), 1);
|
|
3248
|
-
var namespace = "axios-retry";
|
|
3249
|
-
function isNetworkError(error) {
|
|
3250
|
-
const CODE_EXCLUDE_LIST = ["ERR_CANCELED", "ECONNABORTED"];
|
|
3251
|
-
if (error.response) {
|
|
3252
|
-
return false;
|
|
3253
|
-
}
|
|
3254
|
-
if (!error.code) {
|
|
3255
|
-
return false;
|
|
3256
|
-
}
|
|
3257
|
-
if (CODE_EXCLUDE_LIST.includes(error.code)) {
|
|
3258
|
-
return false;
|
|
3259
|
-
}
|
|
3260
|
-
return (0, import_is_retry_allowed.default)(error);
|
|
3261
|
-
}
|
|
3262
|
-
var SAFE_HTTP_METHODS = ["get", "head", "options"];
|
|
3263
|
-
var IDEMPOTENT_HTTP_METHODS = SAFE_HTTP_METHODS.concat(["put", "delete"]);
|
|
3264
|
-
function isRetryableError(error) {
|
|
3265
|
-
return error.code !== "ECONNABORTED" && (!error.response || error.response.status === 429 || error.response.status >= 500 && error.response.status <= 599);
|
|
3266
|
-
}
|
|
3267
|
-
function isSafeRequestError(error) {
|
|
3268
|
-
if (!error.config?.method) {
|
|
3269
|
-
return false;
|
|
3270
|
-
}
|
|
3271
|
-
return isRetryableError(error) && SAFE_HTTP_METHODS.indexOf(error.config.method) !== -1;
|
|
3272
|
-
}
|
|
3273
|
-
function isIdempotentRequestError(error) {
|
|
3274
|
-
if (!error.config?.method) {
|
|
3275
|
-
return false;
|
|
3276
|
-
}
|
|
3277
|
-
return isRetryableError(error) && IDEMPOTENT_HTTP_METHODS.indexOf(error.config.method) !== -1;
|
|
3278
|
-
}
|
|
3279
|
-
function isNetworkOrIdempotentRequestError(error) {
|
|
3280
|
-
return isNetworkError(error) || isIdempotentRequestError(error);
|
|
3281
|
-
}
|
|
3282
|
-
function retryAfter(error = void 0) {
|
|
3283
|
-
const retryAfterHeader = error?.response?.headers["retry-after"];
|
|
3284
|
-
if (!retryAfterHeader) {
|
|
3285
|
-
return 0;
|
|
3286
|
-
}
|
|
3287
|
-
let retryAfterMs = (Number(retryAfterHeader) || 0) * 1e3;
|
|
3288
|
-
if (retryAfterMs === 0) {
|
|
3289
|
-
retryAfterMs = (new Date(retryAfterHeader).valueOf() || 0) - Date.now();
|
|
3290
|
-
}
|
|
3291
|
-
return Math.max(0, retryAfterMs);
|
|
3292
|
-
}
|
|
3293
|
-
function noDelay(_retryNumber = 0, error = void 0) {
|
|
3294
|
-
return Math.max(0, retryAfter(error));
|
|
3295
|
-
}
|
|
3296
|
-
function exponentialDelay(retryNumber = 0, error = void 0, delayFactor = 100) {
|
|
3297
|
-
const calculatedDelay = 2 ** retryNumber * delayFactor;
|
|
3298
|
-
const delay = Math.max(calculatedDelay, retryAfter(error));
|
|
3299
|
-
const randomSum = delay * 0.2 * Math.random();
|
|
3300
|
-
return delay + randomSum;
|
|
3301
|
-
}
|
|
3302
|
-
function linearDelay(delayFactor = 100) {
|
|
3303
|
-
return (retryNumber = 0, error = void 0) => {
|
|
3304
|
-
const delay = retryNumber * delayFactor;
|
|
3305
|
-
return Math.max(delay, retryAfter(error));
|
|
3306
|
-
};
|
|
3307
|
-
}
|
|
3308
|
-
var DEFAULT_OPTIONS = {
|
|
3309
|
-
retries: 3,
|
|
3310
|
-
retryCondition: isNetworkOrIdempotentRequestError,
|
|
3311
|
-
retryDelay: noDelay,
|
|
3312
|
-
shouldResetTimeout: false,
|
|
3313
|
-
onRetry: () => {
|
|
3314
|
-
},
|
|
3315
|
-
onMaxRetryTimesExceeded: () => {
|
|
3316
|
-
},
|
|
3317
|
-
validateResponse: null
|
|
3318
|
-
};
|
|
3319
|
-
function getRequestOptions(config, defaultOptions) {
|
|
3320
|
-
return { ...DEFAULT_OPTIONS, ...defaultOptions, ...config[namespace] };
|
|
3321
|
-
}
|
|
3322
|
-
function setCurrentState(config, defaultOptions, resetLastRequestTime = false) {
|
|
3323
|
-
const currentState = getRequestOptions(config, defaultOptions || {});
|
|
3324
|
-
currentState.retryCount = currentState.retryCount || 0;
|
|
3325
|
-
if (!currentState.lastRequestTime || resetLastRequestTime) {
|
|
3326
|
-
currentState.lastRequestTime = Date.now();
|
|
3327
|
-
}
|
|
3328
|
-
config[namespace] = currentState;
|
|
3329
|
-
return currentState;
|
|
3330
|
-
}
|
|
3331
|
-
function fixConfig(axiosInstance, config) {
|
|
3332
|
-
if (axiosInstance.defaults.agent === config.agent) {
|
|
3333
|
-
delete config.agent;
|
|
3334
|
-
}
|
|
3335
|
-
if (axiosInstance.defaults.httpAgent === config.httpAgent) {
|
|
3336
|
-
delete config.httpAgent;
|
|
3337
|
-
}
|
|
3338
|
-
if (axiosInstance.defaults.httpsAgent === config.httpsAgent) {
|
|
3339
|
-
delete config.httpsAgent;
|
|
3340
|
-
}
|
|
3341
|
-
}
|
|
3342
|
-
async function shouldRetry(currentState, error) {
|
|
3343
|
-
const { retries, retryCondition } = currentState;
|
|
3344
|
-
const shouldRetryOrPromise = (currentState.retryCount || 0) < retries && retryCondition(error);
|
|
3345
|
-
if (typeof shouldRetryOrPromise === "object") {
|
|
3346
|
-
try {
|
|
3347
|
-
const shouldRetryPromiseResult = await shouldRetryOrPromise;
|
|
3348
|
-
return shouldRetryPromiseResult !== false;
|
|
3349
|
-
} catch (_err) {
|
|
3350
|
-
return false;
|
|
3351
|
-
}
|
|
3352
|
-
}
|
|
3353
|
-
return shouldRetryOrPromise;
|
|
3354
|
-
}
|
|
3355
|
-
async function handleRetry(axiosInstance, currentState, error, config) {
|
|
3356
|
-
currentState.retryCount += 1;
|
|
3357
|
-
const { retryDelay, shouldResetTimeout, onRetry } = currentState;
|
|
3358
|
-
const delay = retryDelay(currentState.retryCount, error);
|
|
3359
|
-
fixConfig(axiosInstance, config);
|
|
3360
|
-
if (!shouldResetTimeout && config.timeout && currentState.lastRequestTime) {
|
|
3361
|
-
const lastRequestDuration = Date.now() - currentState.lastRequestTime;
|
|
3362
|
-
const timeout = config.timeout - lastRequestDuration - delay;
|
|
3363
|
-
if (timeout <= 0) {
|
|
3364
|
-
return Promise.reject(error);
|
|
3365
|
-
}
|
|
3366
|
-
config.timeout = timeout;
|
|
3367
|
-
}
|
|
3368
|
-
config.transformRequest = [(data) => data];
|
|
3369
|
-
await onRetry(currentState.retryCount, error, config);
|
|
3370
|
-
if (config.signal?.aborted) {
|
|
3371
|
-
return Promise.resolve(axiosInstance(config));
|
|
3372
|
-
}
|
|
3373
|
-
return new Promise((resolve) => {
|
|
3374
|
-
const abortListener = () => {
|
|
3375
|
-
clearTimeout(timeout);
|
|
3376
|
-
resolve(axiosInstance(config));
|
|
3377
|
-
};
|
|
3378
|
-
const timeout = setTimeout(() => {
|
|
3379
|
-
resolve(axiosInstance(config));
|
|
3380
|
-
if (config.signal?.removeEventListener) {
|
|
3381
|
-
config.signal.removeEventListener("abort", abortListener);
|
|
3382
|
-
}
|
|
3383
|
-
}, delay);
|
|
3384
|
-
if (config.signal?.addEventListener) {
|
|
3385
|
-
config.signal.addEventListener("abort", abortListener, { once: true });
|
|
3386
|
-
}
|
|
3387
|
-
});
|
|
3388
|
-
}
|
|
3389
|
-
async function handleMaxRetryTimesExceeded(currentState, error) {
|
|
3390
|
-
if (currentState.retryCount >= currentState.retries)
|
|
3391
|
-
await currentState.onMaxRetryTimesExceeded(error, currentState.retryCount);
|
|
3392
|
-
}
|
|
3393
|
-
var axiosRetry = (axiosInstance, defaultOptions) => {
|
|
3394
|
-
const requestInterceptorId = axiosInstance.interceptors.request.use((config) => {
|
|
3395
|
-
setCurrentState(config, defaultOptions, true);
|
|
3396
|
-
if (config[namespace]?.validateResponse) {
|
|
3397
|
-
config.validateStatus = () => false;
|
|
3398
|
-
}
|
|
3399
|
-
return config;
|
|
3400
|
-
});
|
|
3401
|
-
const responseInterceptorId = axiosInstance.interceptors.response.use(null, async (error) => {
|
|
3402
|
-
const { config } = error;
|
|
3403
|
-
if (!config) {
|
|
3404
|
-
return Promise.reject(error);
|
|
3405
|
-
}
|
|
3406
|
-
const currentState = setCurrentState(config, defaultOptions);
|
|
3407
|
-
if (error.response && currentState.validateResponse?.(error.response)) {
|
|
3408
|
-
return error.response;
|
|
3409
|
-
}
|
|
3410
|
-
if (await shouldRetry(currentState, error)) {
|
|
3411
|
-
return handleRetry(axiosInstance, currentState, error, config);
|
|
3412
|
-
}
|
|
3413
|
-
await handleMaxRetryTimesExceeded(currentState, error);
|
|
3414
|
-
return Promise.reject(error);
|
|
3415
|
-
});
|
|
3416
|
-
return { requestInterceptorId, responseInterceptorId };
|
|
3417
|
-
};
|
|
3418
|
-
axiosRetry.isNetworkError = isNetworkError;
|
|
3419
|
-
axiosRetry.isSafeRequestError = isSafeRequestError;
|
|
3420
|
-
axiosRetry.isIdempotentRequestError = isIdempotentRequestError;
|
|
3421
|
-
axiosRetry.isNetworkOrIdempotentRequestError = isNetworkOrIdempotentRequestError;
|
|
3422
|
-
axiosRetry.exponentialDelay = exponentialDelay;
|
|
3423
|
-
axiosRetry.linearDelay = linearDelay;
|
|
3424
|
-
axiosRetry.isRetryableError = isRetryableError;
|
|
3425
|
-
var esm_default = axiosRetry;
|
|
3426
|
-
|
|
3427
|
-
// package/axios.ts
|
|
3428
3204
|
var instance = import_axios.default.create({
|
|
3429
3205
|
headers: {
|
|
3430
3206
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
@@ -3435,23 +3211,6 @@ var WebCall = (() => {
|
|
|
3435
3211
|
(response) => response.data,
|
|
3436
3212
|
(error) => Promise.reject(error)
|
|
3437
3213
|
);
|
|
3438
|
-
esm_default(instance, {
|
|
3439
|
-
retries: 3,
|
|
3440
|
-
// Maximum number of retries, default is 3
|
|
3441
|
-
retryDelay: (retryCount, error) => {
|
|
3442
|
-
console.log(
|
|
3443
|
-
`AJAX Retrying attempt ${retryCount}, error: ${error?.message}`
|
|
3444
|
-
);
|
|
3445
|
-
return retryCount * 1e3;
|
|
3446
|
-
},
|
|
3447
|
-
retryCondition: (error) => {
|
|
3448
|
-
if (!error.response)
|
|
3449
|
-
return true;
|
|
3450
|
-
return error.response.status < 200 || error.response.status >= 300;
|
|
3451
|
-
},
|
|
3452
|
-
shouldResetTimeout: true
|
|
3453
|
-
// Whether to reset axios timeout on retry
|
|
3454
|
-
});
|
|
3455
3214
|
var request = (config) => instance.request(config);
|
|
3456
3215
|
var axios_default = request;
|
|
3457
3216
|
|
|
@@ -13204,8 +12963,8 @@ var WebCall = (() => {
|
|
|
13204
12963
|
this.logger.warn(msg);
|
|
13205
12964
|
return;
|
|
13206
12965
|
};
|
|
13207
|
-
const
|
|
13208
|
-
const extraHeaders = [`Retry-After: ${
|
|
12966
|
+
const retryAfter = Math.floor(Math.random() * 10) + 1;
|
|
12967
|
+
const extraHeaders = [`Retry-After: ${retryAfter}`];
|
|
13209
12968
|
if (this.ackProcessing) {
|
|
13210
12969
|
this.core.replyStateless(message, { statusCode: 500, extraHeaders });
|
|
13211
12970
|
warning();
|
|
@@ -20267,9 +20026,9 @@ var WebCall = (() => {
|
|
|
20267
20026
|
* set userstatus
|
|
20268
20027
|
* @param status
|
|
20269
20028
|
*/
|
|
20270
|
-
setUserStatus(status) {
|
|
20029
|
+
async setUserStatus(status) {
|
|
20271
20030
|
const { agentId } = this.config.getConfig().userInfo;
|
|
20272
|
-
this.api.updateUserStatus({
|
|
20031
|
+
await this.api.updateUserStatus({
|
|
20273
20032
|
agentId,
|
|
20274
20033
|
status
|
|
20275
20034
|
});
|