@pallasoft/ps-mail 1.0.0 → 1.2.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.
Files changed (41) hide show
  1. package/README.md +3 -0
  2. package/dist/microsoft/constants/graph-mail-config.d.ts +13 -0
  3. package/dist/microsoft/constants/graph-mail-config.js +13 -0
  4. package/dist/microsoft/constants/graph-mail-lifecycle-event.d.ts +5 -0
  5. package/dist/microsoft/constants/graph-mail-lifecycle-event.js +9 -0
  6. package/dist/microsoft/constants/index.d.ts +1 -0
  7. package/dist/microsoft/constants/index.js +1 -0
  8. package/dist/microsoft/index.d.ts +2 -2
  9. package/dist/microsoft/index.js +2 -1
  10. package/dist/microsoft/models/graph-mail-draft-data.d.ts +2 -0
  11. package/dist/microsoft/models/graph-mail-file-attachment-request.d.ts +6 -0
  12. package/dist/microsoft/models/graph-mail-file-attachment-request.js +2 -0
  13. package/dist/microsoft/models/graph-mail-file-data.d.ts +5 -0
  14. package/dist/microsoft/models/graph-mail-file-data.js +2 -0
  15. package/dist/microsoft/models/graph-mail-notification-data.d.ts +7 -0
  16. package/dist/microsoft/models/graph-mail-notification-data.js +2 -0
  17. package/dist/microsoft/models/graph-mail-notification-payload-data.d.ts +4 -0
  18. package/dist/microsoft/models/graph-mail-notification-payload-data.js +2 -0
  19. package/dist/microsoft/models/graph-mail-reply-data.d.ts +2 -0
  20. package/dist/microsoft/models/graph-mail-subscription-data.d.ts +5 -0
  21. package/dist/microsoft/models/graph-mail-subscription-data.js +2 -0
  22. package/dist/microsoft/models/graph-mail-subscription-options.d.ts +6 -0
  23. package/dist/microsoft/models/graph-mail-subscription-options.js +2 -0
  24. package/dist/microsoft/models/graph-mail-subscription-renew-request.d.ts +3 -0
  25. package/dist/microsoft/models/graph-mail-subscription-renew-request.js +2 -0
  26. package/dist/microsoft/models/graph-mail-subscription-request.d.ts +8 -0
  27. package/dist/microsoft/models/graph-mail-subscription-request.js +2 -0
  28. package/dist/microsoft/models/graph-mail-upload-item-data.d.ts +6 -0
  29. package/dist/microsoft/models/graph-mail-upload-item-data.js +2 -0
  30. package/dist/microsoft/models/graph-mail-upload-session-data.d.ts +4 -0
  31. package/dist/microsoft/models/graph-mail-upload-session-data.js +2 -0
  32. package/dist/microsoft/models/graph-mail-upload-session-request.d.ts +4 -0
  33. package/dist/microsoft/models/graph-mail-upload-session-request.js +2 -0
  34. package/dist/microsoft/models/index.d.ts +11 -0
  35. package/dist/microsoft/services/graph-mail-service.d.ts +10 -0
  36. package/dist/microsoft/services/graph-mail-service.js +129 -2
  37. package/dist/microsoft/services/graph-upload-service.d.ts +6 -0
  38. package/dist/microsoft/services/graph-upload-service.js +91 -0
  39. package/dist/microsoft/services/index.d.ts +1 -0
  40. package/dist/microsoft/services/index.js +1 -0
  41. package/package.json +1 -1
package/README.md CHANGED
@@ -13,6 +13,9 @@ permissions `Mail.ReadWrite` and `Mail.Send`).
13
13
  - `GraphMailService.sendMail`, `createAndSend` and `reply` send mail from the mailbox; `reply` stays
14
14
  in the conversation.
15
15
  - `GraphMailService.setCategories` tags a message for people working in Outlook.
