@pallasoft/ps-mail 1.2.0 → 1.4.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.
@@ -23,6 +23,8 @@ export declare const GraphMailConfig: {
23
23
  readonly filter: "$filter";
24
24
  readonly select: "$select";
25
25
  readonly receivedSinceFilter: "receivedDateTime ge ";
26
+ readonly internetMessageIdFilter: "internetMessageId eq ";
27
+ readonly top: "$top";
26
28
  };
27
29
  readonly prefer: {
28
30
  readonly immutableIds: "IdType=\"ImmutableId\"";
@@ -33,6 +35,9 @@ export declare const GraphMailConfig: {
33
35
  readonly deltaPageSize: 50;
34
36
  readonly deltaFields: readonly ["id", "conversationId", "internetMessageId", "subject", "from", "sender", "toRecipients", "ccRecipients", "replyTo", "receivedDateTime", "sentDateTime", "hasAttachments", "isDraft", "categories", "bodyPreview"];
35
37
  readonly messageFields: readonly ["id", "conversationId", "internetMessageId", "subject", "from", "sender", "toRecipients", "ccRecipients", "replyTo", "receivedDateTime", "sentDateTime", "hasAttachments", "isDraft", "categories", "bodyPreview", "body", "uniqueBody", "internetMessageHeaders"];
38
+ readonly filterQuote: "'";
39
+ readonly locateFields: readonly ["id", "isDraft", "conversationId", "internetMessageId"];
40
+ readonly locateTop: "1";
36
41
  readonly attachmentFields: readonly ["id", "name", "contentType", "size", "isInline"];
37
42
  readonly syncResetErrorCodes: readonly ["syncstatenotfound", "syncstateinvalid", "resyncrequired"];
38
43
  readonly retry: {
@@ -26,6 +26,8 @@ exports.GraphMailConfig = {
26
26
  filter: '$filter',
27
27
  select: '$select',
28
28
  receivedSinceFilter: 'receivedDateTime ge ',
29
+ internetMessageIdFilter: 'internetMessageId eq ',
30
+ top: '$top',
29
31
  },
30
32
  prefer: {
31
33
  immutableIds: 'IdType="ImmutableId"',
@@ -71,6 +73,9 @@ exports.GraphMailConfig = {
71
73
  'uniqueBody',
72
74
  'internetMessageHeaders',
73
75
  ],
76
+ filterQuote: "'",
77
+ locateFields: ['id', 'isDraft', 'conversationId', 'internetMessageId'],
78
+ locateTop: '1',
74
79
  attachmentFields: ['id', 'name', 'contentType', 'size', 'isInline'],
75
80
  syncResetErrorCodes: ['syncstatenotfound', 'syncstateinvalid', 'resyncrequired'],
76
81
  retry: {
@@ -1,3 +1,3 @@
1
1
  export { GraphMailBodyType, GraphMailErrorReason, GraphMailFolder, GraphMailLifecycleEvent, } from './constants';
2
- export { GraphMailErrorService, GraphMailService } from './services';
3
- export type { GraphCredentials, GraphMailBodyData, GraphMailConnection, GraphMailDeltaData, GraphMailDeltaOptions, GraphMailDeltaPageData, GraphMailDraftData, GraphMailErrorData, GraphMailFileData, GraphMailHeaderData, GraphMailMessageData, GraphMailNotificationData, GraphMailNotificationPayloadData, GraphMailRecipientData, GraphMailRemovedData, GraphMailReplyData, GraphMailSubscriptionData, GraphMailSubscriptionOptions, GraphMailUploadSessionData, } from './models';
2
+ export { GraphMailErrorService, GraphMailService, GraphTokenService } from './services';
3
+ export type { GraphCredentials, GraphMailBodyData, GraphMailConnection, GraphMailDeltaData, GraphMailDeltaOptions, GraphMailDeltaPageData, GraphMailDraftData, GraphMailErrorData, GraphMailFileData, GraphMailHeaderData, GraphMailLocatedData, GraphMailMessageData, GraphMailNotificationData, GraphMailNotificationPayloadData, GraphMailRecipientData, GraphMailRemovedData, GraphMailReplyData, GraphMailSubscriptionData, GraphMailSubscriptionOptions, GraphMailUploadSessionData, } from './models';
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GraphMailService = exports.GraphMailErrorService = exports.GraphMailLifecycleEvent = exports.GraphMailFolder = exports.GraphMailErrorReason = exports.GraphMailBodyType = void 0;
3
+ exports.GraphTokenService = exports.GraphMailService = exports.GraphMailErrorService = exports.GraphMailLifecycleEvent = exports.GraphMailFolder = exports.GraphMailErrorReason = exports.GraphMailBodyType = void 0;
4
4
  var constants_1 = require("./constants");
5
5
  Object.defineProperty(exports, "GraphMailBodyType", { enumerable: true, get: function () { return constants_1.GraphMailBodyType; } });
6
6
  Object.defineProperty(exports, "GraphMailErrorReason", { enumerable: true, get: function () { return constants_1.GraphMailErrorReason; } });
@@ -9,3 +9,4 @@ Object.defineProperty(exports, "GraphMailLifecycleEvent", { enumerable: true, ge
9
9
  var services_1 = require("./services");
10
10
  Object.defineProperty(exports, "GraphMailErrorService", { enumerable: true, get: function () { return services_1.GraphMailErrorService; } });
11
11
  Object.defineProperty(exports, "GraphMailService", { enumerable: true, get: function () { return services_1.GraphMailService; } });
12
+ Object.defineProperty(exports, "GraphTokenService", { enumerable: true, get: function () { return services_1.GraphTokenService; } });
@@ -10,4 +10,5 @@ export interface GraphMailDraftData {
10
10
  replyTo?: MailAddressData[];
11
11
  attachments?: GraphMailFileData[];
12
12
  headers?: GraphMailHeaderData[];
13
+ internetMessageId?: string;
13
14
  }
@@ -0,0 +1,6 @@
1
+ export interface GraphMailLocatedData {
2
+ id: string;
3
+ isDraft: boolean;
4
+ conversationId: string | null;
5
+ internetMessageId: string | null;
6
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -7,5 +7,6 @@ export interface GraphMailOutgoingMessageData {
7
7
  toRecipients?: GraphMailRecipientData[];
8
8
  ccRecipients?: GraphMailRecipientData[];
9
9
  replyTo?: GraphMailRecipientData[];
10
+ internetMessageId?: string;
10
11
  internetMessageHeaders?: GraphMailHeaderData[];
11
12
  }
@@ -1,6 +1,7 @@
1
1
  import type { MailAddressData } from '../../models/mail-address-data';
2
2
  import type { GraphMailBodyData } from './graph-mail-body-data';
3
3
  import type { GraphMailFileData } from './graph-mail-file-data';
4
+ import type { GraphMailHeaderData } from './graph-mail-header-data';
4
5
  export interface GraphMailReplyData {
5
6
  body: GraphMailBodyData;
6
7
  subject?: string;
@@ -8,4 +9,6 @@ export interface GraphMailReplyData {
8
9
  cc?: MailAddressData[];
9
10
  replyTo?: MailAddressData[];
10
11
  attachments?: GraphMailFileData[];
12
+ headers?: GraphMailHeaderData[];
13
+ internetMessageId?: string;
11
14
  }
@@ -15,6 +15,7 @@ export type { GraphMailErrorData } from './graph-mail-error-data';
15
15
  export type { GraphMailFileAttachmentRequest } from './graph-mail-file-attachment-request';
16
16
  export type { GraphMailFileData } from './graph-mail-file-data';
17
17
  export type { GraphMailHeaderData } from './graph-mail-header-data';
18
+ export type { GraphMailLocatedData } from './graph-mail-located-data';
18
19
  export type { GraphMailMessageData } from './graph-mail-message-data';
19
20
  export type { GraphMailNotificationData } from './graph-mail-notification-data';
20
21
  export type { GraphMailNotificationPayloadData } from './graph-mail-notification-payload-data';
@@ -8,6 +8,7 @@ import type { GraphMailDeltaOptions } from '../models/graph-mail-delta-options';
8
8
  import type { GraphMailDeltaPageData } from '../models/graph-mail-delta-page-data';
9
9
  import type { GraphMailDraftData } from '../models/graph-mail-draft-data';
10
10
  import type { GraphMailFileData } from '../models/graph-mail-file-data';
11
+ import type { GraphMailLocatedData } from '../models/graph-mail-located-data';
11
12
  import type { GraphMailMessageData } from '../models/graph-mail-message-data';
12
13
  import type { GraphMailReplyData } from '../models/graph-mail-reply-data';
13
14
  import type { GraphMailSubscriptionData } from '../models/graph-mail-subscription-data';
@@ -21,6 +22,10 @@ export declare class GraphMailService {
21
22
  static downloadAttachment(connection: GraphMailConnection, messageId: string, attachmentId: string): Promise<MailAttachmentContentData>;
22
23
  static sendMail(connection: GraphMailConnection, draft: GraphMailDraftData): Promise<void>;
23
24
  static createAndSend(connection: GraphMailConnection, draft: GraphMailDraftData): Promise<MailSentData>;
25
+ static createDraft(connection: GraphMailConnection, draft: GraphMailDraftData): Promise<MailSentData>;
26
+ static createReplyDraft(connection: GraphMailConnection, messageId: string, reply: GraphMailReplyData): Promise<MailSentData>;
27
+ static sendDraft(connection: GraphMailConnection, messageId: string): Promise<void>;
28
+ static locate(connection: GraphMailConnection, internetMessageId: string): Promise<GraphMailLocatedData | null>;
24
29
  static addAttachment(connection: GraphMailConnection, messageId: string, file: GraphMailFileData): Promise<void>;
25
30
  static createUploadSession(connection: GraphMailConnection, messageId: string, file: GraphMailFileData): Promise<GraphMailUploadSessionData>;
26
31
  static reply(connection: GraphMailConnection, messageId: string, reply: GraphMailReplyData): Promise<MailSentData>;
@@ -216,6 +216,22 @@ var GraphMailService = /** @class */ (function () {
216
216
  });
217
217
  };
218
218
  GraphMailService.createAndSend = function (connection, draft) {
219
+ return __awaiter(this, void 0, void 0, function () {
220
+ var created;
221
+ return __generator(this, function (_a) {
222
+ switch (_a.label) {
223
+ case 0: return [4 /*yield*/, this.createDraft(connection, draft)];
224
+ case 1:
225
+ created = _a.sent();
226
+ return [4 /*yield*/, this.sendDraft(connection, created.id)];
227
+ case 2:
228
+ _a.sent();
229
+ return [2 /*return*/, created];
230
+ }
231
+ });
232
+ });
233
+ };
234
+ GraphMailService.createDraft = function (connection, draft) {
219
235
  return __awaiter(this, void 0, void 0, function () {
220
236
  var created;
221
237
  return __generator(this, function (_a) {
@@ -230,14 +246,78 @@ var GraphMailService = /** @class */ (function () {
230
246
  return [4 /*yield*/, this._attach(connection, created.id, draft.attachments)];
231
247
  case 2:
232
248
  _a.sent();
233
- return [4 /*yield*/, this._send(connection, created.id)];
234
- case 3:
249
+ return [2 /*return*/, this._sent(created)];
250
+ }
251
+ });
252
+ });
253
+ };
254
+ GraphMailService.createReplyDraft = function (connection, messageId, reply) {
255
+ return __awaiter(this, void 0, void 0, function () {
256
+ var request, created;
257
+ return __generator(this, function (_a) {
258
+ switch (_a.label) {
259
+ case 0:
260
+ request = { message: this._outgoing(reply) };
261
+ return [4 /*yield*/, graph_request_service_1.GraphRequestService.json(connection, {
262
+ method: ps_utilities_1.HttpMethod.Post,
263
+ url: mail_url_service_1.MailUrlService.path(this._messagePath(connection, messageId), graph_mail_config_1.GraphMailConfig.paths.createReply),
264
+ body: request,
265
+ })];
266
+ case 1:
267
+ created = _a.sent();
268
+ return [4 /*yield*/, this._attach(connection, created.id, reply.attachments)];
269
+ case 2:
235
270
  _a.sent();
236
271
  return [2 /*return*/, this._sent(created)];
237
272
  }
238
273
  });
239
274
  });
240
275
  };
276
+ GraphMailService.sendDraft = function (connection, messageId) {
277
+ return __awaiter(this, void 0, void 0, function () {
278
+ return __generator(this, function (_a) {
279
+ switch (_a.label) {
280
+ case 0: return [4 /*yield*/, this._send(connection, messageId)];
281
+ case 1:
282
+ _a.sent();
283
+ return [2 /*return*/];
284
+ }
285
+ });
286
+ });
287
+ };
288
+ GraphMailService.locate = function (connection, internetMessageId) {
289
+ return __awaiter(this, void 0, void 0, function () {
290
+ var quote, page, found;
291
+ return __generator(this, function (_a) {
292
+ switch (_a.label) {
293
+ case 0:
294
+ quote = graph_mail_config_1.GraphMailConfig.filterQuote;
295
+ return [4 /*yield*/, graph_request_service_1.GraphRequestService.json(connection, {
296
+ method: ps_utilities_1.HttpMethod.Get,
297
+ url: mail_url_service_1.MailUrlService.withQuery(mail_url_service_1.MailUrlService.path(this._mailboxPath(connection), graph_mail_config_1.GraphMailConfig.paths.messages), [
298
+ {
299
+ key: graph_mail_config_1.GraphMailConfig.query.filter,
300
+ value: "".concat(graph_mail_config_1.GraphMailConfig.query.internetMessageIdFilter).concat(quote).concat(internetMessageId.split(quote).join(quote + quote)).concat(quote),
301
+ },
302
+ this._select(graph_mail_config_1.GraphMailConfig.locateFields),
303
+ { key: graph_mail_config_1.GraphMailConfig.query.top, value: graph_mail_config_1.GraphMailConfig.locateTop },
304
+ ]),
305
+ })];
306
+ case 1:
307
+ page = _a.sent();
308
+ found = page.value[0];
309
+ if (found === undefined)
310
+ return [2 /*return*/, null];
311
+ return [2 /*return*/, {
312
+ id: found.id,
313
+ isDraft: found.isDraft === true,
314
+ conversationId: typeof found.conversationId === 'string' ? found.conversationId : null,
315
+ internetMessageId: typeof found.internetMessageId === 'string' ? found.internetMessageId : null,
316
+ }];
317
+ }
318
+ });
319
+ });
320
+ };
241
321
  GraphMailService.addAttachment = function (connection, messageId, file) {
242
322
  return __awaiter(this, void 0, void 0, function () {
243
323
  var _a, _b, _c, request, _d, _e, _f, _g;
@@ -295,25 +375,16 @@ var GraphMailService = /** @class */ (function () {
295
375
  };
296
376
  GraphMailService.reply = function (connection, messageId, reply) {
297
377
  return __awaiter(this, void 0, void 0, function () {
298
- var request, created;
378
+ var created;
299
379
  return __generator(this, function (_a) {
300
380
  switch (_a.label) {
301
- case 0:
302
- request = { message: this._outgoing(reply) };
303
- return [4 /*yield*/, graph_request_service_1.GraphRequestService.json(connection, {
304
- method: ps_utilities_1.HttpMethod.Post,
305
- url: mail_url_service_1.MailUrlService.path(this._messagePath(connection, messageId), graph_mail_config_1.GraphMailConfig.paths.createReply),
306
- body: request,
307
- })];
381
+ case 0: return [4 /*yield*/, this.createReplyDraft(connection, messageId, reply)];
308
382
  case 1:
309
383
  created = _a.sent();
310
- return [4 /*yield*/, this._attach(connection, created.id, reply.attachments)];
384
+ return [4 /*yield*/, this.sendDraft(connection, created.id)];
311
385
  case 2:
312
386
  _a.sent();
313
- return [4 /*yield*/, this._send(connection, created.id)];
314
- case 3:
315
- _a.sent();
316
- return [2 /*return*/, this._sent(created)];
387
+ return [2 /*return*/, created];
317
388
  }
318
389
  });
319
390
  });
@@ -436,8 +507,10 @@ var GraphMailService = /** @class */ (function () {
436
507
  outgoing.ccRecipients = this._recipients(message.cc);
437
508
  if (message.replyTo !== undefined)
438
509
  outgoing.replyTo = this._recipients(message.replyTo);
439
- if ('headers' in message && message.headers !== undefined)
510
+ if (message.headers !== undefined)
440
511
  outgoing.internetMessageHeaders = message.headers;
512
+ if (message.internetMessageId !== undefined)
513
+ outgoing.internetMessageId = message.internetMessageId;
441
514
  return outgoing;
442
515
  };
443
516
  GraphMailService._recipients = function (addresses) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pallasoft/ps-mail",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "private": false,
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",