@pallasoft/ps-mail 1.4.0 → 1.5.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.
@@ -1,4 +1,11 @@
1
1
  export declare const GraphMailConfig: {
2
+ readonly directory: {
3
+ readonly memberType: "member";
4
+ readonly maxPages: 20;
5
+ readonly pageSize: "999";
6
+ readonly userFields: readonly ["id", "displayName", "mail", "userPrincipalName", "userType", "accountEnabled", "assignedLicenses"];
7
+ readonly domainSeparator: "@";
8
+ };
2
9
  readonly graphBaseUrl: "https://graph.microsoft.com/v1.0";
3
10
  readonly loginBaseUrl: "https://login.microsoftonline.com";
4
11
  readonly tokenPath: "oauth2/v2.0/token";
@@ -2,6 +2,21 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GraphMailConfig = void 0;
4
4
  exports.GraphMailConfig = {
5
+ directory: {
6
+ memberType: 'member',
7
+ maxPages: 20,
8
+ pageSize: '999',
9
+ userFields: [
10
+ 'id',
11
+ 'displayName',
12
+ 'mail',
13
+ 'userPrincipalName',
14
+ 'userType',
15
+ 'accountEnabled',
16
+ 'assignedLicenses',
17
+ ],
18
+ domainSeparator: '@',
19
+ },
5
20
  graphBaseUrl: 'https://graph.microsoft.com/v1.0',
6
21
  loginBaseUrl: 'https://login.microsoftonline.com',
7
22
  tokenPath: 'oauth2/v2.0/token',
@@ -1,3 +1,3 @@
1
1
  export { GraphMailBodyType, GraphMailErrorReason, GraphMailFolder, GraphMailLifecycleEvent, } from './constants';
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';
2
+ export { GraphMailErrorService, GraphMailService, GraphTokenService, GraphUserDirectoryService, } from './services';
3
+ export type { GraphCredentials, GraphDirectoryOptions, GraphDirectoryUserData, GraphMailBodyData, GraphMailConnection, GraphMailDeltaData, GraphMailDeltaOptions, GraphMailDeltaPageData, GraphMailDraftData, GraphMailErrorData, GraphMailFileData, GraphMailHeaderData, GraphMailLocatedData, GraphMailMessageData, GraphMailNotificationData, GraphMailNotificationPayloadData, GraphMailRecipientData, GraphMailRemovedData, GraphMailReplyData, GraphMailSubscriptionData, GraphMailSubscriptionOptions, GraphMailUploadSessionData, GraphUserData, } from './models';
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GraphTokenService = exports.GraphMailService = exports.GraphMailErrorService = exports.GraphMailLifecycleEvent = exports.GraphMailFolder = exports.GraphMailErrorReason = exports.GraphMailBodyType = void 0;
3
+ exports.GraphUserDirectoryService = 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; } });
@@ -10,3 +10,4 @@ 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
12
  Object.defineProperty(exports, "GraphTokenService", { enumerable: true, get: function () { return services_1.GraphTokenService; } });