16
+ - `GraphMailService.subscribe` / `renewSubscription` / `deleteSubscription` manage Graph change
17
+ notification subscriptions for a folder (`GraphMailLifecycleEvent` names the lifecycle events;
18
+ `GraphMailNotificationPayloadData` is the webhook body).
16
19
  - `GraphMailErrorService.isSyncStateExpired(error)` tells the caller to drop its delta link and
17
20
  resync. Throttling (429/503 with `Retry-After`) and an expired token (401) are retried inside.
18
21
 
@@ -9,11 +9,13 @@ export declare const GraphMailConfig: {
9
9
  readonly paths: {
10
10
  readonly attachments: "attachments";
11
11
  readonly createReply: "createReply";
12
+ readonly createUploadSession: "createUploadSession";
12
13
  readonly delta: "messages/delta";
13
14
  readonly mailFolders: "mailFolders";
14
15
  readonly messages: "messages";
15
16
  readonly send: "send";
16
17
  readonly sendMail: "sendMail";
18
+ readonly subscriptions: "subscriptions";
17
19
  readonly users: "users";
18
20
  readonly value: "$value";
19
21
  };
@@ -38,5 +40,16 @@ export declare const GraphMailConfig: {
38
40
  readonly maxRetries: 3;
39
41
  readonly maxWaitSeconds: 30;
40
42
  };
43
+ readonly attachment: {
44
+ readonly fileType: "#microsoft.graph.fileAttachment";
45
+ readonly uploadType: "file";
46
+ readonly inlineMaxBytes: 3000000;
47
+ readonly chunkBytes: 3276800;
48
+ readonly contentRangeHeader: "Content-Range";
49
+ readonly rangeUnit: "bytes ";
50
+ };
41
51
  readonly saveToSentItems: true;
52
+ readonly subscription: {
53
+ readonly changeType: "created,updated";
54
+ };
42
55
  };
@@ -12,11 +12,13 @@ exports.GraphMailConfig = {
12
12
  paths: {
13
13
  attachments: 'attachments',
14
14
  createReply: 'createReply',
15
+ createUploadSession: 'createUploadSession',
15
16
  delta: 'messages/delta',
16
17
  mailFolders: 'mailFolders',
17
18
  messages: 'messages',
18
19
  send: 'send',
19
20
  sendMail: 'sendMail',
21
+ subscriptions: 'subscriptions',
20
22
  users: 'users',
21
23
  value: '$value',
22
24
  },
@@ -76,5 +78,16 @@ exports.GraphMailConfig = {
76
78
  maxRetries: 3,
77
79
  maxWaitSeconds: 30,
78
80
  },
81
+ attachment: {
82
+ fileType: '#microsoft.graph.fileAttachment',
83
+ uploadType: 'file',
84
+ inlineMaxBytes: 3000000,
85
+ chunkBytes: 3276800,
86
+ contentRangeHeader: 'Content-Range',
87
+ rangeUnit: 'bytes ',
88
+ },
79
89
  saveToSentItems: true,
90
+ subscription: {
91
+ changeType: 'created,updated',
92
+ },
80
93
  };
