@checkfirst/nestjs-outlook 7.1.0 → 7.1.2
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/README.md +1 -0
- package/dist/constants.d.ts +3 -0
- package/dist/constants.js +4 -1
- package/dist/constants.js.map +1 -1
- package/dist/controllers/calendar.controller.js +2 -4
- package/dist/controllers/calendar.controller.js.map +1 -1
- package/dist/controllers/microsoft-auth.controller.js +20 -0
- package/dist/controllers/microsoft-auth.controller.js.map +1 -1
- package/dist/errors/mailbox-inactive.error.d.ts +4 -0
- package/dist/errors/mailbox-inactive.error.js +12 -0
- package/dist/errors/mailbox-inactive.error.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces/instrumentation.interface.d.ts +8 -0
- package/dist/interfaces/instrumentation.interface.js +5 -0
- package/dist/interfaces/instrumentation.interface.js.map +1 -0
- package/dist/interfaces/recurrence.interfaces.d.ts +5 -1
- package/dist/repositories/outlook-delta-link.repository.d.ts +2 -0
- package/dist/repositories/outlook-delta-link.repository.js +17 -3
- package/dist/repositories/outlook-delta-link.repository.js.map +1 -1
- package/dist/repositories/outlook-webhook-subscription.repository.d.ts +3 -0
- package/dist/repositories/outlook-webhook-subscription.repository.js +33 -5
- package/dist/repositories/outlook-webhook-subscription.repository.js.map +1 -1
- package/dist/services/auth/microsoft-auth.service.d.ts +6 -0
- package/dist/services/auth/microsoft-auth.service.js +69 -2
- package/dist/services/auth/microsoft-auth.service.js.map +1 -1
- package/dist/services/calendar/calendar.service.d.ts +1 -1
- package/dist/services/calendar/calendar.service.js +10 -3
- package/dist/services/calendar/calendar.service.js.map +1 -1
- package/dist/services/calendar/recurrence.service.d.ts +4 -3
- package/dist/services/calendar/recurrence.service.js +56 -34
- package/dist/services/calendar/recurrence.service.js.map +1 -1
- package/dist/services/shared/shared-user.service.js +7 -1
- package/dist/services/shared/shared-user.service.js.map +1 -1
- package/dist/services/shared/user-id-converter.service.d.ts +2 -0
- package/dist/services/shared/user-id-converter.service.js +17 -2
- package/dist/services/shared/user-id-converter.service.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/retry.util.js +25 -0
- package/dist/utils/retry.util.js.map +1 -1
- package/dist/utils/ttl-cache.util.d.ts +9 -0
- package/dist/utils/ttl-cache.util.js +30 -0
- package/dist/utils/ttl-cache.util.js.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/constants.d.ts
CHANGED
package/dist/constants.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MICROSOFT_CONFIG = void 0;
|
|
3
|
+
exports.GRAPH_ERROR_CODES = exports.MICROSOFT_CONFIG = void 0;
|
|
4
4
|
exports.MICROSOFT_CONFIG = 'MICROSOFT_CONFIG';
|
|
5
|
+
exports.GRAPH_ERROR_CODES = {
|
|
6
|
+
MAILBOX_NOT_ENABLED: 'MailboxNotEnabledForRESTAPI',
|
|
7
|
+
};
|
|
5
8
|
//# sourceMappingURL=constants.js.map
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AACa,QAAA,gBAAgB,GAAG,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AACa,QAAA,gBAAgB,GAAG,kBAAkB,CAAC;AAGtC,QAAA,iBAAiB,GAAG;IAE/B,mBAAmB,EAAE,6BAA6B;CAC1C,CAAC"}
|
|
@@ -28,7 +28,6 @@ let CalendarController = CalendarController_1 = class CalendarController {
|
|
|
28
28
|
this.logger = new common_1.Logger(CalendarController_1.name);
|
|
29
29
|
}
|
|
30
30
|
async handleCalendarWebhookNotification(validationToken, notificationBody, req, res) {
|
|
31
|
-
var _a, _b;
|
|
32
31
|
if (validationToken) {
|
|
33
32
|
this.logger.log('Handling Microsoft Graph validation request');
|
|
34
33
|
const decodedToken = decodeURIComponent(validationToken);
|
|
@@ -38,7 +37,7 @@ let CalendarController = CalendarController_1 = class CalendarController {
|
|
|
38
37
|
}
|
|
39
38
|
try {
|
|
40
39
|
const webhookTraceId = (0, crypto_1.randomUUID)();
|
|
41
|
-
this.logger.log(`[WEBHOOK_RECEIVED] webhookTraceId=${webhookTraceId}, endpoint=notification, notificationCount=${
|
|
40
|
+
this.logger.log(`[WEBHOOK_RECEIVED] webhookTraceId=${webhookTraceId}, endpoint=notification, notificationCount=${notificationBody.value.length}`);
|
|
42
41
|
this.logger.debug(`Received webhook notification: ${JSON.stringify(notificationBody)}`);
|
|
43
42
|
if (Array.isArray(notificationBody.value) && notificationBody.value.length > 2) {
|
|
44
43
|
this.logger.log(`Received batch of ${notificationBody.value.length.toString()} notifications, responding with 202 Accepted`);
|
|
@@ -100,7 +99,6 @@ let CalendarController = CalendarController_1 = class CalendarController {
|
|
|
100
99
|
}
|
|
101
100
|
}
|
|
102
101
|
async handleCalendarWebhook(validationToken, notificationBody, req, res) {
|
|
103
|
-
var _a, _b;
|
|
104
102
|
if (validationToken) {
|
|
105
103
|
this.logger.log('Handling Microsoft Graph validation request');
|
|
106
104
|
const decodedToken = decodeURIComponent(validationToken);
|
|
@@ -110,7 +108,7 @@ let CalendarController = CalendarController_1 = class CalendarController {
|
|
|
110
108
|
}
|
|
111
109
|
try {
|
|
112
110
|
const webhookTraceId = (0, crypto_1.randomUUID)();
|
|
113
|
-
this.logger.log(`[WEBHOOK_RECEIVED] webhookTraceId=${webhookTraceId}, endpoint=webhook, notificationCount=${
|
|
111
|
+
this.logger.log(`[WEBHOOK_RECEIVED] webhookTraceId=${webhookTraceId}, endpoint=webhook, notificationCount=${notificationBody.value.length}`);
|
|
114
112
|
this.logger.debug(`Received webhook notification: ${JSON.stringify(notificationBody)}`);
|
|
115
113
|
if (Array.isArray(notificationBody.value) && notificationBody.value.length > 2) {
|
|
116
114
|
this.logger.log(`Received batch of ${notificationBody.value.length.toString()} notifications, responding with 202 Accepted`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calendar.controller.js","sourceRoot":"","sources":["../../src/controllers/calendar.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAuG;AACvG,6CAA0E;AAE1E,mCAAoC;AACpC,4EAAwE;AAExE,8FAAwF;AACxF,4FAA4H;AAC5H,0GAAoG;AAK7F,IAAM,kBAAkB,0BAAxB,MAAM,kBAAkB;IAG7B,YACmB,eAAgC,EAChC,qBAAmD;QADnD,oBAAe,GAAf,eAAe,CAAiB;QAChC,0BAAqB,GAArB,qBAAqB,CAA8B;QAJrD,WAAM,GAAG,IAAI,eAAM,CAAC,oBAAkB,CAAC,IAAI,CAAC,CAAC;IAK3D,CAAC;IAuCE,AAAN,KAAK,CAAC,iCAAiC,CACX,eAAuB,EACzC,gBAA+C,EAChD,GAAY,EACZ,GAAa
|
|
1
|
+
{"version":3,"file":"calendar.controller.js","sourceRoot":"","sources":["../../src/controllers/calendar.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAuG;AACvG,6CAA0E;AAE1E,mCAAoC;AACpC,4EAAwE;AAExE,8FAAwF;AACxF,4FAA4H;AAC5H,0GAAoG;AAK7F,IAAM,kBAAkB,0BAAxB,MAAM,kBAAkB;IAG7B,YACmB,eAAgC,EAChC,qBAAmD;QADnD,oBAAe,GAAf,eAAe,CAAiB;QAChC,0BAAqB,GAArB,qBAAqB,CAA8B;QAJrD,WAAM,GAAG,IAAI,eAAM,CAAC,oBAAkB,CAAC,IAAI,CAAC,CAAC;IAK3D,CAAC;IAuCE,AAAN,KAAK,CAAC,iCAAiC,CACX,eAAuB,EACzC,gBAA+C,EAChD,GAAY,EACZ,GAAa;QAGpB,IAAI,eAAe,EAAE,CAAC;YACpB,IAAI,CA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,CAAC;IACD,IAAA,iBAAO,EAAC;QACP,WAAW,EAAE,8CAA8C;QAC3D,IAAI,EAAE,gEAA6B;QACnC,QAAQ,EAAE,KAAK;KAChB,CAAC;IAEC,WAAA,IAAA,cAAK,EAAC,iBAAiB,CAAC,CAAA;IACxB,WAAA,IAAA,aAAI,GAAE,CAAA;IACN,WAAA,IAAA,YAAG,GAAE,CAAA;IACL,WAAA,IAAA,YAAG,GAAE,CAAA;;6CAFoB,gEAA6B;;+DA+DxD;6BA5OU,kBAAkB;IAH9B,IAAA,iBAAO,EAAC,UAAU,CAAC;IACnB,IAAA,mBAAU,EAAC,UAAU,CAAC;IACtB,IAAA,mBAAU,GAAE;qCAKyB,kCAAe;QACT,8DAA4B;GAL3D,kBAAkB,CAmV9B"}
|
|
@@ -17,6 +17,7 @@ exports.MicrosoftAuthController = void 0;
|
|
|
17
17
|
const common_1 = require("@nestjs/common");
|
|
18
18
|
const swagger_1 = require("@nestjs/swagger");
|
|
19
19
|
const microsoft_auth_service_1 = require("../services/auth/microsoft-auth.service");
|
|
20
|
+
const mailbox_inactive_error_1 = require("../errors/mailbox-inactive.error");
|
|
20
21
|
let MicrosoftAuthController = MicrosoftAuthController_1 = class MicrosoftAuthController {
|
|
21
22
|
constructor(microsoftAuthService) {
|
|
22
23
|
this.microsoftAuthService = microsoftAuthService;
|
|
@@ -43,6 +44,25 @@ let MicrosoftAuthController = MicrosoftAuthController_1 = class MicrosoftAuthCon
|
|
|
43
44
|
}
|
|
44
45
|
catch (error) {
|
|
45
46
|
this.logger.error('Error handling OAuth callback:', error);
|
|
47
|
+
if (error instanceof mailbox_inactive_error_1.MailboxInactiveError) {
|
|
48
|
+
return res.status(common_1.HttpStatus.OK).send(`
|
|
49
|
+
<h1>Calendar Connection Failed</h1>
|
|
50
|
+
<p>Your Microsoft account was authenticated, but we couldn't access your mailbox.</p>
|
|
51
|
+
<p>This usually means your mailbox is either:</p>
|
|
52
|
+
<ul>
|
|
53
|
+
<li>Hosted on an on-premise Exchange server (not Exchange Online)</li>
|
|
54
|
+
<li>Inactive or has been soft-deleted</li>
|
|
55
|
+
<li>Missing an Exchange Online license</li>
|
|
56
|
+
</ul>
|
|
57
|
+
<p>Please contact your IT administrator to ensure your mailbox is hosted in Exchange Online (Microsoft 365).</p>
|
|
58
|
+
<p>You can close this tab now.</p>
|
|
59
|
+
<script>
|
|
60
|
+
if (window.opener) {
|
|
61
|
+
window.opener.postMessage({ type: 'microsoft-auth-failed', error: 'Your mailbox is not supported. It may be inactive, soft-deleted, or hosted on-premise. Please contact your IT administrator.' }, '*');
|
|
62
|
+
}
|
|
63
|
+
</script>
|
|
64
|
+
`);
|
|
65
|
+
}
|
|
46
66
|
return res
|
|
47
67
|
.status(common_1.HttpStatus.INTERNAL_SERVER_ERROR)
|
|
48
68
|
.send('An error occurred during authentication');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"microsoft-auth.controller.js","sourceRoot":"","sources":["../../src/controllers/microsoft-auth.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAiF;AAEjF,6CAA4F;AAC5F,oFAA+E;
|
|
1
|
+
{"version":3,"file":"microsoft-auth.controller.js","sourceRoot":"","sources":["../../src/controllers/microsoft-auth.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAiF;AAEjF,6CAA4F;AAC5F,oFAA+E;AAC/E,6EAAwE;AAIjE,IAAM,uBAAuB,+BAA7B,MAAM,uBAAuB;IAGlC,YAA6B,oBAA0C;QAA1C,yBAAoB,GAApB,oBAAoB,CAAsB;QAFtD,WAAM,GAAG,IAAI,eAAM,CAAC,yBAAuB,CAAC,IAAI,CAAC,CAAC;IAEO,CAAC;IA4DrE,AAAN,KAAK,CAAC,mBAAmB,CACR,IAAY,EACX,KAAa,EACtB,GAAa;QAEpB,IAAI,CAAC;YACH,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;gBACpB,IAAI,CAAC,MAAM,CAAC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nD,CAAC;IACD,IAAA,qBAAW,EAAC;QACX,MAAM,EAAE,GAAG;QACX,WAAW,EAAE,8DAA8D;QAC3E,OAAO,EAAE;YACP,WAAW,EAAE;gBACX,OAAO,EACL,+FAA+F;aAClG;SACF;KACF,CAAC;IACD,IAAA,qBAAW,EAAC;QACX,MAAM,EAAE,GAAG;QACX,WAAW,EAAE,0CAA0C;KACxD,CAAC;IACD,IAAA,qBAAW,EAAC;QACX,MAAM,EAAE,GAAG;QACX,WAAW,EAAE,4CAA4C;KAC1D,CAAC;IACD,IAAA,qBAAW,EAAC,WAAW,CAAC;IAEtB,WAAA,IAAA,cAAK,EAAC,MAAM,CAAC,CAAA;IACb,WAAA,IAAA,cAAK,EAAC,OAAO,CAAC,CAAA;IACd,WAAA,IAAA,YAAG,GAAE,CAAA;;;;kEAkDP;kCApHU,uBAAuB;IAFnC,IAAA,iBAAO,EAAC,gBAAgB,CAAC;IACzB,IAAA,mBAAU,EAAC,gBAAgB,CAAC;qCAIwB,6CAAoB;GAH5D,uBAAuB,CAqHnC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MailboxInactiveError = void 0;
|
|
4
|
+
class MailboxInactiveError extends Error {
|
|
5
|
+
constructor(graphMessage) {
|
|
6
|
+
super(`Mailbox is not accessible: ${graphMessage}`);
|
|
7
|
+
this.graphMessage = graphMessage;
|
|
8
|
+
this.name = 'MailboxInactiveError';
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.MailboxInactiveError = MailboxInactiveError;
|
|
12
|
+
//# sourceMappingURL=mailbox-inactive.error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mailbox-inactive.error.js","sourceRoot":"","sources":["../../src/errors/mailbox-inactive.error.ts"],"names":[],"mappings":";;;AAAA,MAAa,oBAAqB,SAAQ,KAAK;IAC7C,YAA4B,YAAoB;QAC9C,KAAK,CAAC,8BAA8B,YAAY,EAAE,CAAC,CAAC;QAD1B,iBAAY,GAAZ,YAAY,CAAQ;QAE9C,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;CACF;AALD,oDAKC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export * from './enums/permission-scope.enum';
|
|
|
13
13
|
export * from './enums/event-types.enum';
|
|
14
14
|
export * from './enums/show-as-type.enum';
|
|
15
15
|
export * from './constants';
|
|
16
|
+
export * from './errors/mailbox-inactive.error';
|
|
16
17
|
export * from './controllers/calendar.controller';
|
|
17
18
|
export * from './controllers/microsoft-auth.controller';
|
|
18
19
|
export * from './controllers/email.controller';
|
package/dist/index.js
CHANGED
|
@@ -29,6 +29,7 @@ __exportStar(require("./enums/permission-scope.enum"), exports);
|
|
|
29
29
|
__exportStar(require("./enums/event-types.enum"), exports);
|
|
30
30
|
__exportStar(require("./enums/show-as-type.enum"), exports);
|
|
31
31
|
__exportStar(require("./constants"), exports);
|
|
32
|
+
__exportStar(require("./errors/mailbox-inactive.error"), exports);
|
|
32
33
|
__exportStar(require("./controllers/calendar.controller"), exports);
|
|
33
34
|
__exportStar(require("./controllers/microsoft-auth.controller"), exports);
|
|
34
35
|
__exportStar(require("./controllers/email.controller"), exports);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAGA,yEAAuD;AACvD,uEAAqD;AACrD,yEAAuD;AACvD,iEAA+C;AAC/C,8EAA4D;AAC5D,yFAAuE;AACvE,+EAA6D;AAG7D,6DAA2C;AAG3C,gFAA8D;AAC9D,+EAA6D;AAC7D,qEAAmD;AAGnD,gEAA8C;AAC9C,2DAAyC;AACzC,4DAA0C;AAG1C,8CAA4B;AAG5B,oEAAkD;AAClD,0EAAwD;AACxD,iEAA+C;AAG/C,yEAAuD;AAGvD,iFAA+D;AAC/D,mEAAiD;AAGjD,yFAAuE;AAGvE,0CAAwB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAGA,yEAAuD;AACvD,uEAAqD;AACrD,yEAAuD;AACvD,iEAA+C;AAC/C,8EAA4D;AAC5D,yFAAuE;AACvE,+EAA6D;AAG7D,6DAA2C;AAG3C,gFAA8D;AAC9D,+EAA6D;AAC7D,qEAAmD;AAGnD,gEAA8C;AAC9C,2DAAyC;AACzC,4DAA0C;AAG1C,8CAA4B;AAG5B,kEAAgD;AAGhD,oEAAkD;AAClD,0EAAwD;AACxD,iEAA+C;AAG/C,yEAAuD;AAGvD,iFAA+D;AAC/D,mEAAiD;AAGjD,yFAAuE;AAGvE,0CAAwB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface OutlookInstrumentation {
|
|
2
|
+
recordCustomEvent(eventType: string, attributes: Record<string, string | number | boolean>): void;
|
|
3
|
+
recordMetric(name: string, value: number): void;
|
|
4
|
+
noticeError(error: Error, attributes?: Record<string, string | number | boolean>): void;
|
|
5
|
+
addCustomAttributes(params: Record<string, string | number | boolean>): void;
|
|
6
|
+
setLogContext(key: string, value: string | number | boolean): void;
|
|
7
|
+
}
|
|
8
|
+
export declare const OUTLOOK_INSTRUMENTATION = "OUTLOOK_INSTRUMENTATION";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instrumentation.interface.js","sourceRoot":"","sources":["../../src/interfaces/instrumentation.interface.ts"],"names":[],"mappings":";;;AAiCa,QAAA,uBAAuB,GAAG,yBAAyB,CAAC"}
|
|
@@ -48,5 +48,9 @@ export interface ExpansionWindow {
|
|
|
48
48
|
export interface RecurringEventExpansionResult {
|
|
49
49
|
seriesMaster: ProcessedOutlookEvent;
|
|
50
50
|
instances: ProcessedOutlookEvent[];
|
|
51
|
-
expansionWindow: ExpansionWindow;
|
|
51
|
+
expansionWindow: ExpansionWindow[];
|
|
52
|
+
staleExternalIds: string[];
|
|
53
|
+
}
|
|
54
|
+
export interface ExpandRecurringSeriesOptions {
|
|
55
|
+
existingExternalIds?: string[];
|
|
52
56
|
}
|
|
@@ -3,7 +3,9 @@ import { OutlookDeltaLink } from '../entities/delta-link.entity';
|
|
|
3
3
|
import { ResourceType } from '../enums/resource-type.enum';
|
|
4
4
|
export declare class OutlookDeltaLinkRepository {
|
|
5
5
|
private readonly repository;
|
|
6
|
+
private readonly deltaLinkCache;
|
|
6
7
|
constructor(repository: Repository<OutlookDeltaLink>);
|
|
8
|
+
private cacheKey;
|
|
7
9
|
saveDeltaLink(internalUserId: number, resourceType: ResourceType, deltaLink: string): Promise<OutlookDeltaLink>;
|
|
8
10
|
getDeltaLink(internalUserId: number, resourceType: ResourceType): Promise<string | null>;
|
|
9
11
|
deleteDeltaLink(internalUserId: number, resourceType: ResourceType): Promise<void>;
|
|
@@ -17,9 +17,14 @@ const common_1 = require("@nestjs/common");
|
|
|
17
17
|
const typeorm_1 = require("@nestjs/typeorm");
|
|
18
18
|
const typeorm_2 = require("typeorm");
|
|
19
19
|
const delta_link_entity_1 = require("../entities/delta-link.entity");
|
|
20
|
+
const ttl_cache_util_1 = require("../utils/ttl-cache.util");
|
|
20
21
|
let OutlookDeltaLinkRepository = class OutlookDeltaLinkRepository {
|
|
21
22
|
constructor(repository) {
|
|
22
23
|
this.repository = repository;
|
|
24
|
+
this.deltaLinkCache = new ttl_cache_util_1.TtlCache(30000);
|
|
25
|
+
}
|
|
26
|
+
cacheKey(internalUserId, resourceType) {
|
|
27
|
+
return `${String(internalUserId)}:${resourceType}`;
|
|
23
28
|
}
|
|
24
29
|
async saveDeltaLink(internalUserId, resourceType, deltaLink) {
|
|
25
30
|
let deltaLinkEntity = await this.repository.findOne({
|
|
@@ -31,17 +36,26 @@ let OutlookDeltaLinkRepository = class OutlookDeltaLinkRepository {
|
|
|
31
36
|
deltaLinkEntity.resourceType = resourceType;
|
|
32
37
|
}
|
|
33
38
|
deltaLinkEntity.deltaLink = deltaLink;
|
|
34
|
-
|
|
39
|
+
const saved = await this.repository.save(deltaLinkEntity);
|
|
40
|
+
this.deltaLinkCache.set(this.cacheKey(internalUserId, resourceType), deltaLink);
|
|
41
|
+
return saved;
|
|
35
42
|
}
|
|
36
43
|
async getDeltaLink(internalUserId, resourceType) {
|
|
44
|
+
const key = this.cacheKey(internalUserId, resourceType);
|
|
45
|
+
const cached = this.deltaLinkCache.get(key);
|
|
46
|
+
if (cached !== undefined)
|
|
47
|
+
return cached;
|
|
37
48
|
const deltaLinkEntity = await this.repository.findOne({
|
|
38
49
|
where: { userId: internalUserId, resourceType },
|
|
39
|
-
cache: 30000,
|
|
40
50
|
});
|
|
41
|
-
|
|
51
|
+
const value = (deltaLinkEntity === null || deltaLinkEntity === void 0 ? void 0 : deltaLinkEntity.deltaLink) || null;
|
|
52
|
+
if (value)
|
|
53
|
+
this.deltaLinkCache.set(key, value);
|
|
54
|
+
return value;
|
|
42
55
|
}
|
|
43
56
|
async deleteDeltaLink(internalUserId, resourceType) {
|
|
44
57
|
await this.repository.delete({ userId: internalUserId, resourceType });
|
|
58
|
+
this.deltaLinkCache.delete(this.cacheKey(internalUserId, resourceType));
|
|
45
59
|
}
|
|
46
60
|
};
|
|
47
61
|
exports.OutlookDeltaLinkRepository = OutlookDeltaLinkRepository;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outlook-delta-link.repository.js","sourceRoot":"","sources":["../../src/repositories/outlook-delta-link.repository.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,6CAAmD;AACnD,qCAAqC;AACrC,qEAAiE;
|
|
1
|
+
{"version":3,"file":"outlook-delta-link.repository.js","sourceRoot":"","sources":["../../src/repositories/outlook-delta-link.repository.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,6CAAmD;AACnD,qCAAqC;AACrC,qEAAiE;AAEjE,4DAA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AAM,eAAe,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;YACpD,KAAK,EAAE,EAAE,MAAM,EAAE,cAAc,EAAE,YAAY,EAAE;SAChD,CAAC,CAAC;QAEH,MAAM,KAAK,GAAG,CAAA,eAAe,aAAf,eAAe,uBAAf,eAAe,CAAE,SAAS,KAAI,IAAI,CAAC;QACjD,IAAI,KAAK;YAAE,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC/C,OAAO,KAAK,CAAC;IACf,CAAC;IAOD,KAAK,CAAC,eAAe,CACnB,cAAsB,EACtB,YAA0B;QAE1B,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,cAAc,EAAE,YAAY,EAAE,CAAC,CAAC;QACvE,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,EAAE,YAAY,CAAC,CAAC,CAAC;IAC1E,CAAC;CACF,CAAA;AA9EY,gEAA0B;qCAA1B,0BAA0B;IADtC,IAAA,mBAAU,GAAE;IAKR,WAAA,IAAA,0BAAgB,EAAC,oCAAgB,CAAC,CAAA;qCACN,oBAAU;GAL9B,0BAA0B,CA8EtC"}
|
|
@@ -2,7 +2,10 @@ import { Repository } from 'typeorm';
|
|
|
2
2
|
import { OutlookWebhookSubscription } from '../entities/outlook-webhook-subscription.entity';
|
|
3
3
|
export declare class OutlookWebhookSubscriptionRepository {
|
|
4
4
|
private readonly repository;
|
|
5
|
+
private readonly bySubscriptionId;
|
|
6
|
+
private readonly byUserId;
|
|
5
7
|
constructor(repository: Repository<OutlookWebhookSubscription>);
|
|
8
|
+
private invalidate;
|
|
6
9
|
saveSubscription(subscription: Partial<OutlookWebhookSubscription>): Promise<OutlookWebhookSubscription>;
|
|
7
10
|
findBySubscriptionId(subscriptionId: string): Promise<OutlookWebhookSubscription | null>;
|
|
8
11
|
updateSubscriptionExpiration(subscriptionId: string, expirationDateTime: Date): Promise<void>;
|
|
@@ -17,9 +17,18 @@ const common_1 = require("@nestjs/common");
|
|
|
17
17
|
const typeorm_1 = require("@nestjs/typeorm");
|
|
18
18
|
const typeorm_2 = require("typeorm");
|
|
19
19
|
const outlook_webhook_subscription_entity_1 = require("../entities/outlook-webhook-subscription.entity");
|
|
20
|
+
const ttl_cache_util_1 = require("../utils/ttl-cache.util");
|
|
20
21
|
let OutlookWebhookSubscriptionRepository = class OutlookWebhookSubscriptionRepository {
|
|
21
22
|
constructor(repository) {
|
|
22
23
|
this.repository = repository;
|
|
24
|
+
this.bySubscriptionId = new ttl_cache_util_1.TtlCache(60000);
|
|
25
|
+
this.byUserId = new ttl_cache_util_1.TtlCache(60000);
|
|
26
|
+
}
|
|
27
|
+
invalidate(subscription) {
|
|
28
|
+
if (subscription === null || subscription === void 0 ? void 0 : subscription.subscriptionId)
|
|
29
|
+
this.bySubscriptionId.delete(subscription.subscriptionId);
|
|
30
|
+
if ((subscription === null || subscription === void 0 ? void 0 : subscription.userId) !== undefined)
|
|
31
|
+
this.byUserId.delete(subscription.userId);
|
|
23
32
|
}
|
|
24
33
|
async saveSubscription(subscription) {
|
|
25
34
|
if (subscription.subscriptionId) {
|
|
@@ -30,16 +39,26 @@ let OutlookWebhookSubscriptionRepository = class OutlookWebhookSubscriptionRepos
|
|
|
30
39
|
const originalId = existingSubscription.id;
|
|
31
40
|
Object.assign(existingSubscription, subscription);
|
|
32
41
|
existingSubscription.id = originalId;
|
|
33
|
-
|
|
42
|
+
const saved = await this.repository.save(existingSubscription);
|
|
43
|
+
this.invalidate(saved);
|
|
44
|
+
return saved;
|
|
34
45
|
}
|
|
35
46
|
}
|
|
36
47
|
const subscriptionWithoutId = Object.assign({}, subscription);
|
|
37
48
|
delete subscriptionWithoutId.id;
|
|
38
49
|
const newSubscription = this.repository.create(subscriptionWithoutId);
|
|
39
|
-
|
|
50
|
+
const saved = await this.repository.save(newSubscription);
|
|
51
|
+
this.invalidate(saved);
|
|
52
|
+
return saved;
|
|
40
53
|
}
|
|
41
54
|
async findBySubscriptionId(subscriptionId) {
|
|
42
|
-
|
|
55
|
+
const cached = this.bySubscriptionId.get(subscriptionId);
|
|
56
|
+
if (cached !== undefined)
|
|
57
|
+
return cached;
|
|
58
|
+
const result = await this.repository.findOne({ where: { subscriptionId, isActive: true } });
|
|
59
|
+
if (result)
|
|
60
|
+
this.bySubscriptionId.set(subscriptionId, result);
|
|
61
|
+
return result;
|
|
43
62
|
}
|
|
44
63
|
async updateSubscriptionExpiration(subscriptionId, expirationDateTime) {
|
|
45
64
|
const update = {
|
|
@@ -47,9 +66,13 @@ let OutlookWebhookSubscriptionRepository = class OutlookWebhookSubscriptionRepos
|
|
|
47
66
|
updatedAt: new Date(),
|
|
48
67
|
};
|
|
49
68
|
await this.repository.update({ subscriptionId, isActive: true }, update);
|
|
69
|
+
this.bySubscriptionId.delete(subscriptionId);
|
|
70
|
+
this.byUserId.clear();
|
|
50
71
|
}
|
|
51
72
|
async deactivateSubscription(subscriptionId) {
|
|
52
73
|
await this.repository.update({ subscriptionId }, { isActive: false, updatedAt: new Date() });
|
|
74
|
+
this.bySubscriptionId.delete(subscriptionId);
|
|
75
|
+
this.byUserId.clear();
|
|
53
76
|
}
|
|
54
77
|
async findSubscriptionsNeedingRenewal(hoursUntilExpiration) {
|
|
55
78
|
const expirationThreshold = new Date();
|
|
@@ -71,10 +94,15 @@ let OutlookWebhookSubscriptionRepository = class OutlookWebhookSubscriptionRepos
|
|
|
71
94
|
});
|
|
72
95
|
}
|
|
73
96
|
async findActiveByUserId(userId) {
|
|
74
|
-
|
|
97
|
+
const cached = this.byUserId.get(userId);
|
|
98
|
+
if (cached !== undefined)
|
|
99
|
+
return cached;
|
|
100
|
+
const result = await this.repository.findOne({
|
|
75
101
|
where: { userId, isActive: true },
|
|
76
|
-
cache: true,
|
|
77
102
|
});
|
|
103
|
+
if (result)
|
|
104
|
+
this.byUserId.set(userId, result);
|
|
105
|
+
return result;
|
|
78
106
|
}
|
|
79
107
|
async count(options) {
|
|
80
108
|
return await this.repository.count(options);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outlook-webhook-subscription.repository.js","sourceRoot":"","sources":["../../src/repositories/outlook-webhook-subscription.repository.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,6CAAmD;AACnD,qCAAyD;AACzD,yGAA6F;
|
|
1
|
+
{"version":3,"file":"outlook-webhook-subscription.repository.js","sourceRoot":"","sources":["../../src/repositories/outlook-webhook-subscription.repository.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,6CAAmD;AACnD,qCAAyD;AACzD,yGAA6F;AAC7F,4DAAmD;AAG5C,IAAM,oCAAoC,GAA1C,MAAM,oCAAoC;IAI/C,YAEE,UAAmE;QAAlD,eAAU,GAAV,UAAU,CAAwC;QALpD,qBAAgB,GAAG,IAAI,yBAAQ,CAAqC,KAAK,CAAC,CAAC;QAC3E,aAAQ,GAAG,IAAI,yBAAQ,CAAqC,KAAK,CAAC,CAAC;IAKjF,CAAC;IAEI,UAAU,CAAC,YAAyD;QAC1E,IAAI,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,cAAc;YAAE,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC;QAC5F,IAAI,CAAA,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,MAAM,MAAK,SAAS;YAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IACpF,CAAC;IAED,KAAK,CAAC,gBAAgB,CACpB,YAAiD;QAGjD,IAAI,YAAY,CAAC,cAAc,EAAE,CAAC;YAChC,MAAM,oBAAoB,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;gBACzD,KAAK,EAAE,EAAE,cAAc,EAAE,YAAY,CAAC,cAAc,EAAE;aACvD,CAA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F,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,kBAAkB,CAAC,MAAc;QACrC,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACzC,IAAI,MAAM,KAAK,SAAS;YAAE,OAAO,MAAM,CAAC;QAExC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;YAC3C,KAAK,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;SAClC,CAAC,CAAC;QACH,IAAI,MAAM;YAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC9C,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,OAAuE;QACjF,OAAO,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC9C,CAAC;CACF,CAAA;AAjHY,oFAAoC;+CAApC,oCAAoC;IADhD,IAAA,mBAAU,GAAE;IAMR,WAAA,IAAA,0BAAgB,EAAC,gEAA0B,CAAC,CAAA;qCAChB,oBAAU;GAN9B,oCAAoC,CAiHhD"}
|
|
@@ -25,6 +25,7 @@ export declare class MicrosoftAuthService {
|
|
|
25
25
|
private readonly defaultScopes;
|
|
26
26
|
private readonly CSRF_TOKEN_EXPIRY;
|
|
27
27
|
private subscriptionInProgress;
|
|
28
|
+
private readonly microsoftUserCache;
|
|
28
29
|
constructor(eventEmitter: EventEmitter2, calendarService: CalendarService, emailService: EmailService, microsoftConfig: MicrosoftOutlookConfig, csrfTokenRepository: MicrosoftCsrfTokenRepository, microsoftUserRepository: Repository<MicrosoftUser>);
|
|
29
30
|
private mapToMicrosoftScopes;
|
|
30
31
|
private buildRedirectUri;
|
|
@@ -35,6 +36,8 @@ export declare class MicrosoftAuthService {
|
|
|
35
36
|
getLoginUrl(externalUserId: string, scopes?: PermissionScope[]): Promise<string>;
|
|
36
37
|
private saveMicrosoftUser;
|
|
37
38
|
private getMicrosoftUser;
|
|
39
|
+
private buildUserCacheKey;
|
|
40
|
+
private invalidateUserCache;
|
|
38
41
|
getUserAccessToken(params: {
|
|
39
42
|
internalUserId?: number;
|
|
40
43
|
externalUserId?: string;
|
|
@@ -43,6 +46,9 @@ export declare class MicrosoftAuthService {
|
|
|
43
46
|
}): Promise<string>;
|
|
44
47
|
private processTokenInfo;
|
|
45
48
|
exchangeCodeForToken(code: string, state: string): Promise<TokenResponse>;
|
|
49
|
+
private isMailboxDisabledError;
|
|
50
|
+
private validateMailboxAccess;
|
|
51
|
+
private deactivateMicrosoftUser;
|
|
46
52
|
private setupSubscriptions;
|
|
47
53
|
refreshAccessToken(refreshToken: string, internalUserId: number): Promise<string>;
|
|
48
54
|
revokeRefreshToken(refreshToken: string): Promise<void>;
|
|
@@ -29,6 +29,8 @@ const typeorm_1 = require("@nestjs/typeorm");
|
|
|
29
29
|
const typeorm_2 = require("typeorm");
|
|
30
30
|
const microsoft_user_entity_1 = require("../../entities/microsoft-user.entity");
|
|
31
31
|
const retry_util_1 = require("../../utils/retry.util");
|
|
32
|
+
const ttl_cache_util_1 = require("../../utils/ttl-cache.util");
|
|
33
|
+
const mailbox_inactive_error_1 = require("../../errors/mailbox-inactive.error");
|
|
32
34
|
let MicrosoftAuthService = MicrosoftAuthService_1 = class MicrosoftAuthService {
|
|
33
35
|
constructor(eventEmitter, calendarService, emailService, microsoftConfig, csrfTokenRepository, microsoftUserRepository) {
|
|
34
36
|
this.eventEmitter = eventEmitter;
|
|
@@ -49,6 +51,7 @@ let MicrosoftAuthService = MicrosoftAuthService_1 = class MicrosoftAuthService {
|
|
|
49
51
|
];
|
|
50
52
|
this.CSRF_TOKEN_EXPIRY = 30 * 60 * 1000;
|
|
51
53
|
this.subscriptionInProgress = new Map();
|
|
54
|
+
this.microsoftUserCache = new ttl_cache_util_1.TtlCache(30000);
|
|
52
55
|
console.log('MicrosoftAuthService constructor - microsoftConfig:', {
|
|
53
56
|
clientId: this.microsoftConfig.clientId,
|
|
54
57
|
redirectUri: this.microsoftConfig.redirectPath,
|
|
@@ -184,12 +187,19 @@ let MicrosoftAuthService = MicrosoftAuthService_1 = class MicrosoftAuthService {
|
|
|
184
187
|
user.scopes = scopes;
|
|
185
188
|
user.isActive = true;
|
|
186
189
|
await this.microsoftUserRepository.save(user);
|
|
190
|
+
this.invalidateUserCache(user);
|
|
187
191
|
}
|
|
188
192
|
async getMicrosoftUser(params) {
|
|
189
193
|
const { internalUserId, externalUserId, includeInactive = false, cache = true } = params;
|
|
190
194
|
if (!internalUserId && !externalUserId) {
|
|
191
195
|
throw new Error('Either internalUserId or externalUserId must be provided');
|
|
192
196
|
}
|
|
197
|
+
const cacheKey = this.buildUserCacheKey({ internalUserId, externalUserId, includeInactive });
|
|
198
|
+
if (cache) {
|
|
199
|
+
const cached = this.microsoftUserCache.get(cacheKey);
|
|
200
|
+
if (cached !== undefined)
|
|
201
|
+
return cached;
|
|
202
|
+
}
|
|
193
203
|
const whereCondition = {};
|
|
194
204
|
if (!includeInactive) {
|
|
195
205
|
whereCondition.isActive = true;
|
|
@@ -200,10 +210,26 @@ let MicrosoftAuthService = MicrosoftAuthService_1 = class MicrosoftAuthService {
|
|
|
200
210
|
if (externalUserId !== undefined) {
|
|
201
211
|
whereCondition.externalUserId = externalUserId;
|
|
202
212
|
}
|
|
203
|
-
|
|
213
|
+
const user = await this.microsoftUserRepository.findOne({
|
|
204
214
|
where: whereCondition,
|
|
205
|
-
cache,
|
|
206
215
|
});
|
|
216
|
+
if (cache && user) {
|
|
217
|
+
this.microsoftUserCache.set(cacheKey, user);
|
|
218
|
+
}
|
|
219
|
+
return user;
|
|
220
|
+
}
|
|
221
|
+
buildUserCacheKey(params) {
|
|
222
|
+
var _a;
|
|
223
|
+
const scope = params.includeInactive ? 'any' : 'active';
|
|
224
|
+
if (params.internalUserId !== undefined)
|
|
225
|
+
return `int:${String(params.internalUserId)}:${scope}`;
|
|
226
|
+
return `ext:${(_a = params.externalUserId) !== null && _a !== void 0 ? _a : ''}:${scope}`;
|
|
227
|
+
}
|
|
228
|
+
invalidateUserCache(user) {
|
|
229
|
+
for (const scope of ['active', 'any']) {
|
|
230
|
+
this.microsoftUserCache.delete(`int:${String(user.id)}:${scope}`);
|
|
231
|
+
this.microsoftUserCache.delete(`ext:${user.externalUserId}:${scope}`);
|
|
232
|
+
}
|
|
207
233
|
}
|
|
208
234
|
async getUserAccessToken(params) {
|
|
209
235
|
try {
|
|
@@ -285,6 +311,8 @@ let MicrosoftAuthService = MicrosoftAuthService_1 = class MicrosoftAuthService {
|
|
|
285
311
|
};
|
|
286
312
|
this.logger.log(`[${correlationId}] Saving Microsoft user to database`);
|
|
287
313
|
await this.saveMicrosoftUser(stateData.userId, tokenData.access_token, tokenData.refresh_token, tokenData.expires_in, scopeString);
|
|
314
|
+
this.logger.log(`[${correlationId}] Validating mailbox access`);
|
|
315
|
+
await this.validateMailboxAccess(tokenData.access_token, correlationId);
|
|
288
316
|
this.logger.log(`[${correlationId}] Emitting USER_AUTHENTICATED event`);
|
|
289
317
|
await Promise.resolve(this.eventEmitter.emit(event_types_enum_1.OutlookEventTypes.USER_AUTHENTICATED, stateData.userId, {
|
|
290
318
|
externalUserId: stateData.userId,
|
|
@@ -296,6 +324,10 @@ let MicrosoftAuthService = MicrosoftAuthService_1 = class MicrosoftAuthService {
|
|
|
296
324
|
return tokenData;
|
|
297
325
|
}
|
|
298
326
|
catch (error) {
|
|
327
|
+
if (error instanceof mailbox_inactive_error_1.MailboxInactiveError) {
|
|
328
|
+
await this.deactivateMicrosoftUser(stateData.userId, correlationId);
|
|
329
|
+
throw error;
|
|
330
|
+
}
|
|
299
331
|
if (axios_1.default.isAxiosError(error)) {
|
|
300
332
|
this.logger.error(`[${correlationId}] Microsoft token exchange failed:`, {
|
|
301
333
|
status: (_a = error.response) === null || _a === void 0 ? void 0 : _a.status,
|
|
@@ -311,6 +343,40 @@ let MicrosoftAuthService = MicrosoftAuthService_1 = class MicrosoftAuthService {
|
|
|
311
343
|
throw new Error('Failed to exchange code for token');
|
|
312
344
|
}
|
|
313
345
|
}
|
|
346
|
+
isMailboxDisabledError(code, message) {
|
|
347
|
+
return (code === constants_1.GRAPH_ERROR_CODES.MAILBOX_NOT_ENABLED ||
|
|
348
|
+
/inactive|soft-deleted|on-premise/i.test(message !== null && message !== void 0 ? message : ''));
|
|
349
|
+
}
|
|
350
|
+
async validateMailboxAccess(accessToken, correlationId) {
|
|
351
|
+
var _a;
|
|
352
|
+
try {
|
|
353
|
+
await axios_1.default.get('https://graph.microsoft.com/v1.0/me/mailboxSettings', {
|
|
354
|
+
headers: { Authorization: `Bearer ${accessToken}` },
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
catch (error) {
|
|
358
|
+
if (axios_1.default.isAxiosError(error)) {
|
|
359
|
+
const responseData = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data;
|
|
360
|
+
const graphError = responseData === null || responseData === void 0 ? void 0 : responseData.error;
|
|
361
|
+
const code = graphError === null || graphError === void 0 ? void 0 : graphError.code;
|
|
362
|
+
const message = (graphError === null || graphError === void 0 ? void 0 : graphError.message) || error.message;
|
|
363
|
+
if (this.isMailboxDisabledError(code, message)) {
|
|
364
|
+
this.logger.warn(`[${correlationId}] Mailbox validation failed: ${code} — ${message}`);
|
|
365
|
+
throw new mailbox_inactive_error_1.MailboxInactiveError(message);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
this.logger.warn(`[${correlationId}] Mailbox validation call failed (non-blocking): ${error instanceof Error ? error.message : String(error)}`);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
async deactivateMicrosoftUser(externalUserId, correlationId) {
|
|
372
|
+
try {
|
|
373
|
+
await this.microsoftUserRepository.update({ externalUserId }, { isActive: false });
|
|
374
|
+
this.logger.log(`[${correlationId}] Deactivated Microsoft user ${externalUserId} due to unusable mailbox`);
|
|
375
|
+
}
|
|
376
|
+
catch (err) {
|
|
377
|
+
this.logger.warn(`[${correlationId}] Failed to deactivate Microsoft user ${externalUserId}: ${err instanceof Error ? err.message : String(err)}`);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
314
380
|
async setupSubscriptions(externalUserId, scopes = this.defaultScopes) {
|
|
315
381
|
if (this.subscriptionInProgress.get(externalUserId)) {
|
|
316
382
|
this.logger.log(`Subscription setup already in progress for user ${externalUserId}`);
|
|
@@ -409,6 +475,7 @@ let MicrosoftAuthService = MicrosoftAuthService_1 = class MicrosoftAuthService {
|
|
|
409
475
|
internalUser.refreshToken = newRefreshToken;
|
|
410
476
|
internalUser.tokenExpiry = new Date(Date.now() + response.data.expires_in * 1000);
|
|
411
477
|
await this.microsoftUserRepository.save(internalUser);
|
|
478
|
+
this.invalidateUserCache(internalUser);
|
|
412
479
|
return newAccessToken;
|
|
413
480
|
}
|
|
414
481
|
catch (error) {
|