@upyo/jmap 0.4.0-dev.75 → 0.4.0-dev.77
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.cjs +28 -10
- package/dist/index.js +28 -10
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -114,10 +114,10 @@ function createJmapConfig(config) {
|
|
|
114
114
|
basicAuth: config.basicAuth ?? null,
|
|
115
115
|
accountId: config.accountId ?? null,
|
|
116
116
|
identityId: config.identityId ?? null,
|
|
117
|
-
timeout: config.timeout
|
|
118
|
-
retries: config.retries
|
|
117
|
+
timeout: config.timeout ?? 3e4,
|
|
118
|
+
retries: config.retries ?? 3,
|
|
119
119
|
headers: config.headers ?? {},
|
|
120
|
-
sessionCacheTtl: config.sessionCacheTtl
|
|
120
|
+
sessionCacheTtl: config.sessionCacheTtl ?? 3e5,
|
|
121
121
|
baseUrl: config.baseUrl ?? null
|
|
122
122
|
};
|
|
123
123
|
}
|
|
@@ -207,12 +207,18 @@ var JmapHttpClient = class {
|
|
|
207
207
|
const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
|
|
208
208
|
let combinedSignal = controller.signal;
|
|
209
209
|
if (signal) {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
210
|
+
const AbortSignalAny = AbortSignal.any;
|
|
211
|
+
if (typeof AbortSignalAny === "function") combinedSignal = AbortSignalAny([signal, controller.signal]);
|
|
212
|
+
else {
|
|
213
|
+
if (signal.aborted) {
|
|
214
|
+
clearTimeout(timeoutId);
|
|
215
|
+
signal.throwIfAborted();
|
|
216
|
+
}
|
|
217
|
+
signal.addEventListener("abort", () => {
|
|
218
|
+
controller.abort(signal.reason);
|
|
219
|
+
});
|
|
220
|
+
combinedSignal = controller.signal;
|
|
213
221
|
}
|
|
214
|
-
signal.addEventListener("abort", () => controller.abort());
|
|
215
|
-
combinedSignal = controller.signal;
|
|
216
222
|
}
|
|
217
223
|
try {
|
|
218
224
|
return await globalThis.fetch(url, {
|
|
@@ -527,10 +533,14 @@ var JmapTransport = class {
|
|
|
527
533
|
const messageArray = [];
|
|
528
534
|
for await (const message of messages) messageArray.push(message);
|
|
529
535
|
if (messageArray.length === 0) return;
|
|
536
|
+
let processingStage = "initialization";
|
|
537
|
+
let attachmentsUploadedCount = 0;
|
|
530
538
|
try {
|
|
531
539
|
signal?.throwIfAborted();
|
|
540
|
+
processingStage = "session fetch";
|
|
532
541
|
const session = await this.getSession(signal);
|
|
533
542
|
signal?.throwIfAborted();
|
|
543
|
+
processingStage = "account discovery";
|
|
534
544
|
const accountId = this.config.accountId ?? findMailAccount(session);
|
|
535
545
|
if (!accountId) {
|
|
536
546
|
for (let i = 0; i < messageArray.length; i++) yield {
|
|
@@ -539,17 +549,22 @@ var JmapTransport = class {
|
|
|
539
549
|
};
|
|
540
550
|
return;
|
|
541
551
|
}
|
|
552
|
+
processingStage = "mailbox discovery";
|
|
542
553
|
const draftsMailboxId = await this.getDraftsMailboxId(session, accountId, signal);
|
|
543
554
|
signal?.throwIfAborted();
|
|
555
|
+
processingStage = "identity resolution";
|
|
544
556
|
const identityMap = await this.getIdentityMap(session, accountId, signal);
|
|
545
557
|
signal?.throwIfAborted();
|
|
558
|
+
processingStage = "attachment upload";
|
|
546
559
|
const allUploadedBlobs = /* @__PURE__ */ new Map();
|
|
547
560
|
for (let i = 0; i < messageArray.length; i++) {
|
|
548
561
|
const message = messageArray[i];
|
|
549
562
|
const uploadedBlobs = await this.uploadAttachments(session, accountId, message.attachments, signal);
|
|
550
563
|
allUploadedBlobs.set(i, uploadedBlobs);
|
|
564
|
+
attachmentsUploadedCount = i + 1;
|
|
551
565
|
signal?.throwIfAborted();
|
|
552
566
|
}
|
|
567
|
+
processingStage = "message conversion";
|
|
553
568
|
const emailCreates = {};
|
|
554
569
|
const submissionCreates = {};
|
|
555
570
|
for (let i = 0; i < messageArray.length; i++) {
|
|
@@ -564,6 +579,7 @@ var JmapTransport = class {
|
|
|
564
579
|
emailId: `#draft${i}`
|
|
565
580
|
};
|
|
566
581
|
}
|
|
582
|
+
processingStage = "batch request execution";
|
|
567
583
|
const response = await this.httpClient.executeRequest(session.apiUrl, {
|
|
568
584
|
using: [
|
|
569
585
|
JMAP_CAPABILITIES.core,
|
|
@@ -588,10 +604,12 @@ var JmapTransport = class {
|
|
|
588
604
|
}, signal);
|
|
589
605
|
for (let i = 0; i < messageArray.length; i++) yield this.parseBatchResponseForIndex(response, i);
|
|
590
606
|
} catch (error) {
|
|
591
|
-
const
|
|
607
|
+
const baseMessage = error instanceof Error && error.name === "AbortError" ? `Request aborted: ${error.message}` : error instanceof JmapApiError ? error.message : error instanceof Error ? error.message : String(error);
|
|
608
|
+
let detailedMessage = `Failed during ${processingStage}: ${baseMessage}`;
|
|
609
|
+
if (processingStage === "attachment upload" && attachmentsUploadedCount > 0) detailedMessage += ` (${attachmentsUploadedCount}/${messageArray.length} messages had attachments uploaded before failure)`;
|
|
592
610
|
for (let i = 0; i < messageArray.length; i++) yield {
|
|
593
611
|
successful: false,
|
|
594
|
-
errorMessages: [
|
|
612
|
+
errorMessages: [detailedMessage]
|
|
595
613
|
};
|
|
596
614
|
}
|
|
597
615
|
}
|
package/dist/index.js
CHANGED
|
@@ -113,10 +113,10 @@ function createJmapConfig(config) {
|
|
|
113
113
|
basicAuth: config.basicAuth ?? null,
|
|
114
114
|
accountId: config.accountId ?? null,
|
|
115
115
|
identityId: config.identityId ?? null,
|
|
116
|
-
timeout: config.timeout
|
|
117
|
-
retries: config.retries
|
|
116
|
+
timeout: config.timeout ?? 3e4,
|
|
117
|
+
retries: config.retries ?? 3,
|
|
118
118
|
headers: config.headers ?? {},
|
|
119
|
-
sessionCacheTtl: config.sessionCacheTtl
|
|
119
|
+
sessionCacheTtl: config.sessionCacheTtl ?? 3e5,
|
|
120
120
|
baseUrl: config.baseUrl ?? null
|
|
121
121
|
};
|
|
122
122
|
}
|
|
@@ -206,12 +206,18 @@ var JmapHttpClient = class {
|
|
|
206
206
|
const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
|
|
207
207
|
let combinedSignal = controller.signal;
|
|
208
208
|
if (signal) {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
209
|
+
const AbortSignalAny = AbortSignal.any;
|
|
210
|
+
if (typeof AbortSignalAny === "function") combinedSignal = AbortSignalAny([signal, controller.signal]);
|
|
211
|
+
else {
|
|
212
|
+
if (signal.aborted) {
|
|
213
|
+
clearTimeout(timeoutId);
|
|
214
|
+
signal.throwIfAborted();
|
|
215
|
+
}
|
|
216
|
+
signal.addEventListener("abort", () => {
|
|
217
|
+
controller.abort(signal.reason);
|
|
218
|
+
});
|
|
219
|
+
combinedSignal = controller.signal;
|
|
212
220
|
}
|
|
213
|
-
signal.addEventListener("abort", () => controller.abort());
|
|
214
|
-
combinedSignal = controller.signal;
|
|
215
221
|
}
|
|
216
222
|
try {
|
|
217
223
|
return await globalThis.fetch(url, {
|
|
@@ -526,10 +532,14 @@ var JmapTransport = class {
|
|
|
526
532
|
const messageArray = [];
|
|
527
533
|
for await (const message of messages) messageArray.push(message);
|
|
528
534
|
if (messageArray.length === 0) return;
|
|
535
|
+
let processingStage = "initialization";
|
|
536
|
+
let attachmentsUploadedCount = 0;
|
|
529
537
|
try {
|
|
530
538
|
signal?.throwIfAborted();
|
|
539
|
+
processingStage = "session fetch";
|
|
531
540
|
const session = await this.getSession(signal);
|
|
532
541
|
signal?.throwIfAborted();
|
|
542
|
+
processingStage = "account discovery";
|
|
533
543
|
const accountId = this.config.accountId ?? findMailAccount(session);
|
|
534
544
|
if (!accountId) {
|
|
535
545
|
for (let i = 0; i < messageArray.length; i++) yield {
|
|
@@ -538,17 +548,22 @@ var JmapTransport = class {
|
|
|
538
548
|
};
|
|
539
549
|
return;
|
|
540
550
|
}
|
|
551
|
+
processingStage = "mailbox discovery";
|
|
541
552
|
const draftsMailboxId = await this.getDraftsMailboxId(session, accountId, signal);
|
|
542
553
|
signal?.throwIfAborted();
|
|
554
|
+
processingStage = "identity resolution";
|
|
543
555
|
const identityMap = await this.getIdentityMap(session, accountId, signal);
|
|
544
556
|
signal?.throwIfAborted();
|
|
557
|
+
processingStage = "attachment upload";
|
|
545
558
|
const allUploadedBlobs = /* @__PURE__ */ new Map();
|
|
546
559
|
for (let i = 0; i < messageArray.length; i++) {
|
|
547
560
|
const message = messageArray[i];
|
|
548
561
|
const uploadedBlobs = await this.uploadAttachments(session, accountId, message.attachments, signal);
|
|
549
562
|
allUploadedBlobs.set(i, uploadedBlobs);
|
|
563
|
+
attachmentsUploadedCount = i + 1;
|
|
550
564
|
signal?.throwIfAborted();
|
|
551
565
|
}
|
|
566
|
+
processingStage = "message conversion";
|
|
552
567
|
const emailCreates = {};
|
|
553
568
|
const submissionCreates = {};
|
|
554
569
|
for (let i = 0; i < messageArray.length; i++) {
|
|
@@ -563,6 +578,7 @@ var JmapTransport = class {
|
|
|
563
578
|
emailId: `#draft${i}`
|
|
564
579
|
};
|
|
565
580
|
}
|
|
581
|
+
processingStage = "batch request execution";
|
|
566
582
|
const response = await this.httpClient.executeRequest(session.apiUrl, {
|
|
567
583
|
using: [
|
|
568
584
|
JMAP_CAPABILITIES.core,
|
|
@@ -587,10 +603,12 @@ var JmapTransport = class {
|
|
|
587
603
|
}, signal);
|
|
588
604
|
for (let i = 0; i < messageArray.length; i++) yield this.parseBatchResponseForIndex(response, i);
|
|
589
605
|
} catch (error) {
|
|
590
|
-
const
|
|
606
|
+
const baseMessage = error instanceof Error && error.name === "AbortError" ? `Request aborted: ${error.message}` : error instanceof JmapApiError ? error.message : error instanceof Error ? error.message : String(error);
|
|
607
|
+
let detailedMessage = `Failed during ${processingStage}: ${baseMessage}`;
|
|
608
|
+
if (processingStage === "attachment upload" && attachmentsUploadedCount > 0) detailedMessage += ` (${attachmentsUploadedCount}/${messageArray.length} messages had attachments uploaded before failure)`;
|
|
591
609
|
for (let i = 0; i < messageArray.length; i++) yield {
|
|
592
610
|
successful: false,
|
|
593
|
-
errorMessages: [
|
|
611
|
+
errorMessages: [detailedMessage]
|
|
594
612
|
};
|
|
595
613
|
}
|
|
596
614
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@upyo/jmap",
|
|
3
|
-
"version": "0.4.0-dev.
|
|
3
|
+
"version": "0.4.0-dev.77+40049302",
|
|
4
4
|
"description": "JMAP transport for Upyo email library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"email",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
},
|
|
54
54
|
"sideEffects": false,
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@upyo/core": "0.4.0-dev.
|
|
56
|
+
"@upyo/core": "0.4.0-dev.77+40049302"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@dotenvx/dotenvx": "^1.47.3",
|