@delopay/sdk 0.165.0 → 0.166.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/README.md +2 -0
- package/dist/{chunk-CP5M5WR6.js → chunk-W57MOHOE.js} +473 -44
- package/dist/chunk-W57MOHOE.js.map +1 -0
- package/dist/index.cjs +471 -43
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +203 -44
- package/dist/index.d.ts +203 -44
- package/dist/index.js +1 -1
- package/dist/internal.cjs +493 -54
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.d.cts +77 -7
- package/dist/internal.d.ts +77 -7
- package/dist/internal.js +24 -12
- package/dist/internal.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-CP5M5WR6.js.map +0 -1
package/README.md
CHANGED
|
@@ -403,6 +403,8 @@ try {
|
|
|
403
403
|
|
|
404
404
|
Network timeouts throw `DelopayError` with `code: 'TIMEOUT'`. Network failures throw with `code: 'NETWORK'`.
|
|
405
405
|
|
|
406
|
+
An export (`delopay.export.*`, `disputes.workspaceExport`) is held to the record count the server announces in `X-Delopay-Record-Count`: a file that arrives with a different number of records — or ends part-way through a line or a JSON document — throws with `code: 'EXPORT_INCOMPLETE'` (`err.data` is `{ expected_records, received_records }`) instead of resolving to a file that is missing rows. Pass `onProgress` in an export's options to follow the download, and `signal` to cancel it.
|
|
407
|
+
|
|
406
408
|
**Structured error context (`err.data`):** populated for a small set of codes that benefit from a machine-readable hint. Currently:
|
|
407
409
|
|
|
408
410
|
| `err.code` | `err.data` shape | Meaning |
|
|
@@ -938,6 +938,289 @@ var Customers = class {
|
|
|
938
938
|
}
|
|
939
939
|
};
|
|
940
940
|
|
|
941
|
+
// src/recordCounter.ts
|
|
942
|
+
var LF = 10;
|
|
943
|
+
var CR = 13;
|
|
944
|
+
var QUOTE = 34;
|
|
945
|
+
var BACKSLASH = 92;
|
|
946
|
+
var OPEN_BRACE = 123;
|
|
947
|
+
var CLOSE_BRACE = 125;
|
|
948
|
+
var OPEN_BRACKET = 91;
|
|
949
|
+
var CLOSE_BRACKET = 93;
|
|
950
|
+
var CsvRecordCounter = class {
|
|
951
|
+
constructor() {
|
|
952
|
+
this.inQuotes = false;
|
|
953
|
+
this.newlines = 0;
|
|
954
|
+
/** Whether anything but a line break has arrived since the last newline. */
|
|
955
|
+
this.lineHasContent = false;
|
|
956
|
+
}
|
|
957
|
+
push(chunk) {
|
|
958
|
+
let inQuotes = this.inQuotes;
|
|
959
|
+
let newlines = this.newlines;
|
|
960
|
+
let lineHasContent = this.lineHasContent;
|
|
961
|
+
for (const byte of chunk) {
|
|
962
|
+
if (byte === QUOTE) {
|
|
963
|
+
inQuotes = !inQuotes;
|
|
964
|
+
lineHasContent = true;
|
|
965
|
+
} else if (inQuotes) {
|
|
966
|
+
lineHasContent = true;
|
|
967
|
+
} else if (byte === LF) {
|
|
968
|
+
newlines++;
|
|
969
|
+
lineHasContent = false;
|
|
970
|
+
} else if (byte !== CR) {
|
|
971
|
+
lineHasContent = true;
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
this.inQuotes = inQuotes;
|
|
975
|
+
this.newlines = newlines;
|
|
976
|
+
this.lineHasContent = lineHasContent;
|
|
977
|
+
}
|
|
978
|
+
get records() {
|
|
979
|
+
return Math.max(0, this.newlines - 1);
|
|
980
|
+
}
|
|
981
|
+
/**
|
|
982
|
+
* The export writer ends every line — the header and each record — with a
|
|
983
|
+
* newline, so a whole body ends on one, outside quotes. RFC 4180 lets a
|
|
984
|
+
* final line break be omitted, but these bodies never omit it, and without
|
|
985
|
+
* that rule a file cut part-way through its last unquoted field
|
|
986
|
+
* (`pay_1,12` of `pay_1,123`) would count as one more whole record and
|
|
987
|
+
* match the figure it was announced with.
|
|
988
|
+
*/
|
|
989
|
+
get complete() {
|
|
990
|
+
return this.newlines >= 1 && !this.inQuotes && !this.lineHasContent;
|
|
991
|
+
}
|
|
992
|
+
/**
|
|
993
|
+
* The records that ended. An unterminated tail is not one of them — see
|
|
994
|
+
* {@link complete}.
|
|
995
|
+
*/
|
|
996
|
+
finish() {
|
|
997
|
+
return this.records;
|
|
998
|
+
}
|
|
999
|
+
};
|
|
1000
|
+
var SEEKING = 0;
|
|
1001
|
+
var COUNTING = 1;
|
|
1002
|
+
var CLOSED = 2;
|
|
1003
|
+
var JsonArrayRecordCounter = class {
|
|
1004
|
+
constructor() {
|
|
1005
|
+
this.depth = 0;
|
|
1006
|
+
this.inString = false;
|
|
1007
|
+
this.escaped = false;
|
|
1008
|
+
this.topIsObject = false;
|
|
1009
|
+
this.state = SEEKING;
|
|
1010
|
+
this.count = 0;
|
|
1011
|
+
}
|
|
1012
|
+
push(chunk) {
|
|
1013
|
+
if (this.state === CLOSED) return;
|
|
1014
|
+
let { depth, inString, escaped, topIsObject, count } = this;
|
|
1015
|
+
let state = this.state;
|
|
1016
|
+
for (const byte of chunk) {
|
|
1017
|
+
if (inString) {
|
|
1018
|
+
if (escaped) escaped = false;
|
|
1019
|
+
else if (byte === BACKSLASH) escaped = true;
|
|
1020
|
+
else if (byte === QUOTE) inString = false;
|
|
1021
|
+
continue;
|
|
1022
|
+
}
|
|
1023
|
+
if (byte === QUOTE) {
|
|
1024
|
+
inString = true;
|
|
1025
|
+
} else if (byte === OPEN_BRACE || byte === OPEN_BRACKET) {
|
|
1026
|
+
if (depth === 0 && byte === OPEN_BRACE) topIsObject = true;
|
|
1027
|
+
if (byte === OPEN_BRACKET && depth === 1 && topIsObject && state === SEEKING) {
|
|
1028
|
+
state = COUNTING;
|
|
1029
|
+
}
|
|
1030
|
+
depth++;
|
|
1031
|
+
} else if (byte === CLOSE_BRACE || byte === CLOSE_BRACKET) {
|
|
1032
|
+
depth--;
|
|
1033
|
+
if (state === COUNTING) {
|
|
1034
|
+
if (depth === 2) count++;
|
|
1035
|
+
else if (depth === 1) {
|
|
1036
|
+
state = CLOSED;
|
|
1037
|
+
break;
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
this.depth = depth;
|
|
1043
|
+
this.inString = inString;
|
|
1044
|
+
this.escaped = escaped;
|
|
1045
|
+
this.topIsObject = topIsObject;
|
|
1046
|
+
this.state = state;
|
|
1047
|
+
this.count = count;
|
|
1048
|
+
}
|
|
1049
|
+
get records() {
|
|
1050
|
+
return this.count;
|
|
1051
|
+
}
|
|
1052
|
+
/**
|
|
1053
|
+
* Whether the rows array has closed. What follows it is checked by parsing
|
|
1054
|
+
* the whole document, which a cut-off body fails.
|
|
1055
|
+
*/
|
|
1056
|
+
get complete() {
|
|
1057
|
+
return this.state === CLOSED;
|
|
1058
|
+
}
|
|
1059
|
+
finish() {
|
|
1060
|
+
return this.count;
|
|
1061
|
+
}
|
|
1062
|
+
};
|
|
1063
|
+
|
|
1064
|
+
// src/exportDownload.ts
|
|
1065
|
+
var RECORD_COUNT_HEADER = "x-delopay-record-count";
|
|
1066
|
+
var LIST_ENVELOPE = { rows: "records", count: "record_count" };
|
|
1067
|
+
var WORKSPACE_ENVELOPE = { rows: "data", count: "total_count" };
|
|
1068
|
+
function parseRecordCount(header) {
|
|
1069
|
+
if (header === null) return null;
|
|
1070
|
+
const trimmed = header.trim();
|
|
1071
|
+
if (!/^\d+$/.test(trimmed)) return null;
|
|
1072
|
+
const value = Number(trimmed);
|
|
1073
|
+
return Number.isSafeInteger(value) ? value : null;
|
|
1074
|
+
}
|
|
1075
|
+
function counterFor(format) {
|
|
1076
|
+
if (format === "csv") return new CsvRecordCounter();
|
|
1077
|
+
if (format === "json") return new JsonArrayRecordCounter();
|
|
1078
|
+
return null;
|
|
1079
|
+
}
|
|
1080
|
+
function isRecord(value) {
|
|
1081
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1082
|
+
}
|
|
1083
|
+
function announced(expected) {
|
|
1084
|
+
return expected === null ? "" : ` of the ${expected} announced`;
|
|
1085
|
+
}
|
|
1086
|
+
function incomplete(message, expected, received, requestId) {
|
|
1087
|
+
return new DelopayError(message, {
|
|
1088
|
+
status: 0,
|
|
1089
|
+
code: "EXPORT_INCOMPLETE",
|
|
1090
|
+
type: "export_incomplete",
|
|
1091
|
+
...requestId !== void 0 ? { requestId } : {},
|
|
1092
|
+
data: { expected_records: expected, received_records: received }
|
|
1093
|
+
});
|
|
1094
|
+
}
|
|
1095
|
+
async function downloadExport(request, call, options) {
|
|
1096
|
+
const { format } = call;
|
|
1097
|
+
const envelope = call.envelope ?? LIST_ENVELOPE;
|
|
1098
|
+
const onProgress = options?.onProgress;
|
|
1099
|
+
let latest = {
|
|
1100
|
+
phase: "preparing",
|
|
1101
|
+
receivedBytes: 0,
|
|
1102
|
+
totalBytes: null,
|
|
1103
|
+
receivedRecords: 0,
|
|
1104
|
+
expectedRecords: null
|
|
1105
|
+
};
|
|
1106
|
+
const seen = { attempt: -1, counter: null, expected: null, requestId: void 0, listenerError: null };
|
|
1107
|
+
const report = (progress) => {
|
|
1108
|
+
latest = progress;
|
|
1109
|
+
if (!onProgress) return;
|
|
1110
|
+
try {
|
|
1111
|
+
onProgress({ ...progress });
|
|
1112
|
+
} catch (error) {
|
|
1113
|
+
seen.listenerError = { error };
|
|
1114
|
+
throw error;
|
|
1115
|
+
}
|
|
1116
|
+
};
|
|
1117
|
+
report(latest);
|
|
1118
|
+
const onDownloadProgress = (event) => {
|
|
1119
|
+
if (event.attempt !== seen.attempt) {
|
|
1120
|
+
seen.attempt = event.attempt;
|
|
1121
|
+
seen.counter = counterFor(format);
|
|
1122
|
+
seen.expected = format === "pdf" ? null : parseRecordCount(event.headers.get(RECORD_COUNT_HEADER));
|
|
1123
|
+
seen.requestId = event.headers.get("x-request-id") ?? event.headers.get("x-trace-id") ?? void 0;
|
|
1124
|
+
}
|
|
1125
|
+
if (event.chunk.byteLength > 0) seen.counter?.push(event.chunk);
|
|
1126
|
+
report({
|
|
1127
|
+
phase: "receiving",
|
|
1128
|
+
receivedBytes: event.loaded,
|
|
1129
|
+
totalBytes: event.total,
|
|
1130
|
+
receivedRecords: seen.counter?.records ?? 0,
|
|
1131
|
+
expectedRecords: seen.expected
|
|
1132
|
+
});
|
|
1133
|
+
};
|
|
1134
|
+
let result;
|
|
1135
|
+
try {
|
|
1136
|
+
result = await request(call.method, call.path, {
|
|
1137
|
+
...call.request,
|
|
1138
|
+
...options?.signal !== void 0 ? { signal: options.signal } : {},
|
|
1139
|
+
...options?.timeout !== void 0 ? { timeout: options.timeout } : {},
|
|
1140
|
+
onDownloadProgress
|
|
1141
|
+
});
|
|
1142
|
+
} catch (err) {
|
|
1143
|
+
if (seen.listenerError !== null && err === seen.listenerError.error) throw err;
|
|
1144
|
+
if (format === "json" && seen.attempt >= 0 && err instanceof SyntaxError) {
|
|
1145
|
+
const received2 = seen.counter?.records ?? 0;
|
|
1146
|
+
throw incomplete(
|
|
1147
|
+
seen.expected === null ? `Export incomplete: the body ended part-way through the JSON document, after ${received2} records` : `Export incomplete: the server announced ${seen.expected} records, and the body ended part-way through the JSON document after ${received2}`,
|
|
1148
|
+
seen.expected,
|
|
1149
|
+
received2,
|
|
1150
|
+
seen.requestId
|
|
1151
|
+
);
|
|
1152
|
+
}
|
|
1153
|
+
throw err;
|
|
1154
|
+
}
|
|
1155
|
+
const { expected, requestId } = seen;
|
|
1156
|
+
let received = 0;
|
|
1157
|
+
if (format === "json") {
|
|
1158
|
+
const rows = isRecord(result) ? result[envelope.rows] : void 0;
|
|
1159
|
+
if (!Array.isArray(rows)) {
|
|
1160
|
+
throw incomplete(
|
|
1161
|
+
`Export incomplete: the body is not an export envelope with a "${envelope.rows}" array, so it carries 0 records${announced(expected)}`,
|
|
1162
|
+
expected,
|
|
1163
|
+
0,
|
|
1164
|
+
requestId
|
|
1165
|
+
);
|
|
1166
|
+
}
|
|
1167
|
+
received = rows.length;
|
|
1168
|
+
const declared = isRecord(result) ? result[envelope.count] : void 0;
|
|
1169
|
+
if (typeof declared === "number" && declared !== rows.length) {
|
|
1170
|
+
throw incomplete(
|
|
1171
|
+
`Export incomplete: the file's ${envelope.count} is ${declared}, but it carries ${rows.length} records`,
|
|
1172
|
+
declared,
|
|
1173
|
+
rows.length,
|
|
1174
|
+
requestId
|
|
1175
|
+
);
|
|
1176
|
+
}
|
|
1177
|
+
} else if (format === "csv") {
|
|
1178
|
+
const counter = seen.counter;
|
|
1179
|
+
received = counter?.finish() ?? 0;
|
|
1180
|
+
if (!counter?.complete) {
|
|
1181
|
+
throw incomplete(
|
|
1182
|
+
`Export incomplete: the CSV body ended part-way through a line, after ${received} complete records${announced(expected)}`,
|
|
1183
|
+
expected,
|
|
1184
|
+
received,
|
|
1185
|
+
requestId
|
|
1186
|
+
);
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
if (expected !== null && received !== expected) {
|
|
1190
|
+
throw incomplete(
|
|
1191
|
+
`Export incomplete: the server announced ${expected} records, and the body carried ${received}`,
|
|
1192
|
+
expected,
|
|
1193
|
+
received,
|
|
1194
|
+
requestId
|
|
1195
|
+
);
|
|
1196
|
+
}
|
|
1197
|
+
report({
|
|
1198
|
+
phase: "done",
|
|
1199
|
+
receivedBytes: latest.receivedBytes,
|
|
1200
|
+
totalBytes: latest.totalBytes,
|
|
1201
|
+
receivedRecords: received,
|
|
1202
|
+
expectedRecords: expected
|
|
1203
|
+
});
|
|
1204
|
+
return result;
|
|
1205
|
+
}
|
|
1206
|
+
var ACCEPT = {
|
|
1207
|
+
csv: "text/csv",
|
|
1208
|
+
json: "application/json",
|
|
1209
|
+
pdf: "application/pdf"
|
|
1210
|
+
};
|
|
1211
|
+
function negotiated(options, format) {
|
|
1212
|
+
const headers = { ...options.headers, Accept: ACCEPT[format] };
|
|
1213
|
+
return format === "json" ? { ...options, headers } : { ...options, headers, responseType: "blob" };
|
|
1214
|
+
}
|
|
1215
|
+
function runExport(request, method, path, base, options) {
|
|
1216
|
+
const format = options?.format ?? "json";
|
|
1217
|
+
return downloadExport(
|
|
1218
|
+
request,
|
|
1219
|
+
{ method, path, request: negotiated(base, format), format },
|
|
1220
|
+
options
|
|
1221
|
+
);
|
|
1222
|
+
}
|
|
1223
|
+
|
|
941
1224
|
// src/resources/disputes.ts
|
|
942
1225
|
function workspaceQuery(params) {
|
|
943
1226
|
if (!params) return void 0;
|
|
@@ -966,9 +1249,28 @@ var Disputes = class {
|
|
|
966
1249
|
async workspaceAggregate(params) {
|
|
967
1250
|
return this.request("GET", "/disputes/workspace/aggregate", { query: workspaceQuery(params) });
|
|
968
1251
|
}
|
|
969
|
-
/**
|
|
970
|
-
|
|
971
|
-
|
|
1252
|
+
/**
|
|
1253
|
+
* Export the complete filtered set, or throw on the server's explicit
|
|
1254
|
+
* export-limit refusal. `GET /disputes/workspace/export`
|
|
1255
|
+
*
|
|
1256
|
+
* The body is streamed, and held to the `X-Delopay-Record-Count` the server
|
|
1257
|
+
* announces and to its own `total_count`: a set that arrives short rejects
|
|
1258
|
+
* with `EXPORT_INCOMPLETE` rather than resolving. `options` reports the
|
|
1259
|
+
* download's progress and takes a signal and an idle timeout — see
|
|
1260
|
+
* {@link ExportTransferOptions}.
|
|
1261
|
+
*/
|
|
1262
|
+
async workspaceExport(params, options) {
|
|
1263
|
+
return downloadExport(
|
|
1264
|
+
this.request,
|
|
1265
|
+
{
|
|
1266
|
+
method: "GET",
|
|
1267
|
+
path: "/disputes/workspace/export",
|
|
1268
|
+
request: { query: workspaceQuery(params) },
|
|
1269
|
+
format: "json",
|
|
1270
|
+
envelope: WORKSPACE_ENVELOPE
|
|
1271
|
+
},
|
|
1272
|
+
options
|
|
1273
|
+
);
|
|
972
1274
|
}
|
|
973
1275
|
/**
|
|
974
1276
|
* Retrieve a dispute by its ID.
|
|
@@ -4125,77 +4427,68 @@ var Export = class {
|
|
|
4125
4427
|
this.request = request;
|
|
4126
4428
|
}
|
|
4127
4429
|
async transactions(params, options) {
|
|
4128
|
-
return this.request
|
|
4129
|
-
"POST",
|
|
4130
|
-
"/export/transactions",
|
|
4131
|
-
transactionBody(params, options)
|
|
4132
|
-
);
|
|
4430
|
+
return runExport(this.request, "POST", "/export/transactions", { body: params ?? {} }, options);
|
|
4133
4431
|
}
|
|
4134
4432
|
async transactionsForProfile(params, options) {
|
|
4135
|
-
return
|
|
4433
|
+
return runExport(
|
|
4434
|
+
this.request,
|
|
4136
4435
|
"POST",
|
|
4137
4436
|
"/export/profile/transactions",
|
|
4138
|
-
|
|
4437
|
+
{ body: params ?? {} },
|
|
4438
|
+
options
|
|
4139
4439
|
);
|
|
4140
4440
|
}
|
|
4141
4441
|
async refunds(params, options) {
|
|
4142
|
-
return this.request
|
|
4442
|
+
return runExport(this.request, "POST", "/refunds/list/export", { body: params ?? {} }, options);
|
|
4143
4443
|
}
|
|
4144
4444
|
async refundsForProfile(params, options) {
|
|
4145
|
-
return
|
|
4445
|
+
return runExport(
|
|
4446
|
+
this.request,
|
|
4146
4447
|
"POST",
|
|
4147
4448
|
"/refunds/profile/list/export",
|
|
4148
|
-
|
|
4449
|
+
{ body: params ?? {} },
|
|
4450
|
+
options
|
|
4149
4451
|
);
|
|
4150
4452
|
}
|
|
4151
4453
|
async disputes(params, options) {
|
|
4152
|
-
return this.request
|
|
4454
|
+
return runExport(this.request, "GET", "/disputes/list/export", queried(params), options);
|
|
4153
4455
|
}
|
|
4154
4456
|
async disputesForProfile(params, options) {
|
|
4155
|
-
return
|
|
4457
|
+
return runExport(
|
|
4458
|
+
this.request,
|
|
4156
4459
|
"GET",
|
|
4157
4460
|
"/disputes/profile/list/export",
|
|
4158
|
-
queried(params,
|
|
4461
|
+
queried(params),
|
|
4462
|
+
options
|
|
4159
4463
|
);
|
|
4160
4464
|
}
|
|
4161
4465
|
async payouts(params, options) {
|
|
4162
|
-
return this.request
|
|
4466
|
+
return runExport(this.request, "POST", "/payouts/list/export", { body: params }, options);
|
|
4163
4467
|
}
|
|
4164
4468
|
async payoutsForProfile(params, options) {
|
|
4165
|
-
return
|
|
4469
|
+
return runExport(
|
|
4470
|
+
this.request,
|
|
4471
|
+
"POST",
|
|
4472
|
+
"/payouts/profile/list/export",
|
|
4473
|
+
{ body: params },
|
|
4474
|
+
options
|
|
4475
|
+
);
|
|
4166
4476
|
}
|
|
4167
4477
|
async subscriptions(profileId, params, options) {
|
|
4168
|
-
return
|
|
4478
|
+
return runExport(
|
|
4479
|
+
this.request,
|
|
4169
4480
|
"GET",
|
|
4170
4481
|
"/subscriptions/list/export",
|
|
4171
|
-
queried(params,
|
|
4482
|
+
queried(params, { "X-Profile-Id": profileId }),
|
|
4483
|
+
options
|
|
4172
4484
|
);
|
|
4173
4485
|
}
|
|
4174
4486
|
async auditLog(params, options) {
|
|
4175
|
-
return this.request
|
|
4487
|
+
return runExport(this.request, "GET", "/audit/export", queried(params), options);
|
|
4176
4488
|
}
|
|
4177
4489
|
};
|
|
4178
|
-
|
|
4179
|
-
|
|
4180
|
-
json: "application/json",
|
|
4181
|
-
pdf: "application/pdf"
|
|
4182
|
-
};
|
|
4183
|
-
function negotiated(options, format) {
|
|
4184
|
-
const headers = { ...options.headers, Accept: ACCEPT[format] };
|
|
4185
|
-
return format === "json" ? { ...options, headers } : { ...options, headers, responseType: "blob" };
|
|
4186
|
-
}
|
|
4187
|
-
function transactionBody(params, options) {
|
|
4188
|
-
const format = options?.format ?? "json";
|
|
4189
|
-
return negotiated({ body: { ...params, format } }, format);
|
|
4190
|
-
}
|
|
4191
|
-
function bodied(body, options) {
|
|
4192
|
-
return negotiated({ body }, options?.format ?? "json");
|
|
4193
|
-
}
|
|
4194
|
-
function queried(params, options, headers) {
|
|
4195
|
-
return negotiated(
|
|
4196
|
-
{ query: params ?? {}, ...headers ? { headers } : {} },
|
|
4197
|
-
options?.format ?? "json"
|
|
4198
|
-
);
|
|
4490
|
+
function queried(params, headers) {
|
|
4491
|
+
return { query: params ?? {}, ...headers ? { headers } : {} };
|
|
4199
4492
|
}
|
|
4200
4493
|
|
|
4201
4494
|
// src/resources/featureMatrix.ts
|
|
@@ -5568,6 +5861,112 @@ function findIdempotencyKey(headers) {
|
|
|
5568
5861
|
}
|
|
5569
5862
|
function noop() {
|
|
5570
5863
|
}
|
|
5864
|
+
var ListenerFailure = class {
|
|
5865
|
+
constructor(cause) {
|
|
5866
|
+
this.cause = cause;
|
|
5867
|
+
}
|
|
5868
|
+
};
|
|
5869
|
+
var BodyStreamFailure = class {
|
|
5870
|
+
constructor(cause) {
|
|
5871
|
+
this.cause = cause;
|
|
5872
|
+
}
|
|
5873
|
+
};
|
|
5874
|
+
function abortError() {
|
|
5875
|
+
const error = new Error("The operation was aborted");
|
|
5876
|
+
error.name = "AbortError";
|
|
5877
|
+
return error;
|
|
5878
|
+
}
|
|
5879
|
+
function parseContentLength(header) {
|
|
5880
|
+
if (header === null || !/^\s*\d+\s*$/.test(header)) return null;
|
|
5881
|
+
const value = Number(header);
|
|
5882
|
+
return Number.isSafeInteger(value) ? value : null;
|
|
5883
|
+
}
|
|
5884
|
+
function readChunk(reader, signal) {
|
|
5885
|
+
if (signal.aborted) return Promise.reject(abortError());
|
|
5886
|
+
return new Promise((resolve, reject) => {
|
|
5887
|
+
const onAbort = () => reject(abortError());
|
|
5888
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
5889
|
+
reader.read().then(
|
|
5890
|
+
(result) => {
|
|
5891
|
+
signal.removeEventListener("abort", onAbort);
|
|
5892
|
+
resolve(result);
|
|
5893
|
+
},
|
|
5894
|
+
(cause) => {
|
|
5895
|
+
signal.removeEventListener("abort", onAbort);
|
|
5896
|
+
reject(signal.aborted ? abortError() : new BodyStreamFailure(cause));
|
|
5897
|
+
}
|
|
5898
|
+
);
|
|
5899
|
+
});
|
|
5900
|
+
}
|
|
5901
|
+
function concatChunks(chunks, length) {
|
|
5902
|
+
const out = new Uint8Array(length);
|
|
5903
|
+
let offset = 0;
|
|
5904
|
+
for (const chunk of chunks) {
|
|
5905
|
+
out.set(chunk, offset);
|
|
5906
|
+
offset += chunk.byteLength;
|
|
5907
|
+
}
|
|
5908
|
+
return out.buffer;
|
|
5909
|
+
}
|
|
5910
|
+
async function receiveWithProgress(response, responseType, listener, attempt, signal, onActivity) {
|
|
5911
|
+
const headers = response.headers ?? new Headers();
|
|
5912
|
+
const total = parseContentLength(headers.get("content-length"));
|
|
5913
|
+
let loaded = 0;
|
|
5914
|
+
const notify = (chunk) => {
|
|
5915
|
+
try {
|
|
5916
|
+
listener({ loaded, total, chunk: chunk.slice(), headers, attempt });
|
|
5917
|
+
} catch (cause) {
|
|
5918
|
+
throw new ListenerFailure(cause);
|
|
5919
|
+
}
|
|
5920
|
+
};
|
|
5921
|
+
onActivity();
|
|
5922
|
+
notify(new Uint8Array(0));
|
|
5923
|
+
const body = response.body;
|
|
5924
|
+
if (!body || typeof body.getReader !== "function") {
|
|
5925
|
+
if (responseType === "blob") {
|
|
5926
|
+
const blob = await response.blob();
|
|
5927
|
+
const bytes3 = new Uint8Array(await blob.arrayBuffer());
|
|
5928
|
+
loaded = bytes3.byteLength;
|
|
5929
|
+
if (loaded > 0) notify(bytes3);
|
|
5930
|
+
return blob;
|
|
5931
|
+
}
|
|
5932
|
+
if (responseType === "arraybuffer") {
|
|
5933
|
+
const buffer = await response.arrayBuffer();
|
|
5934
|
+
loaded = buffer.byteLength;
|
|
5935
|
+
if (loaded > 0) notify(new Uint8Array(buffer));
|
|
5936
|
+
return buffer;
|
|
5937
|
+
}
|
|
5938
|
+
const text2 = await response.text();
|
|
5939
|
+
const bytes2 = new TextEncoder().encode(text2);
|
|
5940
|
+
loaded = bytes2.byteLength;
|
|
5941
|
+
if (loaded > 0) notify(bytes2);
|
|
5942
|
+
return text2 ? JSON.parse(text2) : void 0;
|
|
5943
|
+
}
|
|
5944
|
+
const reader = body.getReader();
|
|
5945
|
+
const chunks = [];
|
|
5946
|
+
try {
|
|
5947
|
+
for (; ; ) {
|
|
5948
|
+
const { done, value } = await readChunk(reader, signal);
|
|
5949
|
+
if (done) break;
|
|
5950
|
+
if (!value || value.byteLength === 0) continue;
|
|
5951
|
+
chunks.push(value);
|
|
5952
|
+
loaded += value.byteLength;
|
|
5953
|
+
onActivity();
|
|
5954
|
+
notify(value);
|
|
5955
|
+
}
|
|
5956
|
+
} catch (err) {
|
|
5957
|
+
reader.cancel().catch(noop);
|
|
5958
|
+
throw err;
|
|
5959
|
+
}
|
|
5960
|
+
const bytes = concatChunks(chunks, loaded);
|
|
5961
|
+
if (responseType === "blob") {
|
|
5962
|
+
return new Blob([bytes], { type: headers.get("content-type") ?? "" });
|
|
5963
|
+
}
|
|
5964
|
+
if (responseType === "arraybuffer") {
|
|
5965
|
+
return bytes;
|
|
5966
|
+
}
|
|
5967
|
+
const text = new TextDecoder().decode(bytes);
|
|
5968
|
+
return text ? JSON.parse(text) : void 0;
|
|
5969
|
+
}
|
|
5571
5970
|
function combineSignals(signals) {
|
|
5572
5971
|
const controller = new AbortController();
|
|
5573
5972
|
const listeners = [];
|
|
@@ -5849,7 +6248,12 @@ var Delopay = class {
|
|
|
5849
6248
|
emit("retry", { attempt, maxRetries: this.maxRetries, method, path });
|
|
5850
6249
|
}
|
|
5851
6250
|
const timeoutCtrl = new AbortController();
|
|
5852
|
-
|
|
6251
|
+
let timeoutId = setTimeout(() => timeoutCtrl.abort(), timeoutMs);
|
|
6252
|
+
const restartIdleTimer = () => {
|
|
6253
|
+
if (timeoutCtrl.signal.aborted) return;
|
|
6254
|
+
clearTimeout(timeoutId);
|
|
6255
|
+
timeoutId = setTimeout(() => timeoutCtrl.abort(), timeoutMs);
|
|
6256
|
+
};
|
|
5853
6257
|
const combined = combineSignals(
|
|
5854
6258
|
callerSignal ? [timeoutCtrl.signal, callerSignal] : [timeoutCtrl.signal]
|
|
5855
6259
|
);
|
|
@@ -5907,6 +6311,16 @@ var Delopay = class {
|
|
|
5907
6311
|
}
|
|
5908
6312
|
throw error;
|
|
5909
6313
|
}
|
|
6314
|
+
if (options?.onDownloadProgress) {
|
|
6315
|
+
return await receiveWithProgress(
|
|
6316
|
+
response,
|
|
6317
|
+
options.responseType,
|
|
6318
|
+
options.onDownloadProgress,
|
|
6319
|
+
attempt,
|
|
6320
|
+
combined.signal,
|
|
6321
|
+
restartIdleTimer
|
|
6322
|
+
);
|
|
6323
|
+
}
|
|
5910
6324
|
if (options?.responseType === "blob") {
|
|
5911
6325
|
return await response.blob();
|
|
5912
6326
|
}
|
|
@@ -5919,6 +6333,20 @@ var Delopay = class {
|
|
|
5919
6333
|
if (err instanceof DelopayError || err instanceof DelopayAuthenticationError) {
|
|
5920
6334
|
throw err;
|
|
5921
6335
|
}
|
|
6336
|
+
if (err instanceof ListenerFailure) {
|
|
6337
|
+
throw err.cause;
|
|
6338
|
+
}
|
|
6339
|
+
if (err instanceof BodyStreamFailure) {
|
|
6340
|
+
const cause = err.cause;
|
|
6341
|
+
const detail = cause instanceof Error ? cause.message : String(cause ?? "body stream failed");
|
|
6342
|
+
lastError = new DelopayError(`Network error: ${detail}`, {
|
|
6343
|
+
status: 0,
|
|
6344
|
+
code: "NETWORK",
|
|
6345
|
+
type: "network_error"
|
|
6346
|
+
});
|
|
6347
|
+
if (isRetryable && attempt < this.maxRetries) continue;
|
|
6348
|
+
throw lastError;
|
|
6349
|
+
}
|
|
5922
6350
|
if (err instanceof Error && err.name === "AbortError") {
|
|
5923
6351
|
if (callerSignal?.aborted) {
|
|
5924
6352
|
throw new DelopayError("Request aborted", {
|
|
@@ -9510,6 +9938,7 @@ var encodeNativePanes = encodePanes;
|
|
|
9510
9938
|
export {
|
|
9511
9939
|
DelopayError,
|
|
9512
9940
|
DelopayAuthenticationError,
|
|
9941
|
+
runExport,
|
|
9513
9942
|
PaypalDisputes,
|
|
9514
9943
|
Search,
|
|
9515
9944
|
isSubscriptionLifecycleWebhook,
|
|
@@ -9725,4 +10154,4 @@ export {
|
|
|
9725
10154
|
decodeNativePanes,
|
|
9726
10155
|
encodeNativePanes
|
|
9727
10156
|
};
|
|
9728
|
-
//# sourceMappingURL=chunk-
|
|
10157
|
+
//# sourceMappingURL=chunk-W57MOHOE.js.map
|