@signaliz/sdk 1.0.42 → 1.0.44
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/{chunk-B4OMGBD5.mjs → chunk-Q4T2GUXD.mjs} +51 -3
- package/dist/index.js +51 -3
- package/dist/index.mjs +1 -1
- package/dist/mcp-config.js +51 -3
- package/dist/mcp-config.mjs +1 -1
- package/package.json +1 -1
|
@@ -18,7 +18,7 @@ function parseError(status, body) {
|
|
|
18
18
|
code: body.error.code || `HTTP_${status}`,
|
|
19
19
|
message: body.error.message || `Request failed with status ${status}`,
|
|
20
20
|
errorType: mapErrorType(body.error.code, status),
|
|
21
|
-
retryAfter: body.error
|
|
21
|
+
retryAfter: retryAfterSeconds(body.error),
|
|
22
22
|
details: body.error.details
|
|
23
23
|
});
|
|
24
24
|
}
|
|
@@ -27,9 +27,22 @@ function parseError(status, body) {
|
|
|
27
27
|
code,
|
|
28
28
|
message: body?.message || body?.error || `Request failed with status ${status}`,
|
|
29
29
|
errorType: mapErrorType(code, status),
|
|
30
|
-
|
|
30
|
+
retryAfter: retryAfterSeconds(body),
|
|
31
|
+
details: body?.details || publicRetryDetails(body)
|
|
31
32
|
});
|
|
32
33
|
}
|
|
34
|
+
function retryAfterSeconds(body) {
|
|
35
|
+
const value = Number(body?.retry_after_seconds ?? body?.retry_after);
|
|
36
|
+
return Number.isFinite(value) && value >= 0 ? value : void 0;
|
|
37
|
+
}
|
|
38
|
+
function publicRetryDetails(body) {
|
|
39
|
+
const details = {
|
|
40
|
+
...body?.retry_eligible !== void 0 ? { retry_eligible: body.retry_eligible } : {},
|
|
41
|
+
...body?.retry_after !== void 0 ? { retry_after: body.retry_after } : {},
|
|
42
|
+
...body?.retry_after_seconds !== void 0 ? { retry_after_seconds: body.retry_after_seconds } : {}
|
|
43
|
+
};
|
|
44
|
+
return Object.keys(details).length > 0 ? details : void 0;
|
|
45
|
+
}
|
|
33
46
|
function mapErrorType(code, status) {
|
|
34
47
|
if (code === "RATE_LIMITED" || status === 429) return "rate_limited";
|
|
35
48
|
if (code === "VALIDATION_ERROR" || code === "SIGNAL_RUN_COMPANY_MISMATCH" || status === 400) return "validation";
|
|
@@ -358,6 +371,7 @@ function mapErrorTypeFromCode(code) {
|
|
|
358
371
|
}
|
|
359
372
|
|
|
360
373
|
// src/index.ts
|
|
374
|
+
var MAX_ROW_RATE_LIMIT_RETRIES = 2;
|
|
361
375
|
var Signaliz = class {
|
|
362
376
|
constructor(config) {
|
|
363
377
|
this.client = new HttpClient(config);
|
|
@@ -753,7 +767,7 @@ var Signaliz = class {
|
|
|
753
767
|
}
|
|
754
768
|
return results;
|
|
755
769
|
}
|
|
756
|
-
async runCoreBatchRound(path, tasks, options, companyRecoverableBatch) {
|
|
770
|
+
async runCoreBatchRound(path, tasks, options, companyRecoverableBatch, rowRateLimitAttempt = 0) {
|
|
757
771
|
const { serverConcurrency, chunkConcurrency } = batchConcurrencyPlan(options);
|
|
758
772
|
const deduplicated = dedupeExactBatchItems(tasks, (task) => JSON.stringify(task.request));
|
|
759
773
|
const uniqueTasks = deduplicated.uniqueItems;
|
|
@@ -818,6 +832,25 @@ var Signaliz = class {
|
|
|
818
832
|
};
|
|
819
833
|
}
|
|
820
834
|
}
|
|
835
|
+
if (rowRateLimitAttempt < MAX_ROW_RATE_LIMIT_RETRIES) {
|
|
836
|
+
const retryTasks = uniqueTasks.filter((_, index) => isRetryableRowRateLimit(uniqueResults[index]));
|
|
837
|
+
if (retryTasks.length > 0) {
|
|
838
|
+
const retryItems = uniqueResults.filter(isRetryableRowRateLimit);
|
|
839
|
+
await sleep2(rowRateLimitDelayMs(retryItems));
|
|
840
|
+
const retried = await this.runCoreBatchRound(
|
|
841
|
+
path,
|
|
842
|
+
retryTasks,
|
|
843
|
+
options,
|
|
844
|
+
void 0,
|
|
845
|
+
rowRateLimitAttempt + 1
|
|
846
|
+
);
|
|
847
|
+
const retriedByIndex = new Map(retried.map((item) => [item.index, item]));
|
|
848
|
+
for (let index = 0; index < uniqueResults.length; index += 1) {
|
|
849
|
+
const replacement = retriedByIndex.get(uniqueResults[index].index);
|
|
850
|
+
if (replacement) uniqueResults[index] = replacement;
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
}
|
|
821
854
|
return tasks.map((task, index) => ({
|
|
822
855
|
...uniqueResults[deduplicated.sourceIndexByInput[index]],
|
|
823
856
|
index: task.index
|
|
@@ -835,6 +868,21 @@ var Signaliz = class {
|
|
|
835
868
|
};
|
|
836
869
|
}
|
|
837
870
|
};
|
|
871
|
+
function isRetryableRowRateLimit(item) {
|
|
872
|
+
if (!item || item.success || !item.raw || item.raw.retry_eligible === false) return false;
|
|
873
|
+
const code = String(item.raw.error_code || item.raw.code || "").trim().toUpperCase();
|
|
874
|
+
return code === "RATE_LIMITED" || /^RATE_\d+$/.test(code);
|
|
875
|
+
}
|
|
876
|
+
function rowRateLimitDelayMs(items) {
|
|
877
|
+
const delays = items.map((item) => {
|
|
878
|
+
const retryAfterMs = Number(item.raw?.retry_after_ms);
|
|
879
|
+
if (Number.isFinite(retryAfterMs) && retryAfterMs > 0) return retryAfterMs;
|
|
880
|
+
const retryAfterSeconds2 = Number(item.raw?.retry_after_seconds ?? item.raw?.retry_after);
|
|
881
|
+
if (Number.isFinite(retryAfterSeconds2) && retryAfterSeconds2 > 0) return retryAfterSeconds2 * 1e3;
|
|
882
|
+
return 6e4;
|
|
883
|
+
});
|
|
884
|
+
return Math.max(1, Math.min(6e4, Math.max(...delays)));
|
|
885
|
+
}
|
|
838
886
|
function recoverableJobRowFailed(row) {
|
|
839
887
|
return row.success === false || ["failed", "skipped"].includes(String(row._status || "").toLowerCase());
|
|
840
888
|
}
|
package/dist/index.js
CHANGED
|
@@ -45,7 +45,7 @@ function parseError(status, body) {
|
|
|
45
45
|
code: body.error.code || `HTTP_${status}`,
|
|
46
46
|
message: body.error.message || `Request failed with status ${status}`,
|
|
47
47
|
errorType: mapErrorType(body.error.code, status),
|
|
48
|
-
retryAfter: body.error
|
|
48
|
+
retryAfter: retryAfterSeconds(body.error),
|
|
49
49
|
details: body.error.details
|
|
50
50
|
});
|
|
51
51
|
}
|
|
@@ -54,9 +54,22 @@ function parseError(status, body) {
|
|
|
54
54
|
code,
|
|
55
55
|
message: body?.message || body?.error || `Request failed with status ${status}`,
|
|
56
56
|
errorType: mapErrorType(code, status),
|
|
57
|
-
|
|
57
|
+
retryAfter: retryAfterSeconds(body),
|
|
58
|
+
details: body?.details || publicRetryDetails(body)
|
|
58
59
|
});
|
|
59
60
|
}
|
|
61
|
+
function retryAfterSeconds(body) {
|
|
62
|
+
const value = Number(body?.retry_after_seconds ?? body?.retry_after);
|
|
63
|
+
return Number.isFinite(value) && value >= 0 ? value : void 0;
|
|
64
|
+
}
|
|
65
|
+
function publicRetryDetails(body) {
|
|
66
|
+
const details = {
|
|
67
|
+
...body?.retry_eligible !== void 0 ? { retry_eligible: body.retry_eligible } : {},
|
|
68
|
+
...body?.retry_after !== void 0 ? { retry_after: body.retry_after } : {},
|
|
69
|
+
...body?.retry_after_seconds !== void 0 ? { retry_after_seconds: body.retry_after_seconds } : {}
|
|
70
|
+
};
|
|
71
|
+
return Object.keys(details).length > 0 ? details : void 0;
|
|
72
|
+
}
|
|
60
73
|
function mapErrorType(code, status) {
|
|
61
74
|
if (code === "RATE_LIMITED" || status === 429) return "rate_limited";
|
|
62
75
|
if (code === "VALIDATION_ERROR" || code === "SIGNAL_RUN_COMPANY_MISMATCH" || status === 400) return "validation";
|
|
@@ -385,6 +398,7 @@ function mapErrorTypeFromCode(code) {
|
|
|
385
398
|
}
|
|
386
399
|
|
|
387
400
|
// src/index.ts
|
|
401
|
+
var MAX_ROW_RATE_LIMIT_RETRIES = 2;
|
|
388
402
|
var Signaliz = class {
|
|
389
403
|
constructor(config) {
|
|
390
404
|
this.client = new HttpClient(config);
|
|
@@ -780,7 +794,7 @@ var Signaliz = class {
|
|
|
780
794
|
}
|
|
781
795
|
return results;
|
|
782
796
|
}
|
|
783
|
-
async runCoreBatchRound(path, tasks, options, companyRecoverableBatch) {
|
|
797
|
+
async runCoreBatchRound(path, tasks, options, companyRecoverableBatch, rowRateLimitAttempt = 0) {
|
|
784
798
|
const { serverConcurrency, chunkConcurrency } = batchConcurrencyPlan(options);
|
|
785
799
|
const deduplicated = dedupeExactBatchItems(tasks, (task) => JSON.stringify(task.request));
|
|
786
800
|
const uniqueTasks = deduplicated.uniqueItems;
|
|
@@ -845,6 +859,25 @@ var Signaliz = class {
|
|
|
845
859
|
};
|
|
846
860
|
}
|
|
847
861
|
}
|
|
862
|
+
if (rowRateLimitAttempt < MAX_ROW_RATE_LIMIT_RETRIES) {
|
|
863
|
+
const retryTasks = uniqueTasks.filter((_, index) => isRetryableRowRateLimit(uniqueResults[index]));
|
|
864
|
+
if (retryTasks.length > 0) {
|
|
865
|
+
const retryItems = uniqueResults.filter(isRetryableRowRateLimit);
|
|
866
|
+
await sleep2(rowRateLimitDelayMs(retryItems));
|
|
867
|
+
const retried = await this.runCoreBatchRound(
|
|
868
|
+
path,
|
|
869
|
+
retryTasks,
|
|
870
|
+
options,
|
|
871
|
+
void 0,
|
|
872
|
+
rowRateLimitAttempt + 1
|
|
873
|
+
);
|
|
874
|
+
const retriedByIndex = new Map(retried.map((item) => [item.index, item]));
|
|
875
|
+
for (let index = 0; index < uniqueResults.length; index += 1) {
|
|
876
|
+
const replacement = retriedByIndex.get(uniqueResults[index].index);
|
|
877
|
+
if (replacement) uniqueResults[index] = replacement;
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
}
|
|
848
881
|
return tasks.map((task, index) => ({
|
|
849
882
|
...uniqueResults[deduplicated.sourceIndexByInput[index]],
|
|
850
883
|
index: task.index
|
|
@@ -862,6 +895,21 @@ var Signaliz = class {
|
|
|
862
895
|
};
|
|
863
896
|
}
|
|
864
897
|
};
|
|
898
|
+
function isRetryableRowRateLimit(item) {
|
|
899
|
+
if (!item || item.success || !item.raw || item.raw.retry_eligible === false) return false;
|
|
900
|
+
const code = String(item.raw.error_code || item.raw.code || "").trim().toUpperCase();
|
|
901
|
+
return code === "RATE_LIMITED" || /^RATE_\d+$/.test(code);
|
|
902
|
+
}
|
|
903
|
+
function rowRateLimitDelayMs(items) {
|
|
904
|
+
const delays = items.map((item) => {
|
|
905
|
+
const retryAfterMs = Number(item.raw?.retry_after_ms);
|
|
906
|
+
if (Number.isFinite(retryAfterMs) && retryAfterMs > 0) return retryAfterMs;
|
|
907
|
+
const retryAfterSeconds2 = Number(item.raw?.retry_after_seconds ?? item.raw?.retry_after);
|
|
908
|
+
if (Number.isFinite(retryAfterSeconds2) && retryAfterSeconds2 > 0) return retryAfterSeconds2 * 1e3;
|
|
909
|
+
return 6e4;
|
|
910
|
+
});
|
|
911
|
+
return Math.max(1, Math.min(6e4, Math.max(...delays)));
|
|
912
|
+
}
|
|
865
913
|
function recoverableJobRowFailed(row) {
|
|
866
914
|
return row.success === false || ["failed", "skipped"].includes(String(row._status || "").toLowerCase());
|
|
867
915
|
}
|
package/dist/index.mjs
CHANGED
package/dist/mcp-config.js
CHANGED
|
@@ -49,7 +49,7 @@ function parseError(status, body) {
|
|
|
49
49
|
code: body.error.code || `HTTP_${status}`,
|
|
50
50
|
message: body.error.message || `Request failed with status ${status}`,
|
|
51
51
|
errorType: mapErrorType(body.error.code, status),
|
|
52
|
-
retryAfter: body.error
|
|
52
|
+
retryAfter: retryAfterSeconds(body.error),
|
|
53
53
|
details: body.error.details
|
|
54
54
|
});
|
|
55
55
|
}
|
|
@@ -58,9 +58,22 @@ function parseError(status, body) {
|
|
|
58
58
|
code,
|
|
59
59
|
message: body?.message || body?.error || `Request failed with status ${status}`,
|
|
60
60
|
errorType: mapErrorType(code, status),
|
|
61
|
-
|
|
61
|
+
retryAfter: retryAfterSeconds(body),
|
|
62
|
+
details: body?.details || publicRetryDetails(body)
|
|
62
63
|
});
|
|
63
64
|
}
|
|
65
|
+
function retryAfterSeconds(body) {
|
|
66
|
+
const value = Number(body?.retry_after_seconds ?? body?.retry_after);
|
|
67
|
+
return Number.isFinite(value) && value >= 0 ? value : void 0;
|
|
68
|
+
}
|
|
69
|
+
function publicRetryDetails(body) {
|
|
70
|
+
const details = {
|
|
71
|
+
...body?.retry_eligible !== void 0 ? { retry_eligible: body.retry_eligible } : {},
|
|
72
|
+
...body?.retry_after !== void 0 ? { retry_after: body.retry_after } : {},
|
|
73
|
+
...body?.retry_after_seconds !== void 0 ? { retry_after_seconds: body.retry_after_seconds } : {}
|
|
74
|
+
};
|
|
75
|
+
return Object.keys(details).length > 0 ? details : void 0;
|
|
76
|
+
}
|
|
64
77
|
function mapErrorType(code, status) {
|
|
65
78
|
if (code === "RATE_LIMITED" || status === 429) return "rate_limited";
|
|
66
79
|
if (code === "VALIDATION_ERROR" || code === "SIGNAL_RUN_COMPANY_MISMATCH" || status === 400) return "validation";
|
|
@@ -389,6 +402,7 @@ function mapErrorTypeFromCode(code) {
|
|
|
389
402
|
}
|
|
390
403
|
|
|
391
404
|
// src/index.ts
|
|
405
|
+
var MAX_ROW_RATE_LIMIT_RETRIES = 2;
|
|
392
406
|
var Signaliz = class {
|
|
393
407
|
constructor(config) {
|
|
394
408
|
this.client = new HttpClient(config);
|
|
@@ -784,7 +798,7 @@ var Signaliz = class {
|
|
|
784
798
|
}
|
|
785
799
|
return results;
|
|
786
800
|
}
|
|
787
|
-
async runCoreBatchRound(path2, tasks, options, companyRecoverableBatch) {
|
|
801
|
+
async runCoreBatchRound(path2, tasks, options, companyRecoverableBatch, rowRateLimitAttempt = 0) {
|
|
788
802
|
const { serverConcurrency, chunkConcurrency } = batchConcurrencyPlan(options);
|
|
789
803
|
const deduplicated = dedupeExactBatchItems(tasks, (task) => JSON.stringify(task.request));
|
|
790
804
|
const uniqueTasks = deduplicated.uniqueItems;
|
|
@@ -849,6 +863,25 @@ var Signaliz = class {
|
|
|
849
863
|
};
|
|
850
864
|
}
|
|
851
865
|
}
|
|
866
|
+
if (rowRateLimitAttempt < MAX_ROW_RATE_LIMIT_RETRIES) {
|
|
867
|
+
const retryTasks = uniqueTasks.filter((_, index) => isRetryableRowRateLimit(uniqueResults[index]));
|
|
868
|
+
if (retryTasks.length > 0) {
|
|
869
|
+
const retryItems = uniqueResults.filter(isRetryableRowRateLimit);
|
|
870
|
+
await sleep2(rowRateLimitDelayMs(retryItems));
|
|
871
|
+
const retried = await this.runCoreBatchRound(
|
|
872
|
+
path2,
|
|
873
|
+
retryTasks,
|
|
874
|
+
options,
|
|
875
|
+
void 0,
|
|
876
|
+
rowRateLimitAttempt + 1
|
|
877
|
+
);
|
|
878
|
+
const retriedByIndex = new Map(retried.map((item) => [item.index, item]));
|
|
879
|
+
for (let index = 0; index < uniqueResults.length; index += 1) {
|
|
880
|
+
const replacement = retriedByIndex.get(uniqueResults[index].index);
|
|
881
|
+
if (replacement) uniqueResults[index] = replacement;
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
}
|
|
852
885
|
return tasks.map((task, index) => ({
|
|
853
886
|
...uniqueResults[deduplicated.sourceIndexByInput[index]],
|
|
854
887
|
index: task.index
|
|
@@ -866,6 +899,21 @@ var Signaliz = class {
|
|
|
866
899
|
};
|
|
867
900
|
}
|
|
868
901
|
};
|
|
902
|
+
function isRetryableRowRateLimit(item) {
|
|
903
|
+
if (!item || item.success || !item.raw || item.raw.retry_eligible === false) return false;
|
|
904
|
+
const code = String(item.raw.error_code || item.raw.code || "").trim().toUpperCase();
|
|
905
|
+
return code === "RATE_LIMITED" || /^RATE_\d+$/.test(code);
|
|
906
|
+
}
|
|
907
|
+
function rowRateLimitDelayMs(items) {
|
|
908
|
+
const delays = items.map((item) => {
|
|
909
|
+
const retryAfterMs = Number(item.raw?.retry_after_ms);
|
|
910
|
+
if (Number.isFinite(retryAfterMs) && retryAfterMs > 0) return retryAfterMs;
|
|
911
|
+
const retryAfterSeconds2 = Number(item.raw?.retry_after_seconds ?? item.raw?.retry_after);
|
|
912
|
+
if (Number.isFinite(retryAfterSeconds2) && retryAfterSeconds2 > 0) return retryAfterSeconds2 * 1e3;
|
|
913
|
+
return 6e4;
|
|
914
|
+
});
|
|
915
|
+
return Math.max(1, Math.min(6e4, Math.max(...delays)));
|
|
916
|
+
}
|
|
869
917
|
function recoverableJobRowFailed(row) {
|
|
870
918
|
return row.success === false || ["failed", "skipped"].includes(String(row._status || "").toLowerCase());
|
|
871
919
|
}
|
package/dist/mcp-config.mjs
CHANGED
package/package.json
CHANGED