@@ -0,0 +1,5 @@
1
+ export declare enum GraphMailLifecycleEvent {
2
+ Missed = "missed",
3
+ ReauthorizationRequired = "reauthorizationRequired",
4
+ SubscriptionRemoved = "subscriptionRemoved"
5
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GraphMailLifecycleEvent = void 0;
4
+ var GraphMailLifecycleEvent;
5
+ (function (GraphMailLifecycleEvent) {
6
+ GraphMailLifecycleEvent["Missed"] = "missed";
7
+ GraphMailLifecycleEvent["ReauthorizationRequired"] = "reauthorizationRequired";
8
+ GraphMailLifecycleEvent["SubscriptionRemoved"] = "subscriptionRemoved";
9
+ })(GraphMailLifecycleEvent || (exports.GraphMailLifecycleEvent = GraphMailLifecycleEvent = {}));
@@ -3,3 +3,4 @@ export * from './graph-mail-config';
3
3
  export * from './graph-mail-error-messages';
4
4
  export * from './graph-mail-error-reason';
5
5
  export * from './graph-mail-folder';
6
+ export * from './graph-mail-lifecycle-event';
@@ -19,3 +19,4 @@ __exportStar(require("./graph-mail-config"), exports);
19
19
  __exportStar(require("./graph-mail-error-messages"), exports);
20
20
  __exportStar(require("./graph-mail-error-reason"), exports);
21
21
  __exportStar(require("./graph-mail-folder"), exports);
22
+ __exportStar(require("./graph-mail-lifecycle-event"), exports);
@@ -1,3 +1,3 @@
1
- export { GraphMailBodyType, GraphMailErrorReason, GraphMailFolder } from './constants';
1
+ export { GraphMailBodyType, GraphMailErrorReason, GraphMailFolder, GraphMailLifecycleEvent, } from './constants';
2
2
  export { GraphMailErrorService, GraphMailService } from './services';
3
- export type { GraphCredentials, GraphMailBodyData, GraphMailConnection, GraphMailDeltaData, GraphMailDeltaOptions, GraphMailDeltaPageData, GraphMailDraftData, GraphMailErrorData, GraphMailHeaderData, GraphMailMessageData, GraphMailRecipientData, GraphMailRemovedData, GraphMailReplyData, } from './models';
3
+ export type { GraphCredentials, GraphMailBodyData, GraphMailConnection, GraphMailDeltaData, GraphMailDeltaOptions, GraphMailDeltaPageData, GraphMailDraftData, GraphMailErrorData, GraphMailFileData, GraphMailHeaderData, GraphMailMessageData, GraphMailNotificationData, GraphMailNotificationPayloadData, GraphMailRecipientData, GraphMailRemovedData, GraphMailReplyData, GraphMailSubscriptionData, GraphMailSubscriptionOptions, GraphMailUploadSessionData, } from './models';
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GraphMailService = exports.GraphMailErrorService = exports.GraphMailFolder = exports.GraphMailErrorReason = exports.GraphMailBodyType = void 0;
3
+ 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; } });
7
7
  Object.defineProperty(exports, "GraphMailFolder", { enumerable: true, get: function () { return constants_1.GraphMailFolder; } });
8
+ Object.defineProperty(exports, "GraphMailLifecycleEvent", { enumerable: true, get: function () { return constants_1.GraphMailLifecycleEvent; } });
8
9
  var services_1 = require("./services");
9
10
  Object.defineProperty(exports, "GraphMailErrorService", { enumerable: true, get: function () { return services_1.GraphMailErrorService; } });
10
11
  Object.defineProperty(exports, "GraphMailService", { enumerable: true, get: function () { return services_1.GraphMailService; } });
@@ -1,5 +1,6 @@
1
1
  import type { MailAddressData } from '../../models/mail-address-data';
2
2
  import type { GraphMailBodyData } from './graph-mail-body-data';
3
+ import type { GraphMailFileData } from './graph-mail-file-data';
3
4
  import type { GraphMailHeaderData } from './graph-mail-header-data';
