@pallasoft/ps-mail 1.0.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/LICENSE +32 -0
- package/README.md +33 -0
- package/dist/constants/mail-http-config.d.ts +11 -0
- package/dist/constants/mail-http-config.js +14 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/microsoft/constants/graph-mail-body-type.d.ts +4 -0
- package/dist/microsoft/constants/graph-mail-body-type.js +8 -0
- package/dist/microsoft/constants/graph-mail-config.d.ts +42 -0
- package/dist/microsoft/constants/graph-mail-config.js +80 -0
- package/dist/microsoft/constants/graph-mail-error-messages.d.ts +2 -0
- package/dist/microsoft/constants/graph-mail-error-messages.js +12 -0
- package/dist/microsoft/constants/graph-mail-error-reason.d.ts +7 -0
- package/dist/microsoft/constants/graph-mail-error-reason.js +11 -0
- package/dist/microsoft/constants/graph-mail-folder.d.ts +4 -0
- package/dist/microsoft/constants/graph-mail-folder.js +8 -0
- package/dist/microsoft/constants/index.d.ts +5 -0
- package/dist/microsoft/constants/index.js +21 -0
- package/dist/microsoft/index.d.ts +3 -0
- package/dist/microsoft/index.js +10 -0
- package/dist/microsoft/models/graph-access-token-data.d.ts +4 -0
- package/dist/microsoft/models/graph-access-token-data.js +2 -0
- package/dist/microsoft/models/graph-collection-response.d.ts +5 -0
- package/dist/microsoft/models/graph-collection-response.js +2 -0
- package/dist/microsoft/models/graph-credentials.d.ts +6 -0
- package/dist/microsoft/models/graph-credentials.js +2 -0
- package/dist/microsoft/models/graph-error-detail-data.d.ts +4 -0
- package/dist/microsoft/models/graph-error-detail-data.js +2 -0
- package/dist/microsoft/models/graph-error-response.d.ts +4 -0
- package/dist/microsoft/models/graph-error-response.js +2 -0
- package/dist/microsoft/models/graph-mail-attachment-data.d.ts +8 -0
- package/dist/microsoft/models/graph-mail-attachment-data.js +2 -0
- package/dist/microsoft/models/graph-mail-body-data.d.ts +5 -0
- package/dist/microsoft/models/graph-mail-body-data.js +2 -0
- package/dist/microsoft/models/graph-mail-categories-request.d.ts +3 -0
- package/dist/microsoft/models/graph-mail-categories-request.js +2 -0
- package/dist/microsoft/models/graph-mail-connection.d.ts +4 -0
- package/dist/microsoft/models/graph-mail-connection.js +2 -0
- package/dist/microsoft/models/graph-mail-delta-data.d.ts +6 -0
- package/dist/microsoft/models/graph-mail-delta-data.js +2 -0
- package/dist/microsoft/models/graph-mail-delta-options.d.ts +4 -0
- package/dist/microsoft/models/graph-mail-delta-options.js +2 -0
- package/dist/microsoft/models/graph-mail-delta-page-data.d.ts +7 -0
- package/dist/microsoft/models/graph-mail-delta-page-data.js +2 -0
- package/dist/microsoft/models/graph-mail-draft-data.d.ts +11 -0
- package/dist/microsoft/models/graph-mail-draft-data.js +2 -0
- package/dist/microsoft/models/graph-mail-error-data.d.ts +7 -0
- package/dist/microsoft/models/graph-mail-error-data.js +2 -0
- package/dist/microsoft/models/graph-mail-header-data.d.ts +4 -0
- package/dist/microsoft/models/graph-mail-header-data.js +2 -0
- package/dist/microsoft/models/graph-mail-message-data.d.ts +25 -0
- package/dist/microsoft/models/graph-mail-message-data.js +2 -0
- package/dist/microsoft/models/graph-mail-outgoing-message-data.d.ts +11 -0
- package/dist/microsoft/models/graph-mail-outgoing-message-data.js +2 -0
- package/dist/microsoft/models/graph-mail-recipient-data.d.ts +4 -0
- package/dist/microsoft/models/graph-mail-recipient-data.js +2 -0
- package/dist/microsoft/models/graph-mail-removed-data.d.ts +3 -0
- package/dist/microsoft/models/graph-mail-removed-data.js +2 -0
- package/dist/microsoft/models/graph-mail-reply-data.d.ts +9 -0
- package/dist/microsoft/models/graph-mail-reply-data.js +2 -0
- package/dist/microsoft/models/graph-mail-reply-request.d.ts +4 -0
- package/dist/microsoft/models/graph-mail-reply-request.js +2 -0
- package/dist/microsoft/models/graph-mail-send-request.d.ts +5 -0
- package/dist/microsoft/models/graph-mail-send-request.js +2 -0
- package/dist/microsoft/models/graph-request-data.d.ts +7 -0
- package/dist/microsoft/models/graph-request-data.js +2 -0
- package/dist/microsoft/models/graph-token-response.d.ts +5 -0
- package/dist/microsoft/models/graph-token-response.js +2 -0
- package/dist/microsoft/models/index.d.ts +24 -0
- package/dist/microsoft/models/index.js +2 -0
- package/dist/microsoft/services/graph-mail-error-service.d.ts +13 -0
- package/dist/microsoft/services/graph-mail-error-service.js +153 -0
- package/dist/microsoft/services/graph-mail-service.d.ts +32 -0
- package/dist/microsoft/services/graph-mail-service.js +352 -0
- package/dist/microsoft/services/graph-request-service.d.ts +11 -0
- package/dist/microsoft/services/graph-request-service.js +206 -0
- package/dist/microsoft/services/graph-token-service.d.ts +10 -0
- package/dist/microsoft/services/graph-token-service.js +137 -0
- package/dist/microsoft/services/index.d.ts +4 -0
- package/dist/microsoft/services/index.js +20 -0
- package/dist/models/index.d.ts +5 -0
- package/dist/models/index.js +2 -0
- package/dist/models/mail-address-data.d.ts +4 -0
- package/dist/models/mail-address-data.js +2 -0
- package/dist/models/mail-attachment-content-data.d.ts +4 -0
- package/dist/models/mail-attachment-content-data.js +2 -0
- package/dist/models/mail-attachment-data.d.ts +7 -0
- package/dist/models/mail-attachment-data.js +2 -0
- package/dist/models/mail-query-parameter.d.ts +4 -0
- package/dist/models/mail-query-parameter.js +2 -0
- package/dist/models/mail-sent-data.d.ts +5 -0
- package/dist/models/mail-sent-data.js +2 -0
- package/dist/resend/constants/index.d.ts +2 -0
- package/dist/resend/constants/index.js +18 -0
- package/dist/resend/constants/resend-mail-config.d.ts +24 -0
- package/dist/resend/constants/resend-mail-config.js +27 -0
- package/dist/resend/constants/resend-webhook-config.d.ts +16 -0
- package/dist/resend/constants/resend-webhook-config.js +19 -0
- package/dist/resend/index.d.ts +2 -0
- package/dist/resend/index.js +7 -0
- package/dist/resend/models/index.d.ts +15 -0
- package/dist/resend/models/index.js +2 -0
- package/dist/resend/models/resend-attachment-row.d.ts +9 -0
- package/dist/resend/models/resend-attachment-row.js +2 -0
- package/dist/resend/models/resend-authentication-data.d.ts +5 -0
- package/dist/resend/models/resend-authentication-data.js +2 -0
- package/dist/resend/models/resend-connection.d.ts +5 -0
- package/dist/resend/models/resend-connection.js +2 -0
- package/dist/resend/models/resend-error-response.d.ts +5 -0
- package/dist/resend/models/resend-error-response.js +2 -0
- package/dist/resend/models/resend-list-response.d.ts +3 -0
- package/dist/resend/models/resend-list-response.js +2 -0
- package/dist/resend/models/resend-mail-error-data.d.ts +4 -0
- package/dist/resend/models/resend-mail-error-data.js +2 -0
- package/dist/resend/models/resend-received-attachment-data.d.ts +4 -0
- package/dist/resend/models/resend-received-attachment-data.js +2 -0
- package/dist/resend/models/resend-received-email-data.d.ts +20 -0
- package/dist/resend/models/resend-received-email-data.js +2 -0
- package/dist/resend/models/resend-received-email-row.d.ts +21 -0
- package/dist/resend/models/resend-received-email-row.js +2 -0
- package/dist/resend/models/resend-send-attachment-data.d.ts +6 -0
- package/dist/resend/models/resend-send-attachment-data.js +2 -0
- package/dist/resend/models/resend-send-attachment-request.d.ts +6 -0
- package/dist/resend/models/resend-send-attachment-request.js +2 -0
- package/dist/resend/models/resend-send-data.d.ts +15 -0
- package/dist/resend/models/resend-send-data.js +2 -0
- package/dist/resend/models/resend-send-request.d.ts +13 -0
- package/dist/resend/models/resend-send-request.js +2 -0
- package/dist/resend/models/resend-send-response.d.ts +3 -0
- package/dist/resend/models/resend-send-response.js +2 -0
- package/dist/resend/models/resend-webhook-headers.d.ts +1 -0
- package/dist/resend/models/resend-webhook-headers.js +2 -0
- package/dist/resend/services/index.d.ts +3 -0
- package/dist/resend/services/index.js +19 -0
- package/dist/resend/services/resend-mail-error-service.d.ts +7 -0
- package/dist/resend/services/resend-mail-error-service.js +79 -0
- package/dist/resend/services/resend-mail-service.d.ts +22 -0
- package/dist/resend/services/resend-mail-service.js +322 -0
- package/dist/resend/services/resend-webhook-service.d.ts +10 -0
- package/dist/resend/services/resend-webhook-service.js +139 -0
- package/dist/services/mail-fetch-failure-service.d.ts +3 -0
- package/dist/services/mail-fetch-failure-service.js +49 -0
- package/dist/services/mail-url-service.d.ts +5 -0
- package/dist/services/mail-url-service.js +27 -0
- package/package.json +88 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ResendAuthenticationData } from './resend-authentication-data';
|
|
2
|
+
import type { ResendReceivedAttachmentData } from './resend-received-attachment-data';
|
|
3
|
+
export interface ResendReceivedEmailData {
|
|
4
|
+
id: string;
|
|
5
|
+
from: string;
|
|
6
|
+
to: string[];
|
|
7
|
+
cc: string[];
|
|
8
|
+
bcc: string[];
|
|
9
|
+
replyTo: string[];
|
|
10
|
+
receivedFor: string[];
|
|
11
|
+
subject: string | null;
|
|
12
|
+
receivedAt: string | null;
|
|
13
|
+
text: string | null;
|
|
14
|
+
html: string | null;
|
|
15
|
+
headers: Record<string, string>;
|
|
16
|
+
messageId: string | null;
|
|
17
|
+
authentication: ResendAuthenticationData | null;
|
|
18
|
+
hasAttachments: boolean;
|
|
19
|
+
attachments: ResendReceivedAttachmentData[];
|
|
20
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ResendAttachmentRow } from './resend-attachment-row';
|
|
2
|
+
import type { ResendAuthenticationData } from './resend-authentication-data';
|
|
3
|
+
export interface ResendReceivedEmailRow {
|
|
4
|
+
id?: string;
|
|
5
|
+
from?: string;
|
|
6
|
+
to?: string[] | null;
|
|
7
|
+
cc?: string[] | null;
|
|
8
|
+
bcc?: string[] | null;
|
|
9
|
+
reply_to?: string[] | null;
|
|
10
|
+
received_for?: string[] | null;
|
|
11
|
+
subject?: string | null;
|
|
12
|
+
created_at?: string;
|
|
13
|
+
received_at?: string;
|
|
14
|
+
text?: string | null;
|
|
15
|
+
html?: string | null;
|
|
16
|
+
headers?: Record<string, string> | null;
|
|
17
|
+
message_id?: string | null;
|
|
18
|
+
authentication?: ResendAuthenticationData | null;
|
|
19
|
+
has_attachments?: boolean;
|
|
20
|
+
attachments?: ResendAttachmentRow[] | null;
|
|
21
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { MailAddressData } from '../../models/mail-address-data';
|
|
2
|
+
import type { ResendSendAttachmentData } from './resend-send-attachment-data';
|
|
3
|
+
export interface ResendSendData {
|
|
4
|
+
from: MailAddressData;
|
|
5
|
+
to: MailAddressData[];
|
|
6
|
+
subject: string;
|
|
7
|
+
html?: string;
|
|
8
|
+
text?: string;
|
|
9
|
+
cc?: MailAddressData[];
|
|
10
|
+
bcc?: MailAddressData[];
|
|
11
|
+
replyTo?: MailAddressData[];
|
|
12
|
+
headers?: Record<string, string>;
|
|
13
|
+
attachments?: ResendSendAttachmentData[];
|
|
14
|
+
idempotencyKey?: string;
|
|
15
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ResendSendAttachmentRequest } from './resend-send-attachment-request';
|
|
2
|
+
export interface ResendSendRequest {
|
|
3
|
+
from: string;
|
|
4
|
+
to: string[];
|
|
5
|
+
subject: string;
|
|
6
|
+
html?: string;
|
|
7
|
+
text?: string;
|
|
8
|
+
cc?: string[];
|
|
9
|
+
bcc?: string[];
|
|
10
|
+
reply_to?: string[];
|
|
11
|
+
headers?: Record<string, string>;
|
|
12
|
+
attachments?: ResendSendAttachmentRequest[];
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type ResendWebhookHeaders = Headers | Record<string, string>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./resend-mail-error-service"), exports);
|
|
18
|
+
__exportStar(require("./resend-mail-service"), exports);
|
|
19
|
+
__exportStar(require("./resend-webhook-service"), exports);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ResendMailErrorData } from '../models/resend-mail-error-data';
|
|
2
|
+
export declare class ResendMailErrorService {
|
|
3
|
+
static create(message: string, status: number, providerCode?: string | null): ResendMailErrorData;
|
|
4
|
+
static fromResponse(response: Response): Promise<ResendMailErrorData>;
|
|
5
|
+
static fromFetchFailure(error: unknown): ResendMailErrorData;
|
|
6
|
+
static isResendMailError(error: unknown): error is ResendMailErrorData;
|
|
7
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.ResendMailErrorService = void 0;
|
|
40
|
+
var ps_utilities_1 = require("@pallasoft/ps-utilities");
|
|
41
|
+
var mail_fetch_failure_service_1 = require("../../services/mail-fetch-failure-service");
|
|
42
|
+
var resend_mail_config_1 = require("../constants/resend-mail-config");
|
|
43
|
+
var ResendMailErrorService = /** @class */ (function () {
|
|
44
|
+
function ResendMailErrorService() {
|
|
45
|
+
}
|
|
46
|
+
ResendMailErrorService.create = function (message, status, providerCode) {
|
|
47
|
+
if (providerCode === void 0) { providerCode = null; }
|
|
48
|
+
return Object.assign(ps_utilities_1.Common.ErrorResponseService.create(message, status), { providerCode: providerCode });
|
|
49
|
+
};
|
|
50
|
+
ResendMailErrorService.fromResponse = function (response) {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
52
|
+
var body, _a, _b, failure;
|
|
53
|
+
return __generator(this, function (_c) {
|
|
54
|
+
switch (_c.label) {
|
|
55
|
+
case 0:
|
|
56
|
+
_b = (_a = ps_utilities_1.Common.JsonService).read;
|
|
57
|
+
return [4 /*yield*/, response.text().catch(function () { return ''; })];
|
|
58
|
+
case 1:
|
|
59
|
+
body = _b.apply(_a, [_c.sent()]);
|
|
60
|
+
failure = typeof body === 'object' && body !== null ? body : {};
|
|
61
|
+
return [2 /*return*/, this.create(typeof failure.message === 'string' && failure.message !== ''
|
|
62
|
+
? failure.message
|
|
63
|
+
: resend_mail_config_1.ResendMailConfig.unknownErrorMessage, response.status, typeof failure.name === 'string' && failure.name !== '' ? failure.name : null)];
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
ResendMailErrorService.fromFetchFailure = function (error) {
|
|
69
|
+
return this.create(resend_mail_config_1.ResendMailConfig.unreachableMessage, mail_fetch_failure_service_1.MailFetchFailureService.status(error));
|
|
70
|
+
};
|
|
71
|
+
ResendMailErrorService.isResendMailError = function (error) {
|
|
72
|
+
return (error instanceof Error &&
|
|
73
|
+
'providerCode' in error &&
|
|
74
|
+
'code' in error &&
|
|
75
|
+
typeof error.code === 'number');
|
|
76
|
+
};
|
|
77
|
+
return ResendMailErrorService;
|
|
78
|
+
}());
|
|
79
|
+
exports.ResendMailErrorService = ResendMailErrorService;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { MailAddressData } from '../../models/mail-address-data';
|
|
2
|
+
import type { MailAttachmentContentData } from '../../models/mail-attachment-content-data';
|
|
3
|
+
import type { MailSentData } from '../../models/mail-sent-data';
|
|
4
|
+
import type { ResendConnection } from '../models/resend-connection';
|
|
5
|
+
import type { ResendReceivedAttachmentData } from '../models/resend-received-attachment-data';
|
|
6
|
+
import type { ResendReceivedEmailData } from '../models/resend-received-email-data';
|
|
7
|
+
import type { ResendSendData } from '../models/resend-send-data';
|
|
8
|
+
export declare class ResendMailService {
|
|
9
|
+
static send(connection: ResendConnection, data: ResendSendData): Promise<MailSentData>;
|
|
10
|
+
static listReceived(connection: ResendConnection, limit: number): Promise<ResendReceivedEmailData[]>;
|
|
11
|
+
static getReceived(connection: ResendConnection, emailId: string): Promise<ResendReceivedEmailData>;
|
|
12
|
+
static listReceivedAttachments(connection: ResendConnection, emailId: string): Promise<ResendReceivedAttachmentData[]>;
|
|
13
|
+
static downloadAttachment(downloadUrl: string, timeoutMs?: number): Promise<MailAttachmentContentData>;
|
|
14
|
+
static formatAddress(address: MailAddressData): string;
|
|
15
|
+
private static _request;
|
|
16
|
+
private static _received;
|
|
17
|
+
private static _attachment;
|
|
18
|
+
private static _attachmentRequest;
|
|
19
|
+
private static _addresses;
|
|
20
|
+
private static _list;
|
|
21
|
+
private static _path;
|
|
22
|
+
}
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}) : (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
o[k2] = m[k];
|
|
23
|
+
}));
|
|
24
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
+
}) : function(o, v) {
|
|
27
|
+
o["default"] = v;
|
|
28
|
+
});
|
|
29
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
30
|
+
var ownKeys = function(o) {
|
|
31
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
32
|
+
var ar = [];
|
|
33
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
34
|
+
return ar;
|
|
35
|
+
};
|
|
36
|
+
return ownKeys(o);
|
|
37
|
+
};
|
|
38
|
+
return function (mod) {
|
|
39
|
+
if (mod && mod.__esModule) return mod;
|
|
40
|
+
var result = {};
|
|
41
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
42
|
+
__setModuleDefault(result, mod);
|
|
43
|
+
return result;
|
|
44
|
+
};
|
|
45
|
+
})();
|
|
46
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
47
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
48
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
49
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
50
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
51
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
52
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
56
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
57
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
58
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
59
|
+
function step(op) {
|
|
60
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
61
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
62
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
63
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
64
|
+
switch (op[0]) {
|
|
65
|
+
case 0: case 1: t = op; break;
|
|
66
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
67
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
68
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
69
|
+
default:
|
|
70
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
71
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
72
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
73
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
74
|
+
if (t[2]) _.ops.pop();
|
|
75
|
+
_.trys.pop(); continue;
|
|
76
|
+
}
|
|
77
|
+
op = body.call(thisArg, _);
|
|
78
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
79
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
83
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
84
|
+
if (ar || !(i in from)) {
|
|
85
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
86
|
+
ar[i] = from[i];
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
90
|
+
};
|
|
91
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
92
|
+
exports.ResendMailService = void 0;
|
|
93
|
+
var Attributes = __importStar(require("@pallasoft/ps-attributes"));
|
|
94
|
+
var ps_utilities_1 = require("@pallasoft/ps-utilities");
|
|
95
|
+
var mail_url_service_1 = require("../../services/mail-url-service");
|
|
96
|
+
var resend_mail_config_1 = require("../constants/resend-mail-config");
|
|
97
|
+
var resend_mail_error_service_1 = require("./resend-mail-error-service");
|
|
98
|
+
var ResendMailService = /** @class */ (function () {
|
|
99
|
+
function ResendMailService() {
|
|
100
|
+
}
|
|
101
|
+
ResendMailService.send = function (connection, data) {
|
|
102
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
103
|
+
var request, headers, body;
|
|
104
|
+
var _this = this;
|
|
105
|
+
return __generator(this, function (_a) {
|
|
106
|
+
switch (_a.label) {
|
|
107
|
+
case 0:
|
|
108
|
+
request = {
|
|
109
|
+
from: this.formatAddress(data.from),
|
|
110
|
+
to: this._addresses(data.to),
|
|
111
|
+
subject: data.subject,
|
|
112
|
+
};
|
|
113
|
+
if (data.html !== undefined)
|
|
114
|
+
request.html = data.html;
|
|
115
|
+
if (data.text !== undefined)
|
|
116
|
+
request.text = data.text;
|
|
117
|
+
if (data.cc !== undefined)
|
|
118
|
+
request.cc = this._addresses(data.cc);
|
|
119
|
+
if (data.bcc !== undefined)
|
|
120
|
+
request.bcc = this._addresses(data.bcc);
|
|
121
|
+
if (data.replyTo !== undefined)
|
|
122
|
+
request.reply_to = this._addresses(data.replyTo);
|
|
123
|
+
if (data.headers !== undefined)
|
|
124
|
+
request.headers = data.headers;
|
|
125
|
+
if (data.attachments !== undefined)
|
|
126
|
+
request.attachments = data.attachments.map(function (attachment) {
|
|
127
|
+
return _this._attachmentRequest(attachment);
|
|
128
|
+
});
|
|
129
|
+
headers = {};
|
|
130
|
+
if (data.idempotencyKey !== undefined)
|
|
131
|
+
headers[ps_utilities_1.Common.HttpHeader.idempotencyKey] = data.idempotencyKey;
|
|
132
|
+
return [4 /*yield*/, this._request(connection, ps_utilities_1.HttpMethod.Post, this._path(resend_mail_config_1.ResendMailConfig.paths.emails), request, headers)];
|
|
133
|
+
case 1:
|
|
134
|
+
body = _a.sent();
|
|
135
|
+
if (typeof body.id !== 'string' || body.id === '')
|
|
136
|
+
throw resend_mail_error_service_1.ResendMailErrorService.create(resend_mail_config_1.ResendMailConfig.missingIdMessage, Attributes.Common.Response.ErrorCodes.BadGateway);
|
|
137
|
+
return [2 /*return*/, { id: body.id, conversationId: null, internetMessageId: null }];
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
ResendMailService.listReceived = function (connection, limit) {
|
|
143
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
144
|
+
var body;
|
|
145
|
+
var _this = this;
|
|
146
|
+
return __generator(this, function (_a) {
|
|
147
|
+
switch (_a.label) {
|
|
148
|
+
case 0: return [4 /*yield*/, this._request(connection, ps_utilities_1.HttpMethod.Get, mail_url_service_1.MailUrlService.withQuery(this._path(resend_mail_config_1.ResendMailConfig.paths.emails, resend_mail_config_1.ResendMailConfig.paths.receiving), [{ key: resend_mail_config_1.ResendMailConfig.query.limit, value: String(limit) }]))];
|
|
149
|
+
case 1:
|
|
150
|
+
body = _a.sent();
|
|
151
|
+
return [2 /*return*/, (Array.isArray(body.data) ? body.data : []).map(function (row) { return _this._received(row, ''); })];
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
ResendMailService.getReceived = function (connection, emailId) {
|
|
157
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
158
|
+
var row;
|
|
159
|
+
return __generator(this, function (_a) {
|
|
160
|
+
switch (_a.label) {
|
|
161
|
+
case 0: return [4 /*yield*/, this._request(connection, ps_utilities_1.HttpMethod.Get, mail_url_service_1.MailUrlService.withQuery(this._path(resend_mail_config_1.ResendMailConfig.paths.emails, resend_mail_config_1.ResendMailConfig.paths.receiving, encodeURIComponent(emailId)), [{ key: resend_mail_config_1.ResendMailConfig.query.htmlFormat, value: resend_mail_config_1.ResendMailConfig.htmlFormat }]))];
|
|
162
|
+
case 1:
|
|
163
|
+
row = _a.sent();
|
|
164
|
+
return [2 /*return*/, this._received(row, emailId)];
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
};
|
|
169
|
+
ResendMailService.listReceivedAttachments = function (connection, emailId) {
|
|
170
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
171
|
+
var body;
|
|
172
|
+
var _this = this;
|
|
173
|
+
return __generator(this, function (_a) {
|
|
174
|
+
switch (_a.label) {
|
|
175
|
+
case 0: return [4 /*yield*/, this._request(connection, ps_utilities_1.HttpMethod.Get, this._path(resend_mail_config_1.ResendMailConfig.paths.emails, resend_mail_config_1.ResendMailConfig.paths.receiving, encodeURIComponent(emailId), resend_mail_config_1.ResendMailConfig.paths.attachments))];
|
|
176
|
+
case 1:
|
|
177
|
+
body = _a.sent();
|
|
178
|
+
return [2 /*return*/, (Array.isArray(body.data) ? body.data : []).map(function (row) { return _this._attachment(row); })];
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
};
|
|
183
|
+
ResendMailService.downloadAttachment = function (downloadUrl, timeoutMs) {
|
|
184
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
185
|
+
var response, contentType;
|
|
186
|
+
var _a;
|
|
187
|
+
return __generator(this, function (_b) {
|
|
188
|
+
switch (_b.label) {
|
|
189
|
+
case 0: return [4 /*yield*/, fetch(downloadUrl, {
|
|
190
|
+
method: ps_utilities_1.HttpMethod.Get,
|
|
191
|
+
signal: typeof timeoutMs === 'number' ? AbortSignal.timeout(timeoutMs) : undefined,
|
|
192
|
+
}).catch(function (error) {
|
|
193
|
+
throw resend_mail_error_service_1.ResendMailErrorService.fromFetchFailure(error);
|
|
194
|
+
})];
|
|
195
|
+
case 1:
|
|
196
|
+
response = _b.sent();
|
|
197
|
+
if (!response.ok)
|
|
198
|
+
throw resend_mail_error_service_1.ResendMailErrorService.create(resend_mail_config_1.ResendMailConfig.downloadErrorMessage, response.status);
|
|
199
|
+
contentType = response.headers.get(ps_utilities_1.Common.HttpHeader.contentType);
|
|
200
|
+
_a = {};
|
|
201
|
+
return [4 /*yield*/, response.arrayBuffer()];
|
|
202
|
+
case 2: return [2 /*return*/, (_a.content = _b.sent(),
|
|
203
|
+
_a.contentType = contentType === null ? ps_utilities_1.Common.HttpContentType.octetStream : contentType,
|
|
204
|
+
_a)];
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
};
|
|
209
|
+
ResendMailService.formatAddress = function (address) {
|
|
210
|
+
if (typeof address.name !== 'string' || address.name.trim() === '')
|
|
211
|
+
return address.address;
|
|
212
|
+
var name = address.name.trim();
|
|
213
|
+
var display = resend_mail_config_1.ResendMailConfig.addressQuoted.test(name)
|
|
214
|
+
? "".concat(resend_mail_config_1.ResendMailConfig.addressQuote).concat(name.replace(resend_mail_config_1.ResendMailConfig.addressQuoteEscape, resend_mail_config_1.ResendMailConfig.addressQuoteEscapeReplacement)).concat(resend_mail_config_1.ResendMailConfig.addressQuote)
|
|
215
|
+
: name;
|
|
216
|
+
return "".concat(display).concat(resend_mail_config_1.ResendMailConfig.addressOpen).concat(address.address).concat(resend_mail_config_1.ResendMailConfig.addressClose);
|
|
217
|
+
};
|
|
218
|
+
ResendMailService._request = function (connection_1, method_1, path_1, payload_1) {
|
|
219
|
+
return __awaiter(this, arguments, void 0, function (connection, method, path, payload, extraHeaders) {
|
|
220
|
+
var headers, response, body, _a, _b;
|
|
221
|
+
var _c;
|
|
222
|
+
if (extraHeaders === void 0) { extraHeaders = {}; }
|
|
223
|
+
return __generator(this, function (_d) {
|
|
224
|
+
switch (_d.label) {
|
|
225
|
+
case 0:
|
|
226
|
+
headers = __assign((_c = {}, _c[ps_utilities_1.Common.HttpHeader.authorization] = "".concat(ps_utilities_1.Common.HttpAuthScheme.bearerPrefix).concat(connection.apiKey), _c), extraHeaders);
|
|
227
|
+
if (payload !== undefined)
|
|
228
|
+
headers[ps_utilities_1.Common.HttpHeader.contentType] = ps_utilities_1.Common.HttpContentType.json;
|
|
229
|
+
return [4 /*yield*/, fetch("".concat(connection.baseUrl).concat(path), {
|
|
230
|
+
method: method,
|
|
231
|
+
headers: headers,
|
|
232
|
+
body: payload === undefined ? undefined : JSON.stringify(payload),
|
|
233
|
+
signal: typeof connection.timeoutMs === 'number'
|
|
234
|
+
? AbortSignal.timeout(connection.timeoutMs)
|
|
235
|
+
: undefined,
|
|
236
|
+
}).catch(function (error) {
|
|
237
|
+
throw resend_mail_error_service_1.ResendMailErrorService.fromFetchFailure(error);
|
|
238
|
+
})];
|
|
239
|
+
case 1:
|
|
240
|
+
response = _d.sent();
|
|
241
|
+
if (!!response.ok) return [3 /*break*/, 3];
|
|
242
|
+
return [4 /*yield*/, resend_mail_error_service_1.ResendMailErrorService.fromResponse(response)];
|
|
243
|
+
case 2: throw _d.sent();
|
|
244
|
+
case 3:
|
|
245
|
+
_b = (_a = ps_utilities_1.Common.JsonService).read;
|
|
246
|
+
return [4 /*yield*/, response.text()];
|
|
247
|
+
case 4:
|
|
248
|
+
body = _b.apply(_a, [_d.sent()]);
|
|
249
|
+
return [2 /*return*/, (typeof body === 'object' && body !== null ? body : {})];
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
};
|
|
254
|
+
ResendMailService._received = function (row, fallbackId) {
|
|
255
|
+
var _this = this;
|
|
256
|
+
var attachments = Array.isArray(row.attachments) ? row.attachments : [];
|
|
257
|
+
return {
|
|
258
|
+
id: typeof row.id === 'string' ? row.id : fallbackId,
|
|
259
|
+
from: typeof row.from === 'string' ? row.from : '',
|
|
260
|
+
to: this._list(row.to),
|
|
261
|
+
cc: this._list(row.cc),
|
|
262
|
+
bcc: this._list(row.bcc),
|
|
263
|
+
replyTo: this._list(row.reply_to),
|
|
264
|
+
receivedFor: this._list(row.received_for),
|
|
265
|
+
subject: typeof row.subject === 'string' ? row.subject : null,
|
|
266
|
+
receivedAt: typeof row.received_at === 'string'
|
|
267
|
+
? row.received_at
|
|
268
|
+
: typeof row.created_at === 'string'
|
|
269
|
+
? row.created_at
|
|
270
|
+
: null,
|
|
271
|
+
text: typeof row.text === 'string' ? row.text : null,
|
|
272
|
+
html: typeof row.html === 'string' ? row.html : null,
|
|
273
|
+
headers: typeof row.headers === 'object' && row.headers !== null ? row.headers : {},
|
|
274
|
+
messageId: typeof row.message_id === 'string' ? row.message_id : null,
|
|
275
|
+
authentication: typeof row.authentication === 'object' && row.authentication !== null
|
|
276
|
+
? row.authentication
|
|
277
|
+
: null,
|
|
278
|
+
hasAttachments: typeof row.has_attachments === 'boolean' ? row.has_attachments : attachments.length > 0,
|
|
279
|
+
attachments: attachments.map(function (attachment) { return _this._attachment(attachment); }),
|
|
280
|
+
};
|
|
281
|
+
};
|
|
282
|
+
ResendMailService._attachment = function (row) {
|
|
283
|
+
return {
|
|
284
|
+
id: typeof row.id === 'string' ? row.id : '',
|
|
285
|
+
fileName: typeof row.filename === 'string' && row.filename !== ''
|
|
286
|
+
? row.filename
|
|
287
|
+
: resend_mail_config_1.ResendMailConfig.fallbackFileName,
|
|
288
|
+
contentType: typeof row.content_type === 'string' && row.content_type !== ''
|
|
289
|
+
? row.content_type
|
|
290
|
+
: ps_utilities_1.Common.HttpContentType.octetStream,
|
|
291
|
+
sizeBytes: typeof row.size === 'number' ? row.size : 0,
|
|
292
|
+
inline: row.content_disposition === resend_mail_config_1.ResendMailConfig.inlineDisposition,
|
|
293
|
+
downloadUrl: typeof row.download_url === 'string' ? row.download_url : null,
|
|
294
|
+
};
|
|
295
|
+
};
|
|
296
|
+
ResendMailService._attachmentRequest = function (attachment) {
|
|
297
|
+
var request = {
|
|
298
|
+
content: ps_utilities_1.Common.Base64Service.encode(attachment.content),
|
|
299
|
+
filename: attachment.fileName,
|
|
300
|
+
content_type: attachment.contentType,
|
|
301
|
+
};
|
|
302
|
+
if (attachment.contentId !== undefined)
|
|
303
|
+
request.content_id = attachment.contentId;
|
|
304
|
+
return request;
|
|
305
|
+
};
|
|
306
|
+
ResendMailService._addresses = function (addresses) {
|
|
307
|
+
var _this = this;
|
|
308
|
+
return addresses.map(function (address) { return _this.formatAddress(address); });
|
|
309
|
+
};
|
|
310
|
+
ResendMailService._list = function (value) {
|
|
311
|
+
return Array.isArray(value) ? value.filter(function (item) { return typeof item === 'string'; }) : [];
|
|
312
|
+
};
|
|
313
|
+
ResendMailService._path = function () {
|
|
314
|
+
var segments = [];
|
|
315
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
316
|
+
segments[_i] = arguments[_i];
|
|
317
|
+
}
|
|
318
|
+
return mail_url_service_1.MailUrlService.path.apply(mail_url_service_1.MailUrlService, __spreadArray([''], segments, false));
|
|
319
|
+
};
|
|
320
|
+
return ResendMailService;
|
|
321
|
+
}());
|
|
322
|
+
exports.ResendMailService = ResendMailService;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ResendWebhookHeaders } from '../models/resend-webhook-headers';
|
|
2
|
+
export declare class ResendWebhookService {
|
|
3
|
+
private static _textEncoder;
|
|
4
|
+
static verify(secret: string, body: string, headers: ResendWebhookHeaders): Promise<boolean>;
|
|
5
|
+
private static _isFresh;
|
|
6
|
+
private static _key;
|
|
7
|
+
private static _matches;
|
|
8
|
+
private static _header;
|
|
9
|
+
private static _recordHeader;
|
|
10
|
+
}
|