13
+ Object.defineProperty(exports, "GraphUserDirectoryService", { enumerable: true, get: function () { return services_1.GraphUserDirectoryService; } });
@@ -0,0 +1,3 @@
1
+ export interface GraphDirectoryOptions {
2
+ domains: string[];
3
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ export interface GraphDirectoryUserData {
2
+ email: string;
3
+ id: string;
4
+ name: string;
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,9 @@
1
+ export interface GraphUserData {
2
+ accountEnabled?: boolean;
3
+ assignedLicenses?: unknown[];
4
+ displayName?: string | null;
5
+ id: string;
6
+ mail?: string | null;
7
+ userPrincipalName?: string | null;
8
+ userType?: string | null;
9
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -34,3 +34,6 @@ export type { GraphMailUploadSessionData } from './graph-mail-upload-session-dat
34
34
  export type { GraphMailUploadSessionRequest } from './graph-mail-upload-session-request';
35
35
  export type { GraphRequestData } from './graph-request-data';
36
36
  export type { GraphTokenResponse } from './graph-token-response';
37
+ export type { GraphDirectoryOptions } from './graph-directory-options';
38
+ export type { GraphDirectoryUserData } from './graph-directory-user-data';
39
+ export type { GraphUserData } from './graph-user-data';
@@ -96,22 +96,21 @@ var GraphRequestService = /** @class */ (function () {
96
96
  return [4 /*yield*/, this._attempt(credentials, request, url, body)];
97
97
  case 2:
98
98
  outcome = _b.sent();
99
- if (outcome instanceof Response && outcome.ok)
99
+ if (!graph_mail_error_service_1.GraphMailErrorService.isGraphMailError(outcome) && outcome.ok)
100
100
  return [2 /*return*/, outcome];
101
- if (outcome instanceof Response &&
101
+ if (!graph_mail_error_service_1.GraphMailErrorService.isGraphMailError(outcome) &&
102
102
  outcome.status === Attributes.Common.Response.ErrorCodes.Unauthorized &&
103
103
  !refreshed) {
104
104
  refreshed = true;
105
105
  graph_token_service_1.GraphTokenService.clear(credentials);
106
106
  return [3 /*break*/, 1];
107
107
  }
108
- if (!(outcome instanceof Response)) return [3 /*break*/, 4];
109
- return [4 /*yield*/, graph_mail_error_service_1.GraphMailErrorService.fromResponse(outcome)];
110
- case 3:
111
- _a = _b.sent();
108
+ if (!graph_mail_error_service_1.GraphMailErrorService.isGraphMailError(outcome)) return [3 /*break*/, 3];
109
+ _a = outcome;
112
110
  return [3 /*break*/, 5];
111
+ case 3: return [4 /*yield*/, graph_mail_error_service_1.GraphMailErrorService.fromResponse(outcome)];
113
112
  case 4:
114
- _a = outcome;
113
+ _a = _b.sent();
115
114
  _b.label = 5;
116
115
  case 5:
117
116
  error = _a;
@@ -0,0 +1,10 @@
1
+ import type { GraphCredentials } from '../models/graph-credentials';
2
+ import type { GraphDirectoryOptions } from '../models/graph-directory-options';
3
+ import type { GraphDirectoryUserData } from '../models/graph-directory-user-data';
4
+ import type { GraphUserData } from '../models/graph-user-data';
5
+ export declare class GraphUserDirectoryService {
6
+ static list(credentials: GraphCredentials, options: GraphDirectoryOptions): Promise<GraphDirectoryUserData[]>;
7
+ static isLicensedMember(user: GraphUserData): boolean;
8
+ private static _entry;
9
+ private static _start;
10
+ }
@@ -0,0 +1,114 @@
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.GraphUserDirectoryService = void 0;
40
+ var ps_utilities_1 = require("@pallasoft/ps-utilities");
41
+ var mail_http_config_1 = require("../../constants/mail-http-config");
42
+ var mail_url_service_1 = require("../../services/mail-url-service");
43
+ var graph_mail_config_1 = require("../constants/graph-mail-config");
44
+ var graph_request_service_1 = require("./graph-request-service");
45
+ var GraphUserDirectoryService = /** @class */ (function () {
46
+ function GraphUserDirectoryService() {
47
+ }
48
+ GraphUserDirectoryService.list = function (credentials, options) {
49
+ return __awaiter(this, void 0, void 0, function () {
50
+ var domains, users, url, pages, page, _i, _a, user, entry;
51
+ return __generator(this, function (_b) {
52
+ switch (_b.label) {
53
+ case 0:
54
+ domains = options.domains.map(function (domain) { return domain.trim().toLowerCase(); });
55
+ users = [];
56
+ url = this._start();
57
+ pages = 0;
58
+ _b.label = 1;
59
+ case 1:
60
+ if (!(url !== null && pages < graph_mail_config_1.GraphMailConfig.directory.maxPages)) return [3 /*break*/, 3];
61
+ return [4 /*yield*/, graph_request_service_1.GraphRequestService.json(credentials, { method: ps_utilities_1.HttpMethod.Get, url: url })];
62
+ case 2:
63
+ page = _b.sent();
64
+ for (_i = 0, _a = page.value; _i < _a.length; _i++) {
65
+ user = _a[_i];
66
+ entry = this._entry(user, domains);
67
+ if (entry !== null)
68
+ users.push(entry);
69
+ }
70
+ url = typeof page['@odata.nextLink'] === 'string' ? page['@odata.nextLink'] : null;
71
+ pages += 1;
72
+ return [3 /*break*/, 1];
73
+ case 3: return [2 /*return*/, users];
74
+ }
75
+ });
76
+ });
77
+ };
78
+ GraphUserDirectoryService.isLicensedMember = function (user) {
79
+ return (user.accountEnabled === true &&
80
+ typeof user.userType === 'string' &&
81
+ user.userType.toLowerCase() === graph_mail_config_1.GraphMailConfig.directory.memberType &&
82
+ Array.isArray(user.assignedLicenses) &&
83
+ user.assignedLicenses.length > 0);
84
+ };
85
+ GraphUserDirectoryService._entry = function (user, domains) {
86
+ if (!this.isLicensedMember(user))
87
+ return null;
88
+ var address = typeof user.mail === 'string' && user.mail !== ''
89
+ ? user.mail
90
+ : typeof user.userPrincipalName === 'string'
91
+ ? user.userPrincipalName
92
+ : '';
93
+ var email = address.trim().toLowerCase();
94
+ var domain = email.split(graph_mail_config_1.GraphMailConfig.directory.domainSeparator)[1];
95
+ if (email === '' || domain === undefined || !domains.includes(domain))
96
+ return null;
97
+ return {
98
+ email: email,
99
+ id: user.id,
100
+ name: typeof user.displayName === 'string' && user.displayName !== '' ? user.displayName : email,
101
+ };
102
+ };
103
+ GraphUserDirectoryService._start = function () {
104
+ return mail_url_service_1.MailUrlService.withQuery(mail_url_service_1.MailUrlService.path('', graph_mail_config_1.GraphMailConfig.paths.users), [
105
+ {
106
+ key: graph_mail_config_1.GraphMailConfig.query.select,
107
+ value: graph_mail_config_1.GraphMailConfig.directory.userFields.join(mail_http_config_1.MailHttpConfig.listSeparator),
108
+ },
109
+ { key: graph_mail_config_1.GraphMailConfig.query.top, value: graph_mail_config_1.GraphMailConfig.directory.pageSize },
110
+ ]);
111
+ };
112
+ return GraphUserDirectoryService;
113
+ }());
114
+ exports.GraphUserDirectoryService = GraphUserDirectoryService;
@@ -3,3 +3,4 @@ export * from './graph-mail-service';
3
3
  export * from './graph-request-service';
4
4
  export * from './graph-token-service';
5
5
  export * from './graph-upload-service';
6
+ export * from './graph-user-directory-service';
@@ -19,3 +19,4 @@ __exportStar(require("./graph-mail-service"), exports);
19
19
  __exportStar(require("./graph-request-service"), exports);
20
20
  __exportStar(require("./graph-token-service"), exports);
21
21
  __exportStar(require("./graph-upload-service"), exports);
22
+ __exportStar(require("./graph-user-directory-service"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pallasoft/ps-mail",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "private": false,
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",