@bitrix24/b24jssdk 0.1.7 → 0.2.0
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/commonjs/index.cjs +421 -186
- package/dist/commonjs/index.cjs.map +1 -1
- package/dist/commonjs/index.d.cts +129 -68
- package/dist/commonjs/index.d.mts +129 -68
- package/dist/commonjs/index.d.ts +129 -68
- package/dist/esm/index.d.mts +129 -68
- package/dist/esm/index.d.ts +129 -68
- package/dist/esm/index.mjs +421 -186
- package/dist/esm/index.mjs.map +1 -1
- package/dist/umd/index.js +586 -528
- package/dist/umd/index.js.map +1 -1
- package/dist/umd/index.min.js +24 -18
- package/dist/umd/index.min.js.map +1 -1
- package/package.json +72 -76
package/dist/commonjs/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @version @bitrix24/b24jssdk v0.
|
|
2
|
+
* @version @bitrix24/b24jssdk v0.2.0
|
|
3
3
|
* @copyright (c) 2025 Bitrix24
|
|
4
4
|
* @licence MIT
|
|
5
5
|
* @links https://github.com/bitrix24/b24jssdk - GitHub
|
|
@@ -679,7 +679,6 @@ class TextManager {
|
|
|
679
679
|
return str;
|
|
680
680
|
}
|
|
681
681
|
const matches = str.match(
|
|
682
|
-
// eslint-disable-next-line
|
|
683
682
|
/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g
|
|
684
683
|
);
|
|
685
684
|
if (!matches) {
|
|
@@ -1048,75 +1047,42 @@ var RpcMethod = /* @__PURE__ */ ((RpcMethod2) => {
|
|
|
1048
1047
|
})(RpcMethod || {});
|
|
1049
1048
|
|
|
1050
1049
|
class Result {
|
|
1051
|
-
|
|
1050
|
+
_errors;
|
|
1052
1051
|
_data;
|
|
1053
|
-
constructor() {
|
|
1054
|
-
this.
|
|
1055
|
-
this._data = null;
|
|
1052
|
+
constructor(data) {
|
|
1053
|
+
this._errors = /* @__PURE__ */ new Map();
|
|
1054
|
+
this._data = data ?? null;
|
|
1056
1055
|
}
|
|
1057
|
-
/**
|
|
1058
|
-
* Getter for the `isSuccess` property.
|
|
1059
|
-
* Checks if the `_errorCollection` is empty to determine success.
|
|
1060
|
-
*
|
|
1061
|
-
* @returns Whether the operation resulted in success (no errors).
|
|
1062
|
-
*/
|
|
1063
1056
|
get isSuccess() {
|
|
1064
|
-
return this.
|
|
1057
|
+
return this._errors.size === 0;
|
|
1058
|
+
}
|
|
1059
|
+
get errors() {
|
|
1060
|
+
return this._errors;
|
|
1065
1061
|
}
|
|
1066
|
-
/**
|
|
1067
|
-
* Sets the data associated with the result.
|
|
1068
|
-
*
|
|
1069
|
-
* @param data The data to be stored in the result.
|
|
1070
|
-
* @returns The current Result object for chaining methods.
|
|
1071
|
-
*/
|
|
1072
1062
|
setData(data) {
|
|
1073
1063
|
this._data = data;
|
|
1074
1064
|
return this;
|
|
1075
1065
|
}
|
|
1076
|
-
/**
|
|
1077
|
-
* Retrieves the data associated with the result.
|
|
1078
|
-
*
|
|
1079
|
-
* @returns The data stored in the result, if any.
|
|
1080
|
-
*/
|
|
1081
1066
|
getData() {
|
|
1082
1067
|
return this._data;
|
|
1083
1068
|
}
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
* @returns The current Result object for chaining methods.
|
|
1089
|
-
*/
|
|
1090
|
-
addError(error) {
|
|
1091
|
-
if (error instanceof Error) {
|
|
1092
|
-
this._errorCollection.add(error);
|
|
1093
|
-
} else {
|
|
1094
|
-
this._errorCollection.add(new Error(error.toString()));
|
|
1095
|
-
}
|
|
1069
|
+
addError(error, key) {
|
|
1070
|
+
const errorKey = key ?? Text.getUuidRfc4122();
|
|
1071
|
+
const errorObj = typeof error === "string" ? new Error(error) : error;
|
|
1072
|
+
this._errors.set(errorKey, errorObj);
|
|
1096
1073
|
return this;
|
|
1097
1074
|
}
|
|
1098
|
-
/**
|
|
1099
|
-
* Adds multiple errors to the result in a single call.
|
|
1100
|
-
*
|
|
1101
|
-
* @param errors An array of errors or strings that will be converted to errors.
|
|
1102
|
-
* @returns The current Result object for chaining methods.
|
|
1103
|
-
*/
|
|
1104
1075
|
addErrors(errors) {
|
|
1105
1076
|
for (const error of errors) {
|
|
1106
|
-
|
|
1107
|
-
this._errorCollection.add(error);
|
|
1108
|
-
} else {
|
|
1109
|
-
this._errorCollection.add(new Error(error.toString()));
|
|
1110
|
-
}
|
|
1077
|
+
this.addError(error);
|
|
1111
1078
|
}
|
|
1112
1079
|
return this;
|
|
1113
1080
|
}
|
|
1114
|
-
/**
|
|
1115
|
-
* Retrieves an iterator for the errors collected in the result.
|
|
1116
|
-
* @returns An iterator over the stored Error objects.
|
|
1117
|
-
*/
|
|
1118
1081
|
getErrors() {
|
|
1119
|
-
return this.
|
|
1082
|
+
return this._errors.values();
|
|
1083
|
+
}
|
|
1084
|
+
hasError(key) {
|
|
1085
|
+
return this._errors.has(key);
|
|
1120
1086
|
}
|
|
1121
1087
|
/**
|
|
1122
1088
|
* Retrieves an array of error messages from the collected errors.
|
|
@@ -1125,7 +1091,7 @@ class Result {
|
|
|
1125
1091
|
* contains the message of a corresponding error object.
|
|
1126
1092
|
*/
|
|
1127
1093
|
getErrorMessages() {
|
|
1128
|
-
return
|
|
1094
|
+
return Array.from(this._errors.values(), (e) => e.message);
|
|
1129
1095
|
}
|
|
1130
1096
|
/**
|
|
1131
1097
|
* Converts the Result object to a string.
|
|
@@ -1133,36 +1099,168 @@ class Result {
|
|
|
1133
1099
|
* @returns {string} Returns a string representation of the result operation
|
|
1134
1100
|
*/
|
|
1135
1101
|
toString() {
|
|
1136
|
-
|
|
1137
|
-
|
|
1102
|
+
const status = this.isSuccess ? "success" : "failure";
|
|
1103
|
+
const data = this.safeStringify(this._data);
|
|
1104
|
+
return this.isSuccess ? `Result(${status}): ${data}` : `Result(${status}): ${data}
|
|
1105
|
+
Errors: ${this.getErrorMessages().join(", ")}`;
|
|
1106
|
+
}
|
|
1107
|
+
safeStringify(data) {
|
|
1108
|
+
try {
|
|
1109
|
+
return JSON.stringify(data, this.replacer, 2);
|
|
1110
|
+
} catch {
|
|
1111
|
+
return "[Unable to serialize data]";
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
replacer(_, value) {
|
|
1115
|
+
if (value instanceof Error) {
|
|
1116
|
+
return {
|
|
1117
|
+
name: value.name,
|
|
1118
|
+
message: value.message,
|
|
1119
|
+
stack: value.stack
|
|
1120
|
+
};
|
|
1138
1121
|
}
|
|
1139
|
-
return
|
|
1122
|
+
return value;
|
|
1123
|
+
}
|
|
1124
|
+
// Static constructors
|
|
1125
|
+
static ok(data) {
|
|
1126
|
+
return new Result(data);
|
|
1127
|
+
}
|
|
1128
|
+
static fail(error, key) {
|
|
1129
|
+
return new Result().addError(error, key);
|
|
1140
1130
|
}
|
|
1141
1131
|
}
|
|
1142
1132
|
|
|
1143
1133
|
class AjaxError extends Error {
|
|
1144
|
-
|
|
1134
|
+
code;
|
|
1145
1135
|
_status;
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1136
|
+
requestInfo;
|
|
1137
|
+
timestamp;
|
|
1138
|
+
originalError;
|
|
1139
|
+
// override cause: null | Error
|
|
1140
|
+
// private _status: number
|
|
1141
|
+
// private _answerError: AnswerError
|
|
1142
|
+
constructor(details) {
|
|
1143
|
+
const message = AjaxError.formatErrorMessage(details);
|
|
1149
1144
|
super(message);
|
|
1150
|
-
this.
|
|
1151
|
-
this.
|
|
1152
|
-
this._status =
|
|
1153
|
-
this.
|
|
1154
|
-
|
|
1145
|
+
this.name = "AjaxError";
|
|
1146
|
+
this.code = details.code;
|
|
1147
|
+
this._status = details.status;
|
|
1148
|
+
this.requestInfo = details.requestInfo;
|
|
1149
|
+
this.originalError = details.originalError;
|
|
1150
|
+
this.timestamp = /* @__PURE__ */ new Date();
|
|
1151
|
+
this.cleanErrorStack();
|
|
1152
|
+
}
|
|
1153
|
+
// constructor(params: AjaxErrorParams) {
|
|
1154
|
+
// const message = `${ params.answerError.error }${
|
|
1155
|
+
// params.answerError.errorDescription
|
|
1156
|
+
// ? ': ' + params.answerError.errorDescription
|
|
1157
|
+
// : ''
|
|
1158
|
+
// }`
|
|
1159
|
+
//
|
|
1160
|
+
// super(message)
|
|
1161
|
+
// this.cause = params.cause || null
|
|
1162
|
+
// this.name = this.constructor.name
|
|
1163
|
+
//
|
|
1164
|
+
// this._status = params.status
|
|
1165
|
+
// this._answerError = params.answerError
|
|
1166
|
+
// }
|
|
1167
|
+
/**
|
|
1168
|
+
* @deprecated
|
|
1169
|
+
*/
|
|
1155
1170
|
get answerError() {
|
|
1156
|
-
return
|
|
1171
|
+
return {
|
|
1172
|
+
error: this.message,
|
|
1173
|
+
errorDescription: ""
|
|
1174
|
+
};
|
|
1157
1175
|
}
|
|
1158
1176
|
get status() {
|
|
1159
1177
|
return this._status;
|
|
1160
1178
|
}
|
|
1179
|
+
/**
|
|
1180
|
+
* @deprecated
|
|
1181
|
+
*/
|
|
1161
1182
|
set status(status) {
|
|
1162
1183
|
this._status = status;
|
|
1163
1184
|
}
|
|
1185
|
+
/**
|
|
1186
|
+
* Creates AjaxError from HTTP response
|
|
1187
|
+
*/
|
|
1188
|
+
static fromResponse(response) {
|
|
1189
|
+
return new AjaxError({
|
|
1190
|
+
code: response.data?.error || "unknown_error",
|
|
1191
|
+
description: response.data?.error_description,
|
|
1192
|
+
status: response.status,
|
|
1193
|
+
requestInfo: {
|
|
1194
|
+
method: response.config?.method?.toUpperCase(),
|
|
1195
|
+
url: response.config?.url,
|
|
1196
|
+
params: response.config?.params
|
|
1197
|
+
}
|
|
1198
|
+
});
|
|
1199
|
+
}
|
|
1200
|
+
/**
|
|
1201
|
+
* Creates AjaxError from exception
|
|
1202
|
+
*/
|
|
1203
|
+
static fromException(error, context) {
|
|
1204
|
+
if (error instanceof AjaxError) return error;
|
|
1205
|
+
return new AjaxError({
|
|
1206
|
+
code: context?.code || "internal_error",
|
|
1207
|
+
status: context?.status || 500,
|
|
1208
|
+
description: error instanceof Error ? error.message : String(error),
|
|
1209
|
+
requestInfo: context?.requestInfo,
|
|
1210
|
+
originalError: error
|
|
1211
|
+
});
|
|
1212
|
+
}
|
|
1213
|
+
/**
|
|
1214
|
+
* Serializes error for logging and debugging
|
|
1215
|
+
*/
|
|
1216
|
+
toJSON() {
|
|
1217
|
+
return {
|
|
1218
|
+
name: this.name,
|
|
1219
|
+
code: this.code,
|
|
1220
|
+
message: this.message,
|
|
1221
|
+
status: this._status,
|
|
1222
|
+
timestamp: this.timestamp.toISOString(),
|
|
1223
|
+
requestInfo: this.requestInfo,
|
|
1224
|
+
stack: this.stack
|
|
1225
|
+
};
|
|
1226
|
+
}
|
|
1227
|
+
// override toString(): string {
|
|
1228
|
+
// return `${ this.answerError.error }${
|
|
1229
|
+
// this.answerError.errorDescription
|
|
1230
|
+
// ? ': ' + this.answerError.errorDescription
|
|
1231
|
+
// : ''
|
|
1232
|
+
// } (${ this.status })`
|
|
1233
|
+
// }
|
|
1234
|
+
/**
|
|
1235
|
+
* Formats error information for human-readable output
|
|
1236
|
+
*/
|
|
1164
1237
|
toString() {
|
|
1165
|
-
|
|
1238
|
+
let output = `[${this.name}] ${this.code} (${this._status}): ${this.message}`;
|
|
1239
|
+
if (this.requestInfo) {
|
|
1240
|
+
output += `
|
|
1241
|
+
Request: ${this.requestInfo.method} ${this.requestInfo.url}`;
|
|
1242
|
+
}
|
|
1243
|
+
if (this.stack) {
|
|
1244
|
+
output += `
|
|
1245
|
+
Stack trace:
|
|
1246
|
+
${this.stack}`;
|
|
1247
|
+
}
|
|
1248
|
+
return output;
|
|
1249
|
+
}
|
|
1250
|
+
static formatErrorMessage(details) {
|
|
1251
|
+
const parts = [details.code];
|
|
1252
|
+
if (details.description) {
|
|
1253
|
+
parts.push(`- ${details.description}`);
|
|
1254
|
+
}
|
|
1255
|
+
if (details.requestInfo?.method && details.requestInfo.url) {
|
|
1256
|
+
parts.push(`(on ${details.requestInfo.method} ${details.requestInfo.url})`);
|
|
1257
|
+
}
|
|
1258
|
+
return parts.join(" ");
|
|
1259
|
+
}
|
|
1260
|
+
cleanErrorStack() {
|
|
1261
|
+
if (typeof this.stack === "string") {
|
|
1262
|
+
this.stack = this.stack.split("\n").filter((line) => !line.includes("AjaxError.constructor")).join("\n");
|
|
1263
|
+
}
|
|
1166
1264
|
}
|
|
1167
1265
|
}
|
|
1168
1266
|
|
|
@@ -1170,31 +1268,48 @@ class AjaxResult extends Result {
|
|
|
1170
1268
|
_status;
|
|
1171
1269
|
_query;
|
|
1172
1270
|
_data;
|
|
1173
|
-
constructor(
|
|
1271
|
+
constructor(options) {
|
|
1174
1272
|
super();
|
|
1175
|
-
this._data = answer;
|
|
1176
|
-
this._query = structuredClone(query);
|
|
1177
|
-
this._status = status;
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1273
|
+
this._data = Object.freeze(options.answer);
|
|
1274
|
+
this._query = Object.freeze(structuredClone(options.query));
|
|
1275
|
+
this._status = options.status;
|
|
1276
|
+
this.#processErrors();
|
|
1277
|
+
}
|
|
1278
|
+
#processErrors() {
|
|
1279
|
+
const { error } = this._data;
|
|
1280
|
+
if (!error) return;
|
|
1281
|
+
const errorParams = this.#normalizeError(error);
|
|
1282
|
+
this.addError(this.#createAjaxError(errorParams), "base-error");
|
|
1283
|
+
}
|
|
1284
|
+
#normalizeError(error) {
|
|
1285
|
+
return typeof error === "string" ? { code: error, description: this._data.error_description || "" } : { code: error.error, description: error.error_description || "" };
|
|
1286
|
+
}
|
|
1287
|
+
#createAjaxError(params) {
|
|
1288
|
+
return new AjaxError({
|
|
1289
|
+
code: String(this._status),
|
|
1290
|
+
description: params.description,
|
|
1291
|
+
status: this._status,
|
|
1292
|
+
requestInfo: {
|
|
1293
|
+
method: this._query.method,
|
|
1294
|
+
// url: '?',
|
|
1295
|
+
params: this._query.params
|
|
1296
|
+
}
|
|
1297
|
+
// request:
|
|
1298
|
+
});
|
|
1195
1299
|
}
|
|
1196
1300
|
getData() {
|
|
1197
|
-
return
|
|
1301
|
+
return Object.freeze({
|
|
1302
|
+
result: this._data.result,
|
|
1303
|
+
next: this._data.next,
|
|
1304
|
+
total: this._data.total,
|
|
1305
|
+
time: this._data.time
|
|
1306
|
+
});
|
|
1307
|
+
}
|
|
1308
|
+
/**
|
|
1309
|
+
* Alias for isMore
|
|
1310
|
+
*/
|
|
1311
|
+
hasMore() {
|
|
1312
|
+
return this.isMore();
|
|
1198
1313
|
}
|
|
1199
1314
|
isMore() {
|
|
1200
1315
|
return Type.isNumber(this._data?.next);
|
|
@@ -1208,16 +1323,35 @@ class AjaxResult extends Result {
|
|
|
1208
1323
|
getQuery() {
|
|
1209
1324
|
return this._query;
|
|
1210
1325
|
}
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1326
|
+
/**
|
|
1327
|
+
* Alias for getNext
|
|
1328
|
+
* @param http
|
|
1329
|
+
*/
|
|
1330
|
+
async fetchNext(http) {
|
|
1331
|
+
const data = await this.getNext(http);
|
|
1332
|
+
if (data === false) {
|
|
1333
|
+
return null;
|
|
1219
1334
|
}
|
|
1220
|
-
return
|
|
1335
|
+
return data;
|
|
1336
|
+
}
|
|
1337
|
+
async getNext(http) {
|
|
1338
|
+
if (!this.isMore() || !this.isSuccess) return false;
|
|
1339
|
+
const nextPageQuery = this.#buildNextPageQuery();
|
|
1340
|
+
return http.call(
|
|
1341
|
+
nextPageQuery.method,
|
|
1342
|
+
nextPageQuery.params,
|
|
1343
|
+
nextPageQuery.start
|
|
1344
|
+
);
|
|
1345
|
+
}
|
|
1346
|
+
#buildNextPageQuery() {
|
|
1347
|
+
return {
|
|
1348
|
+
...this._query,
|
|
1349
|
+
start: Text.toInteger(this._data.next)
|
|
1350
|
+
};
|
|
1351
|
+
}
|
|
1352
|
+
// Immutable API
|
|
1353
|
+
setData() {
|
|
1354
|
+
throw new ReferenceError("AjaxResult does not allow data modification");
|
|
1221
1355
|
}
|
|
1222
1356
|
}
|
|
1223
1357
|
|
|
@@ -1404,33 +1538,37 @@ class Http {
|
|
|
1404
1538
|
// endregion ////
|
|
1405
1539
|
// region Actions Call ////
|
|
1406
1540
|
async batch(calls, isHaltOnError = true) {
|
|
1407
|
-
|
|
1408
|
-
|
|
1541
|
+
if (Array.isArray(calls)) {
|
|
1542
|
+
return this.#batchAsArray(
|
|
1543
|
+
calls,
|
|
1544
|
+
isHaltOnError
|
|
1545
|
+
);
|
|
1546
|
+
}
|
|
1547
|
+
return this.#batchAsObject(
|
|
1548
|
+
calls,
|
|
1549
|
+
isHaltOnError
|
|
1550
|
+
);
|
|
1551
|
+
}
|
|
1552
|
+
async #batchAsObject(calls, isHaltOnError = true) {
|
|
1553
|
+
const cmd = {};
|
|
1409
1554
|
let cnt = 0;
|
|
1410
1555
|
const processRow = (row, index) => {
|
|
1411
1556
|
let method = null;
|
|
1412
1557
|
let params = null;
|
|
1413
|
-
if (
|
|
1414
|
-
method = row
|
|
1415
|
-
params = row
|
|
1416
|
-
} else if (row.
|
|
1417
|
-
method = row
|
|
1418
|
-
params = row
|
|
1558
|
+
if (row.method) {
|
|
1559
|
+
method = row.method ?? null;
|
|
1560
|
+
params = row?.params ?? null;
|
|
1561
|
+
} else if (Array.isArray(row) && row.length > 0) {
|
|
1562
|
+
method = row[0] ?? null;
|
|
1563
|
+
params = row[1] ?? null;
|
|
1419
1564
|
}
|
|
1420
1565
|
if (method) {
|
|
1421
1566
|
cnt++;
|
|
1422
|
-
|
|
1423
|
-
if (isArrayMode || Array.isArray(cmd)) {
|
|
1424
|
-
cmd.push(data);
|
|
1425
|
-
} else {
|
|
1426
|
-
cmd[index] = data;
|
|
1427
|
-
}
|
|
1567
|
+
cmd[index] = method + "?" + qs__namespace.stringify(params);
|
|
1428
1568
|
}
|
|
1429
1569
|
};
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
} else {
|
|
1433
|
-
for (const [index, item] of Object.entries(calls)) processRow(item, index);
|
|
1570
|
+
for (const [index, row] of Object.entries(calls)) {
|
|
1571
|
+
processRow(row, index);
|
|
1434
1572
|
}
|
|
1435
1573
|
if (cnt < 1) {
|
|
1436
1574
|
return Promise.resolve(new Result());
|
|
@@ -1440,7 +1578,7 @@ class Http {
|
|
|
1440
1578
|
cmd
|
|
1441
1579
|
}).then((response) => {
|
|
1442
1580
|
const responseResult = response.getData().result;
|
|
1443
|
-
const results =
|
|
1581
|
+
const results = {};
|
|
1444
1582
|
const processResponse = (row, index) => {
|
|
1445
1583
|
if (
|
|
1446
1584
|
// @ts-ignore
|
|
@@ -1448,8 +1586,8 @@ class Http {
|
|
|
1448
1586
|
typeof responseResult.result_error[index] !== "undefined"
|
|
1449
1587
|
) {
|
|
1450
1588
|
const q = row.split("?");
|
|
1451
|
-
|
|
1452
|
-
{
|
|
1589
|
+
results[index] = new AjaxResult({
|
|
1590
|
+
answer: {
|
|
1453
1591
|
// @ts-ignore
|
|
1454
1592
|
result: Type.isUndefined(responseResult.result[index]) ? (
|
|
1455
1593
|
// @ts-ignore
|
|
@@ -1463,67 +1601,154 @@ class Http {
|
|
|
1463
1601
|
// @ts-ignore
|
|
1464
1602
|
total: responseResult.result_total[index],
|
|
1465
1603
|
// @ts-ignore
|
|
1466
|
-
next: responseResult.result_next[index]
|
|
1604
|
+
next: responseResult.result_next[index],
|
|
1605
|
+
// @todo test this ////
|
|
1606
|
+
// @ts-ignore
|
|
1607
|
+
time: responseResult.result_time[index]
|
|
1467
1608
|
},
|
|
1468
|
-
{
|
|
1609
|
+
query: {
|
|
1469
1610
|
method: q[0] || "",
|
|
1470
1611
|
params: qs__namespace.parse(q[1] || ""),
|
|
1471
1612
|
start: 0
|
|
1472
1613
|
},
|
|
1473
|
-
response.getStatus()
|
|
1474
|
-
);
|
|
1475
|
-
if (isArrayMode || Array.isArray(results)) {
|
|
1476
|
-
results.push(data);
|
|
1477
|
-
} else {
|
|
1478
|
-
results[index] = data;
|
|
1479
|
-
}
|
|
1614
|
+
status: response.getStatus()
|
|
1615
|
+
});
|
|
1480
1616
|
}
|
|
1481
1617
|
};
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
} else {
|
|
1485
|
-
for (const [index, item] of Object.entries(cmd))
|
|
1486
|
-
processResponse(item, index);
|
|
1618
|
+
for (const [index, row] of Object.entries(cmd)) {
|
|
1619
|
+
processResponse(row, index);
|
|
1487
1620
|
}
|
|
1488
|
-
|
|
1621
|
+
const dataResult = {};
|
|
1489
1622
|
const initError = (result2) => {
|
|
1623
|
+
if (result2.hasError("base-error")) {
|
|
1624
|
+
return result2.errors.get("base-error");
|
|
1625
|
+
}
|
|
1490
1626
|
return new AjaxError({
|
|
1627
|
+
code: "0",
|
|
1628
|
+
description: result2.getErrorMessages().join("; "),
|
|
1491
1629
|
status: 0,
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1630
|
+
requestInfo: {
|
|
1631
|
+
method: result2.getQuery().method,
|
|
1632
|
+
params: result2.getQuery().params
|
|
1495
1633
|
},
|
|
1496
|
-
|
|
1634
|
+
originalError: result2.getErrors().next().value
|
|
1497
1635
|
});
|
|
1498
1636
|
};
|
|
1499
1637
|
const result = new Result();
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
continue;
|
|
1508
|
-
}
|
|
1509
|
-
return Promise.reject(error);
|
|
1638
|
+
for (const key of Object.keys(results)) {
|
|
1639
|
+
const data = results[key];
|
|
1640
|
+
if (data.getStatus() !== 200 || !data.isSuccess) {
|
|
1641
|
+
const error = initError(data);
|
|
1642
|
+
if (!isHaltOnError && !data.isSuccess) {
|
|
1643
|
+
result.addError(error, key);
|
|
1644
|
+
continue;
|
|
1510
1645
|
}
|
|
1511
|
-
|
|
1646
|
+
return Promise.reject(error);
|
|
1512
1647
|
}
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1648
|
+
dataResult[key] = data.getData().result;
|
|
1649
|
+
}
|
|
1650
|
+
result.setData(dataResult);
|
|
1651
|
+
return Promise.resolve(result);
|
|
1652
|
+
});
|
|
1653
|
+
}
|
|
1654
|
+
async #batchAsArray(calls, isHaltOnError = true) {
|
|
1655
|
+
const cmd = [];
|
|
1656
|
+
let cnt = 0;
|
|
1657
|
+
const processRow = (row) => {
|
|
1658
|
+
let method = null;
|
|
1659
|
+
let params = null;
|
|
1660
|
+
if (row.method) {
|
|
1661
|
+
method = row.method ?? null;
|
|
1662
|
+
params = row?.params ?? null;
|
|
1663
|
+
} else if (Array.isArray(row) && row.length > 0) {
|
|
1664
|
+
method = row[0] ?? null;
|
|
1665
|
+
params = row[1] ?? null;
|
|
1666
|
+
}
|
|
1667
|
+
if (method) {
|
|
1668
|
+
cnt++;
|
|
1669
|
+
const data = method + "?" + qs__namespace.stringify(params);
|
|
1670
|
+
cmd.push(data);
|
|
1671
|
+
}
|
|
1672
|
+
};
|
|
1673
|
+
for (const [_, row] of calls.entries()) {
|
|
1674
|
+
processRow(row);
|
|
1675
|
+
}
|
|
1676
|
+
if (cnt < 1) {
|
|
1677
|
+
return Promise.resolve(new Result());
|
|
1678
|
+
}
|
|
1679
|
+
return this.call("batch", {
|
|
1680
|
+
halt: isHaltOnError ? 1 : 0,
|
|
1681
|
+
cmd
|
|
1682
|
+
}).then((response) => {
|
|
1683
|
+
const responseResult = response.getData().result;
|
|
1684
|
+
const results = [];
|
|
1685
|
+
const processResponse = (row, index) => {
|
|
1686
|
+
if (
|
|
1687
|
+
// @ts-ignore
|
|
1688
|
+
typeof responseResult.result[index] !== "undefined" || // @ts-ignore
|
|
1689
|
+
typeof responseResult.result_error[index] !== "undefined"
|
|
1690
|
+
) {
|
|
1691
|
+
const q = row.split("?");
|
|
1692
|
+
const data = new AjaxResult({
|
|
1693
|
+
answer: {
|
|
1694
|
+
// @ts-ignore
|
|
1695
|
+
result: Type.isUndefined(responseResult.result[index]) ? (
|
|
1696
|
+
// @ts-ignore
|
|
1697
|
+
{}
|
|
1698
|
+
) : (
|
|
1699
|
+
// @ts-ignore
|
|
1700
|
+
responseResult.result[index]
|
|
1701
|
+
),
|
|
1702
|
+
// @ts-ignore
|
|
1703
|
+
error: responseResult?.result_error[index] || void 0,
|
|
1704
|
+
// @ts-ignore
|
|
1705
|
+
total: responseResult.result_total[index],
|
|
1706
|
+
// @ts-ignore
|
|
1707
|
+
next: responseResult.result_next[index],
|
|
1708
|
+
// @todo test this ////
|
|
1709
|
+
// @ts-ignore
|
|
1710
|
+
time: responseResult.result_time[index]
|
|
1711
|
+
},
|
|
1712
|
+
query: {
|
|
1713
|
+
method: q[0] || "",
|
|
1714
|
+
params: qs__namespace.parse(q[1] || ""),
|
|
1715
|
+
start: 0
|
|
1716
|
+
},
|
|
1717
|
+
status: response.getStatus()
|
|
1718
|
+
});
|
|
1719
|
+
results.push(data);
|
|
1720
|
+
}
|
|
1721
|
+
};
|
|
1722
|
+
for (const [index, row] of cmd.entries()) {
|
|
1723
|
+
processResponse(row, index);
|
|
1724
|
+
}
|
|
1725
|
+
const dataResult = [];
|
|
1726
|
+
const initError = (result2) => {
|
|
1727
|
+
if (result2.hasError("base-error")) {
|
|
1728
|
+
return result2.errors.get("base-error");
|
|
1729
|
+
}
|
|
1730
|
+
return new AjaxError({
|
|
1731
|
+
code: "0",
|
|
1732
|
+
description: result2.getErrorMessages().join("; "),
|
|
1733
|
+
status: 0,
|
|
1734
|
+
requestInfo: {
|
|
1735
|
+
method: result2.getQuery().method,
|
|
1736
|
+
params: result2.getQuery().params
|
|
1737
|
+
},
|
|
1738
|
+
originalError: result2.getErrors().next().value
|
|
1739
|
+
});
|
|
1740
|
+
};
|
|
1741
|
+
const result = new Result();
|
|
1742
|
+
for (const data of results) {
|
|
1743
|
+
if (data.getStatus() !== 200 || !data.isSuccess) {
|
|
1744
|
+
const error = initError(data);
|
|
1745
|
+
if (!isHaltOnError && !data.isSuccess) {
|
|
1746
|
+
result.addError(error);
|
|
1747
|
+
continue;
|
|
1524
1748
|
}
|
|
1525
|
-
|
|
1749
|
+
return Promise.reject(error);
|
|
1526
1750
|
}
|
|
1751
|
+
dataResult.push(data.getData().result);
|
|
1527
1752
|
}
|
|
1528
1753
|
result.setData(dataResult);
|
|
1529
1754
|
return Promise.resolve(result);
|
|
@@ -1571,9 +1796,14 @@ class Http {
|
|
|
1571
1796
|
};
|
|
1572
1797
|
}
|
|
1573
1798
|
const problemError = new AjaxError({
|
|
1799
|
+
code: String(answerError.error),
|
|
1800
|
+
description: answerError.errorDescription,
|
|
1574
1801
|
status: error_.response?.status || 0,
|
|
1575
|
-
|
|
1576
|
-
|
|
1802
|
+
requestInfo: {
|
|
1803
|
+
method,
|
|
1804
|
+
params
|
|
1805
|
+
},
|
|
1806
|
+
originalError: error_
|
|
1577
1807
|
});
|
|
1578
1808
|
if (problemError.status === 401 && ["expired_token", "invalid_token"].includes(
|
|
1579
1809
|
problemError.answerError.error
|
|
@@ -1607,9 +1837,14 @@ class Http {
|
|
|
1607
1837
|
};
|
|
1608
1838
|
}
|
|
1609
1839
|
const problemError2 = new AjaxError({
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1840
|
+
code: String(answerError2.error),
|
|
1841
|
+
description: answerError2.errorDescription,
|
|
1842
|
+
status: error_.response?.status || 0,
|
|
1843
|
+
requestInfo: {
|
|
1844
|
+
method,
|
|
1845
|
+
params
|
|
1846
|
+
},
|
|
1847
|
+
originalError: error__
|
|
1613
1848
|
});
|
|
1614
1849
|
return Promise.reject(problemError2);
|
|
1615
1850
|
}
|
|
@@ -1618,15 +1853,15 @@ class Http {
|
|
|
1618
1853
|
return Promise.reject(problemError);
|
|
1619
1854
|
}
|
|
1620
1855
|
).then((response) => {
|
|
1621
|
-
const result = new AjaxResult(
|
|
1622
|
-
response.payload,
|
|
1623
|
-
{
|
|
1856
|
+
const result = new AjaxResult({
|
|
1857
|
+
answer: response.payload,
|
|
1858
|
+
query: {
|
|
1624
1859
|
method,
|
|
1625
1860
|
params,
|
|
1626
1861
|
start
|
|
1627
1862
|
},
|
|
1628
|
-
response.status
|
|
1629
|
-
);
|
|
1863
|
+
status: response.status
|
|
1864
|
+
});
|
|
1630
1865
|
return Promise.resolve(result);
|
|
1631
1866
|
});
|
|
1632
1867
|
}
|
|
@@ -1647,7 +1882,7 @@ class Http {
|
|
|
1647
1882
|
result.logTag = this.#logTag;
|
|
1648
1883
|
}
|
|
1649
1884
|
result[this.#requestIdGenerator.getQueryStringParameterName()] = this.#requestIdGenerator.getRequestId();
|
|
1650
|
-
result[this.#requestIdGenerator.getQueryStringSdkParameterName()] = "0.
|
|
1885
|
+
result[this.#requestIdGenerator.getQueryStringSdkParameterName()] = "0.2.0";
|
|
1651
1886
|
if (!!result.data && !!result.data.start) {
|
|
1652
1887
|
delete result.data.start;
|
|
1653
1888
|
}
|
|
@@ -11619,7 +11854,7 @@ class PullClient {
|
|
|
11619
11854
|
}
|
|
11620
11855
|
if (message.extra.server_time_unix) {
|
|
11621
11856
|
message.extra.server_time_ago = (Date.now() - message.extra.server_time_unix * 1e3) / 1e3 - (this._config?.server.timeShift || 0);
|
|
11622
|
-
message.extra.server_time_ago =
|
|
11857
|
+
message.extra.server_time_ago = Math.max(message.extra.server_time_ago, 0);
|
|
11623
11858
|
}
|
|
11624
11859
|
this.logMessage(message);
|
|
11625
11860
|
try {
|
|
@@ -12685,7 +12920,7 @@ Data string: ${pullEvent}
|
|
|
12685
12920
|
}
|
|
12686
12921
|
trimDuplicates() {
|
|
12687
12922
|
if (this._session.lastMessageIds.length > MAX_IDS_TO_STORE) {
|
|
12688
|
-
this._session.lastMessageIds = this._session.lastMessageIds.slice(-
|
|
12923
|
+
this._session.lastMessageIds = this._session.lastMessageIds.slice(-10);
|
|
12689
12924
|
}
|
|
12690
12925
|
}
|
|
12691
12926
|
// endregion ////
|
|
@@ -12763,19 +12998,19 @@ Data string: ${pullEvent}
|
|
|
12763
12998
|
* @deprecated
|
|
12764
12999
|
*/
|
|
12765
13000
|
/*/
|
|
12766
|
-
|
|
12767
|
-
|
|
12768
|
-
|
|
13001
|
+
getRestClientOptions()
|
|
13002
|
+
{
|
|
13003
|
+
let result = {};
|
|
12769
13004
|
|
|
12770
|
-
|
|
12771
|
-
|
|
12772
|
-
|
|
12773
|
-
|
|
12774
|
-
|
|
12775
|
-
|
|
12776
|
-
|
|
12777
|
-
|
|
12778
|
-
|
|
13005
|
+
if (this.guestMode && this.guestUserId !== 0)
|
|
13006
|
+
{
|
|
13007
|
+
result.queryParams = {
|
|
13008
|
+
pull_guest_id: this.guestUserId
|
|
13009
|
+
}
|
|
13010
|
+
}
|
|
13011
|
+
return result;
|
|
13012
|
+
}
|
|
13013
|
+
//*/
|
|
12779
13014
|
// endregion ////
|
|
12780
13015
|
}
|
|
12781
13016
|
|