4
5
  export interface GraphMailDraftData {
5
6
  subject: string;
@@ -7,5 +8,6 @@ export interface GraphMailDraftData {
7
8
  to: MailAddressData[];
8
9
  cc?: MailAddressData[];
9
10
  replyTo?: MailAddressData[];
11
+ attachments?: GraphMailFileData[];
10
12
  headers?: GraphMailHeaderData[];
11
13
  }
@@ -0,0 +1,6 @@
1
+ export interface GraphMailFileAttachmentRequest {
2
+ '@odata.type': string;
3
+ 'name': string;
4
+ 'contentType': string;
5
+ 'contentBytes': string;
6
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ export interface GraphMailFileData {
2
+ name: string;
3
+ contentType: string;
4
+ content: Blob;
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ export interface GraphMailNotificationData {
2
+ subscriptionId: string;
3
+ clientState?: string;
4
+ changeType?: string;
5
+ lifecycleEvent?: string;
6
+ resource?: string;
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ import type { GraphMailNotificationData } from './graph-mail-notification-data';
2
+ export interface GraphMailNotificationPayloadData {
3
+ value: GraphMailNotificationData[];
4
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,9 +1,11 @@
1
1
  import type { MailAddressData } from '../../models/mail-address-data';
2
2
  import type { GraphMailBodyData } from './graph-mail-body-data';
3
+ import type { GraphMailFileData } from './graph-mail-file-data';
3
4
  export interface GraphMailReplyData {
4
5
  body: GraphMailBodyData;
5
6
  subject?: string;
6
7
  to?: MailAddressData[];
7
8
  cc?: MailAddressData[];
8
9
  replyTo?: MailAddressData[];
10
+ attachments?: GraphMailFileData[];
9
11
  }
@@ -0,0 +1,5 @@
1
+ export interface GraphMailSubscriptionData {
2
+ id: string;
3
+ resource: string;
4
+ expirationDateTime: string;
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ export interface GraphMailSubscriptionOptions {
2
+ notificationUrl: string;
3
+ lifecycleNotificationUrl: string;
4
+ clientState: string;
5
+ expiresAt: Date;
6
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ export interface GraphMailSubscriptionRenewRequest {
2
+ expirationDateTime: string;
3
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ export interface GraphMailSubscriptionRequest {
2
+ changeType: string;
3
+ notificationUrl: string;
4
+ lifecycleNotificationUrl: string;
5
+ resource: string;
6
+ expirationDateTime: string;
7
+ clientState: string;
8
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ export interface GraphMailUploadItemData {
2
+ attachmentType: string;
3
+ name: string;
4
+ size: number;
5
+ contentType: string;
6
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ export interface GraphMailUploadSessionData {
2
+ uploadUrl: string;
3
+ expirationDateTime?: string;
4
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ import type { GraphMailUploadItemData } from './graph-mail-upload-item-data';
2
+ export interface GraphMailUploadSessionRequest {
3
+ AttachmentItem: GraphMailUploadItemData;
4
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -12,13 +12,24 @@ export type { GraphMailDeltaOptions } from './graph-mail-delta-options';
12
12
  export type { GraphMailDeltaPageData } from './graph-mail-delta-page-data';
13
13
  export type { GraphMailDraftData } from './graph-mail-draft-data';
14
14
  export type { GraphMailErrorData } from './graph-mail-error-data';
15
+ export type { GraphMailFileAttachmentRequest } from './graph-mail-file-attachment-request';
16
+ export type { GraphMailFileData } from './graph-mail-file-data';
15
17
  export type { GraphMailHeaderData } from './graph-mail-header-data';
16
18
  export type { GraphMailMessageData } from './graph-mail-message-data';
19
+ export type { GraphMailNotificationData } from './graph-mail-notification-data';
20
+ export type { GraphMailNotificationPayloadData } from './graph-mail-notification-payload-data';
17
21
  export type { GraphMailOutgoingMessageData } from './graph-mail-outgoing-message-data';
18
22
  export type { GraphMailRecipientData } from './graph-mail-recipient-data';
19
23
  export type { GraphMailRemovedData } from './graph-mail-removed-data';
20
24
  export type { GraphMailReplyData } from './graph-mail-reply-data';
21
25
  export type { GraphMailReplyRequest } from './graph-mail-reply-request';
22
26
  export type { GraphMailSendRequest } from './graph-mail-send-request';
27
+ export type { GraphMailSubscriptionData } from './graph-mail-subscription-data';
28
+ export type { GraphMailSubscriptionOptions } from './graph-mail-subscription-options';
29
+ export type { GraphMailSubscriptionRenewRequest } from './graph-mail-subscription-renew-request';
30
+ export type { GraphMailSubscriptionRequest } from './graph-mail-subscription-request';
31
+ export type { GraphMailUploadItemData } from './graph-mail-upload-item-data';
32
+ export type { GraphMailUploadSessionData } from './graph-mail-upload-session-data';
33
+ export type { GraphMailUploadSessionRequest } from './graph-mail-upload-session-request';
23
34
  export type { GraphRequestData } from './graph-request-data';
24
35
  export type { GraphTokenResponse } from './graph-token-response';
@@ -7,8 +7,12 @@ import type { GraphMailDeltaData } from '../models/graph-mail-delta-data';
7
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
+ import type { GraphMailFileData } from '../models/graph-mail-file-data';
10
11
  import type { GraphMailMessageData } from '../models/graph-mail-message-data';
11
12
  import type { GraphMailReplyData } from '../models/graph-mail-reply-data';
13
+ import type { GraphMailSubscriptionData } from '../models/graph-mail-subscription-data';
14
+ import type { GraphMailSubscriptionOptions } from '../models/graph-mail-subscription-options';
15
+ import type { GraphMailUploadSessionData } from '../models/graph-mail-upload-session-data';
12
16
  export declare class GraphMailService {
13
17
  static deltaPage(connection: GraphMailConnection, folder: GraphMailFolder, link: string | null, options?: GraphMailDeltaOptions): Promise<GraphMailDeltaPageData>;
14
18
  static delta(connection: GraphMailConnection, folder: GraphMailFolder, deltaLink: string | null, options?: GraphMailDeltaOptions): Promise<GraphMailDeltaData>;
@@ -17,8 +21,14 @@ export declare class GraphMailService {
17
21
  static downloadAttachment(connection: GraphMailConnection, messageId: string, attachmentId: string): Promise<MailAttachmentContentData>;
18
22
  static sendMail(connection: GraphMailConnection, draft: GraphMailDraftData): Promise<void>;
19
23
  static createAndSend(connection: GraphMailConnection, draft: GraphMailDraftData): Promise<MailSentData>;
24
+ static addAttachment(connection: GraphMailConnection, messageId: string, file: GraphMailFileData): Promise<void>;
25
+ static createUploadSession(connection: GraphMailConnection, messageId: string, file: GraphMailFileData): Promise<GraphMailUploadSessionData>;
20
26
  static reply(connection: GraphMailConnection, messageId: string, reply: GraphMailReplyData): Promise<MailSentData>;
21
27
  static setCategories(connection: GraphMailConnection, messageId: string, categories: string[]): Promise<void>;
28
+ static subscribe(connection: GraphMailConnection, folder: GraphMailFolder, options: GraphMailSubscriptionOptions): Promise<GraphMailSubscriptionData>;
29
+ static renewSubscription(connection: GraphMailConnection, subscriptionId: string, expiresAt: Date): Promise<GraphMailSubscriptionData>;
30
+ static deleteSubscription(connection: GraphMailConnection, subscriptionId: string): Promise<void>;
31
+ private static _attach;
22
32
  private static _send;
23
33
  private static _deltaStart;
24
34
  private static _outgoing;
@@ -78,6 +78,7 @@ var graph_mail_config_1 = require("../constants/graph-mail-config");
78
78
  var graph_mail_error_reason_1 = require("../constants/graph-mail-error-reason");
79
79
  var graph_mail_error_service_1 = require("./graph-mail-error-service");
80
80
  var graph_request_service_1 = require("./graph-request-service");
81
+ var graph_upload_service_1 = require("./graph-upload-service");
81
82
  var GraphMailService = /** @class */ (function () {
82
83
  function GraphMailService() {
83
84
  }
@@ -226,14 +227,72 @@ var GraphMailService = /** @class */ (function () {
226
227
  })];
227
228
  case 1:
228
229
  created = _a.sent();
229
- return [4 /*yield*/, this._send(connection, created.id)];
230
+ return [4 /*yield*/, this._attach(connection, created.id, draft.attachments)];
230
231
  case 2:
232
+ _a.sent();
233
+ return [4 /*yield*/, this._send(connection, created.id)];
234
+ case 3:
231
235
  _a.sent();
232
236
  return [2 /*return*/, this._sent(created)];
233
237
  }
234
238
  });
235
239
  });
236
240
  };
241
+ GraphMailService.addAttachment = function (connection, messageId, file) {
242
+ return __awaiter(this, void 0, void 0, function () {
243
+ var _a, _b, _c, request, _d, _e, _f, _g;
244
+ var _h;
245
+ return __generator(this, function (_j) {
246
+ switch (_j.label) {
247
+ case 0:
248
+ if (!(file.content.size > graph_mail_config_1.GraphMailConfig.attachment.inlineMaxBytes)) return [3 /*break*/, 3];
249
+ _b = (_a = graph_upload_service_1.GraphUploadService).put;
250
+ _c = [connection];
251
+ return [4 /*yield*/, this.createUploadSession(connection, messageId, file)];
252
+ case 1: return [4 /*yield*/, _b.apply(_a, _c.concat([_j.sent(), file]))];
253
+ case 2:
254
+ _j.sent();
255
+ return [2 /*return*/];
256
+ case 3:
257
+ _h = {
258
+ '@odata.type': graph_mail_config_1.GraphMailConfig.attachment.fileType,
259
+ 'name': file.name,
260
+ 'contentType': file.contentType
261
+ };
262
+ _d = 'contentBytes';
263
+ _f = (_e = ps_utilities_1.Common.Base64Service).encode;
264
+ _g = Uint8Array.bind;
265
+ return [4 /*yield*/, file.content.arrayBuffer()];
266
+ case 4:
267
+ request = (_h[_d] = _f.apply(_e, [new (_g.apply(Uint8Array, [void 0, _j.sent()]))()]),
268
+ _h);
269
+ return [4 /*yield*/, graph_request_service_1.GraphRequestService.send(connection, {
270
+ method: ps_utilities_1.HttpMethod.Post,
271
+ url: mail_url_service_1.MailUrlService.path(this._messagePath(connection, messageId), graph_mail_config_1.GraphMailConfig.paths.attachments),
272
+ body: request,
273
+ })];
274
+ case 5:
275
+ _j.sent();
276
+ return [2 /*return*/];
277
+ }
278
+ });
279
+ });
280
+ };
281
+ GraphMailService.createUploadSession = function (connection, messageId, file) {
282
+ var request = {
283
+ AttachmentItem: {
284
+ attachmentType: graph_mail_config_1.GraphMailConfig.attachment.uploadType,
285
+ name: file.name,
286
+ size: file.content.size,
287
+ contentType: file.contentType,
288
+ },
289
+ };
290
+ return graph_request_service_1.GraphRequestService.json(connection, {
291
+ method: ps_utilities_1.HttpMethod.Post,
292
+ url: mail_url_service_1.MailUrlService.path(this._messagePath(connection, messageId), graph_mail_config_1.GraphMailConfig.paths.attachments, graph_mail_config_1.GraphMailConfig.paths.createUploadSession),
293
+ body: request,
294
+ });
295
+ };
237
296
  GraphMailService.reply = function (connection, messageId, reply) {
238
297
  return __awaiter(this, void 0, void 0, function () {
239
298
  var request, created;
@@ -248,8 +307,11 @@ var GraphMailService = /** @class */ (function () {
248
307
  })];
249
308
  case 1:
250
309
  created = _a.sent();
251
- return [4 /*yield*/, this._send(connection, created.id)];
310
+ return [4 /*yield*/, this._attach(connection, created.id, reply.attachments)];
252
311
  case 2:
312
+ _a.sent();
313
+ return [4 /*yield*/, this._send(connection, created.id)];
314
+ case 3:
253
315
  _a.sent();
254
316
  return [2 /*return*/, this._sent(created)];
255
317
  }
@@ -275,6 +337,71 @@ var GraphMailService = /** @class */ (function () {
275
337
  });
276
338
  });
277
339
  };
340
+ GraphMailService.subscribe = function (connection, folder, options) {
341
+ var request = {
342
+ changeType: graph_mail_config_1.GraphMailConfig.subscription.changeType,
343
+ clientState: options.clientState,
344
+ expirationDateTime: options.expiresAt.toISOString(),
345
+ lifecycleNotificationUrl: options.lifecycleNotificationUrl,
346
+ notificationUrl: options.notificationUrl,
347
+ resource: mail_url_service_1.MailUrlService.path(this._mailboxPath(connection), graph_mail_config_1.GraphMailConfig.paths.mailFolders, folder, graph_mail_config_1.GraphMailConfig.paths.messages).slice(mail_http_config_1.MailHttpConfig.pathSeparator.length),
348
+ };
349
+ return graph_request_service_1.GraphRequestService.json(connection, {
350
+ method: ps_utilities_1.HttpMethod.Post,
351
+ url: mail_url_service_1.MailUrlService.path('', graph_mail_config_1.GraphMailConfig.paths.subscriptions),
352
+ body: request,
353
+ });
354
+ };
355
+ GraphMailService.renewSubscription = function (connection, subscriptionId, expiresAt) {
356
+ var request = {
357
+ expirationDateTime: expiresAt.toISOString(),
358
+ };
359
+ return graph_request_service_1.GraphRequestService.json(connection, {
360
+ method: ps_utilities_1.HttpMethod.Patch,
361
+ url: mail_url_service_1.MailUrlService.path('', graph_mail_config_1.GraphMailConfig.paths.subscriptions, subscriptionId),
362
+ body: request,
363
+ });
364
+ };
365
+ GraphMailService.deleteSubscription = function (connection, subscriptionId) {
366
+ return __awaiter(this, void 0, void 0, function () {
367
+ return __generator(this, function (_a) {
368
+ switch (_a.label) {
369
+ case 0: return [4 /*yield*/, graph_request_service_1.GraphRequestService.send(connection, {
370
+ method: ps_utilities_1.HttpMethod.Delete,
371
+ url: mail_url_service_1.MailUrlService.path('', graph_mail_config_1.GraphMailConfig.paths.subscriptions, subscriptionId),
372
+ })];
373
+ case 1:
374
+ _a.sent();
375
+ return [2 /*return*/];
376
+ }
377
+ });
378
+ });
379
+ };
380
+ GraphMailService._attach = function (connection, messageId, files) {
381
+ return __awaiter(this, void 0, void 0, function () {
382
+ var _i, files_1, file;
383
+ return __generator(this, function (_a) {
384
+ switch (_a.label) {
385
+ case 0:
386
+ if (files === undefined)
387
+ return [2 /*return*/];
388
+ _i = 0, files_1 = files;
389
+ _a.label = 1;
390
+ case 1:
391
+ if (!(_i < files_1.length)) return [3 /*break*/, 4];
392
+ file = files_1[_i];
393
+ return [4 /*yield*/, this.addAttachment(connection, messageId, file)];
394
+ case 2:
395
+ _a.sent();
396
+ _a.label = 3;
397
+ case 3:
398
+ _i++;
399
+ return [3 /*break*/, 1];
400
+ case 4: return [2 /*return*/];
401
+ }
402
+ });
403
+ });
404
+ };
278
405
  GraphMailService._send = function (connection, messageId) {
279
406
  return __awaiter(this, void 0, void 0, function () {
280
407
  return __generator(this, function (_a) {
@@ -0,0 +1,6 @@
1
+ import type { GraphCredentials } from '../models/graph-credentials';
2
+ import type { GraphMailFileData } from '../models/graph-mail-file-data';
3
+ import type { GraphMailUploadSessionData } from '../models/graph-mail-upload-session-data';
4
+ export declare class GraphUploadService {
5
+ static put(credentials: GraphCredentials, session: GraphMailUploadSessionData, file: GraphMailFileData): Promise<void>;
6
+ }
@@ -0,0 +1,91 @@
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.GraphUploadService = void 0;
40
+ var ps_utilities_1 = require("@pallasoft/ps-utilities");
41
+ var graph_mail_config_1 = require("../constants/graph-mail-config");
42
+ var graph_mail_error_service_1 = require("./graph-mail-error-service");
43
+ var graph_token_service_1 = require("./graph-token-service");
44
+ var GraphUploadService = /** @class */ (function () {
45
+ function GraphUploadService() {
46
+ }
47
+ GraphUploadService.put = function (credentials, session, file) {
48
+ return __awaiter(this, void 0, void 0, function () {
49
+ var total, _a, chunkBytes, contentRangeHeader, rangeUnit, start, end, bytes, _b, response;
50
+ var _c;
51
+ return __generator(this, function (_d) {
52
+ switch (_d.label) {
53
+ case 0:
54
+ total = file.content.size;
55
+ _a = graph_mail_config_1.GraphMailConfig.attachment, chunkBytes = _a.chunkBytes, contentRangeHeader = _a.contentRangeHeader, rangeUnit = _a.rangeUnit;
56
+ start = 0;
57
+ _d.label = 1;
58
+ case 1:
59
+ if (!(start < total)) return [3 /*break*/, 6];
60
+ end = Math.min(start + chunkBytes, total);
61
+ _b = Uint8Array.bind;
62
+ return [4 /*yield*/, file.content.slice(start, end).arrayBuffer()];
63
+ case 2:
64
+ bytes = new (_b.apply(Uint8Array, [void 0, _d.sent()]))();
65
+ return [4 /*yield*/, fetch(session.uploadUrl, {
66
+ method: ps_utilities_1.HttpMethod.Put,
67
+ headers: (_c = {},
68
+ _c[ps_utilities_1.Common.HttpHeader.contentType] = ps_utilities_1.Common.HttpContentType.octetStream,
69
+ _c[contentRangeHeader] = "".concat(rangeUnit).concat(start, "-").concat(end - 1, "/").concat(total),
70
+ _c),
71
+ body: bytes,
72
+ signal: graph_token_service_1.GraphTokenService.signal(credentials),
73
+ }).catch(function (error) {
74
+ throw graph_mail_error_service_1.GraphMailErrorService.fromFetchFailure(error);
75
+ })];
76
+ case 3:
77
+ response = _d.sent();
78
+ if (!!response.ok) return [3 /*break*/, 5];
79
+ return [4 /*yield*/, graph_mail_error_service_1.GraphMailErrorService.fromResponse(response)];
80
+ case 4: throw _d.sent();
81
+ case 5:
82
+ start += chunkBytes;
83
+ return [3 /*break*/, 1];
84
+ case 6: return [2 /*return*/];
85
+ }
86
+ });
87
+ });
88
+ };
89
+ return GraphUploadService;
90
+ }());
91
+ exports.GraphUploadService = GraphUploadService;
@@ -2,3 +2,4 @@ export * from './graph-mail-error-service';
2
2
  export * from './graph-mail-service';
3
3
  export * from './graph-request-service';
4
4
  export * from './graph-token-service';
5
+ export * from './graph-upload-service';
@@ -18,3 +18,4 @@ __exportStar(require("./graph-mail-error-service"), exports);
18
18
  __exportStar(require("./graph-mail-service"), exports);
19
19
  __exportStar(require("./graph-request-service"), exports);
20
20
  __exportStar(require("./graph-token-service"), exports);
21
+ __exportStar(require("./graph-upload-service"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pallasoft/ps-mail",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "private": false,
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",