@pallasoft/ps-mail 1.1.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 (25) hide show
  1. package/README.md +3 -0
  2. package/dist/microsoft/constants/graph-mail-config.d.ts +4 -0
  3. package/dist/microsoft/constants/graph-mail-config.js +4 -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-notification-data.d.ts +7 -0
  11. package/dist/microsoft/models/graph-mail-notification-data.js +2 -0
  12. package/dist/microsoft/models/graph-mail-notification-payload-data.d.ts +4 -0
  13. package/dist/microsoft/models/graph-mail-notification-payload-data.js +2 -0
  14. package/dist/microsoft/models/graph-mail-subscription-data.d.ts +5 -0
  15. package/dist/microsoft/models/graph-mail-subscription-data.js +2 -0
  16. package/dist/microsoft/models/graph-mail-subscription-options.d.ts +6 -0
  17. package/dist/microsoft/models/graph-mail-subscription-options.js +2 -0
  18. package/dist/microsoft/models/graph-mail-subscription-renew-request.d.ts +3 -0
  19. package/dist/microsoft/models/graph-mail-subscription-renew-request.js +2 -0
  20. package/dist/microsoft/models/graph-mail-subscription-request.d.ts +8 -0
  21. package/dist/microsoft/models/graph-mail-subscription-request.js +2 -0
  22. package/dist/microsoft/models/index.d.ts +6 -0
  23. package/dist/microsoft/services/graph-mail-service.d.ts +5 -0
  24. package/dist/microsoft/services/graph-mail-service.js +40 -0
  25. 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
 
@@ -15,6 +15,7 @@ export declare const GraphMailConfig: {
15
15
  readonly messages: "messages";
16
16
  readonly send: "send";
17
17
  readonly sendMail: "sendMail";
18
+ readonly subscriptions: "subscriptions";
18
19
  readonly users: "users";
19
20
  readonly value: "$value";
20
21
  };
@@ -48,4 +49,7 @@ export declare const GraphMailConfig: {
48
49
  readonly rangeUnit: "bytes ";
49
50
  };
50
51
  readonly saveToSentItems: true;
52
+ readonly subscription: {
53
+ readonly changeType: "created,updated";
54
+ };
51
55
  };
@@ -18,6 +18,7 @@ exports.GraphMailConfig = {
18
18
  messages: 'messages',
19
19
  send: 'send',
20
20
  sendMail: 'sendMail',
21
+ subscriptions: 'subscriptions',
21
22
  users: 'users',
22
23
  value: '$value',
23
24
  },
@@ -86,4 +87,7 @@ exports.GraphMailConfig = {
86
87
  rangeUnit: 'bytes ',
87
88
  },
88
89
  saveToSentItems: true,
90
+ subscription: {
91
+ changeType: 'created,updated',
92
+ },
89
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, GraphMailFileData, GraphMailHeaderData, GraphMailMessageData, GraphMailRecipientData, GraphMailRemovedData, GraphMailReplyData, GraphMailUploadSessionData, } 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; } });
@@ -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 });
@@ -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 });
@@ -16,12 +16,18 @@ export type { GraphMailFileAttachmentRequest } from './graph-mail-file-attachmen
16
16
  export type { GraphMailFileData } from './graph-mail-file-data';
17
17
  export type { GraphMailHeaderData } from './graph-mail-header-data';
18
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';
19
21
  export type { GraphMailOutgoingMessageData } from './graph-mail-outgoing-message-data';
20
22
  export type { GraphMailRecipientData } from './graph-mail-recipient-data';
21
23
  export type { GraphMailRemovedData } from './graph-mail-removed-data';
22
24
  export type { GraphMailReplyData } from './graph-mail-reply-data';
23
25
  export type { GraphMailReplyRequest } from './graph-mail-reply-request';
24
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';
25
31
  export type { GraphMailUploadItemData } from './graph-mail-upload-item-data';
26
32
  export type { GraphMailUploadSessionData } from './graph-mail-upload-session-data';
27
33
  export type { GraphMailUploadSessionRequest } from './graph-mail-upload-session-request';
@@ -10,6 +10,8 @@ import type { GraphMailDraftData } from '../models/graph-mail-draft-data';
10
10
  import type { GraphMailFileData } from '../models/graph-mail-file-data';
11
11
  import type { GraphMailMessageData } from '../models/graph-mail-message-data';
12
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';
13
15
  import type { GraphMailUploadSessionData } from '../models/graph-mail-upload-session-data';
14
16
  export declare class GraphMailService {
15
17
  static deltaPage(connection: GraphMailConnection, folder: GraphMailFolder, link: string | null, options?: GraphMailDeltaOptions): Promise<GraphMailDeltaPageData>;
@@ -23,6 +25,9 @@ export declare class GraphMailService {
23
25
  static createUploadSession(connection: GraphMailConnection, messageId: string, file: GraphMailFileData): Promise<GraphMailUploadSessionData>;
24
26
  static reply(connection: GraphMailConnection, messageId: string, reply: GraphMailReplyData): Promise<MailSentData>;
25
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>;
26
31
  private static _attach;
27
32
  private static _send;
28
33
  private static _deltaStart;
@@ -337,6 +337,46 @@ var GraphMailService = /** @class */ (function () {
337
337
  });
338
338
  });
339
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
+ };
340
380
  GraphMailService._attach = function (connection, messageId, files) {
341
381
  return __awaiter(this, void 0, void 0, function () {
342
382
  var _i, files_1, file;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pallasoft/ps-mail",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "private": false,
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",