@rapidmx/autodiscover 1.0.0-beta.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.
package/LICENSE ADDED
@@ -0,0 +1,382 @@
1
+ # Mozilla Public License Version 2.0
2
+
3
+ 1. Definitions
4
+
5
+ ---
6
+
7
+ 1.1. "Contributor"
8
+ means each individual or legal entity that creates, contributes to
9
+ the creation of, or owns Covered Software.
10
+
11
+ 1.2. "Contributor Version"
12
+ means the combination of the Contributions of others (if any) used
13
+ by a Contributor and that particular Contributor's Contribution.
14
+
15
+ 1.3. "Contribution"
16
+ means Covered Software of a particular Contributor.
17
+
18
+ 1.4. "Covered Software"
19
+ means Source Code Form to which the initial Contributor has attached
20
+ the notice in Exhibit A, the Executable Form of such Source Code
21
+ Form, and Modifications of such Source Code Form, in each case
22
+ including portions thereof.
23
+
24
+ 1.5. "Incompatible With Secondary Licenses"
25
+ means
26
+
27
+ (a) that the initial Contributor has attached the notice described
28
+ in Exhibit B to the Covered Software; or
29
+
30
+ (b) that the Covered Software was made available under the terms of
31
+ version 1.1 or earlier of the License, but not also under the
32
+ terms of a Secondary License.
33
+
34
+ 1.6. "Executable Form"
35
+ means any form of the work other than Source Code Form.
36
+
37
+ 1.7. "Larger Work"
38
+ means a work that combines Covered Software with other material, in
39
+ a separate file or files, that is not Covered Software.
40
+
41
+ 1.8. "License"
42
+ means this document.
43
+
44
+ 1.9. "Licensable"
45
+ means having the right to grant, to the maximum extent possible,
46
+ whether at the time of the initial grant or subsequently, any and
47
+ all of the rights conveyed by this License.
48
+
49
+ 1.10. "Modifications"
50
+ means any of the following:
51
+
52
+ (a) any file in Source Code Form that results from an addition to,
53
+ deletion from, or modification of the contents of Covered
54
+ Software; or
55
+
56
+ (b) any new file in Source Code Form that contains any Covered
57
+ Software.
58
+
59
+ 1.11. "Patent Claims" of a Contributor
60
+ means any patent claim(s), including without limitation, method,
61
+ process, and apparatus claims, in any patent Licensable by such
62
+ Contributor that would be infringed, but for the grant of the
63
+ License, by the making, using, selling, offering for sale, having
64
+ made, import, or transfer of either its Contributions or its
65
+ Contributor Version.
66
+
67
+ 1.12. "Secondary License"
68
+ means either the GNU General Public License, Version 2.0, the GNU
69
+ Lesser General Public License, Version 2.1, the GNU Affero General
70
+ Public License, Version 3.0, or any later versions of those
71
+ licenses.
72
+
73
+ 1.13. "Source Code Form"
74
+ means the form of the work preferred for making modifications.
75
+
76
+ 1.14. "You" (or "Your")
77
+ means an individual or a legal entity exercising rights under this
78
+ License. For legal entities, "You" includes any entity that
79
+ controls, is controlled by, or is under common control with You. For
80
+ purposes of this definition, "control" means (a) the power, direct
81
+ or indirect, to cause the direction or management of such entity,
82
+ whether by contract or otherwise, or (b) ownership of more than
83
+ fifty percent (50%) of the outstanding shares or beneficial
84
+ ownership of such entity.
85
+
86
+ 2. License Grants and Conditions
87
+
88
+ ---
89
+
90
+ 2.1. Grants
91
+
92
+ Each Contributor hereby grants You a world-wide, royalty-free,
93
+ non-exclusive license:
94
+
95
+ (a) under intellectual property rights (other than patent or trademark)
96
+ Licensable by such Contributor to use, reproduce, make available,
97
+ modify, display, perform, distribute, and otherwise exploit its
98
+ Contributions, either on an unmodified basis, with Modifications, or
99
+ as part of a Larger Work; and
100
+
101
+ (b) under Patent Claims of such Contributor to make, use, sell, offer
102
+ for sale, have made, import, and otherwise transfer either its
103
+ Contributions or its Contributor Version.
104
+
105
+ 2.2. Effective Date
106
+
107
+ The licenses granted in Section 2.1 with respect to any Contribution
108
+ become effective for each Contribution on the date the Contributor first
109
+ distributes such Contribution.
110
+
111
+ 2.3. Limitations on Grant Scope
112
+
113
+ The licenses granted in this Section 2 are the only rights granted under
114
+ this License. No additional rights or licenses will be implied from the
115
+ distribution or licensing of Covered Software under this License.
116
+ Notwithstanding Section 2.1(b) above, no patent license is granted by a
117
+ Contributor:
118
+
119
+ (a) for any code that a Contributor has removed from Covered Software;
120
+ or
121
+
122
+ (b) for infringements caused by: (i) Your and any other third party's
123
+ modifications of Covered Software, or (ii) the combination of its
124
+ Contributions with other software (except as part of its Contributor
125
+ Version); or
126
+
127
+ (c) under Patent Claims infringed by Covered Software in the absence of
128
+ its Contributions.
129
+
130
+ This License does not grant any rights in the trademarks, service marks,
131
+ or logos of any Contributor (except as may be necessary to comply with
132
+ the notice requirements in Section 3.4).
133
+
134
+ 2.4. Subsequent Licenses
135
+
136
+ No Contributor makes additional grants as a result of Your choice to
137
+ distribute the Covered Software under a subsequent version of this
138
+ License (see Section 10.2) or under the terms of a Secondary License (if
139
+ permitted under the terms of Section 3.3).
140
+
141
+ 2.5. Representation
142
+
143
+ Each Contributor represents that the Contributor believes its
144
+ Contributions are its original creation(s) or it has sufficient rights
145
+ to grant the rights to its Contributions conveyed by this License.
146
+
147
+ 2.6. Fair Use
148
+
149
+ This License is not intended to limit any rights You have under
150
+ applicable copyright doctrines of fair use, fair dealing, or other
151
+ equivalents.
152
+
153
+ 2.7. Conditions
154
+
155
+ Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
156
+ in Section 2.1.
157
+
158
+ 3. Responsibilities
159
+
160
+ ---
161
+
162
+ 3.1. Distribution of Source Form
163
+
164
+ All distribution of Covered Software in Source Code Form, including any
165
+ Modifications that You create or to which You contribute, must be under
166
+ the terms of this License. You must inform recipients that the Source
167
+ Code Form of the Covered Software is governed by the terms of this
168
+ License, and how they can obtain a copy of this License. You may not
169
+ attempt to alter or restrict the recipients' rights in the Source Code
170
+ Form.
171
+
172
+ 3.2. Distribution of Executable Form
173
+
174
+ If You distribute Covered Software in Executable Form then:
175
+
176
+ (a) such Covered Software must also be made available in Source Code
177
+ Form, as described in Section 3.1, and You must inform recipients of
178
+ the Executable Form how they can obtain a copy of such Source Code
179
+ Form by reasonable means in a timely manner, at a charge no more
180
+ than the cost of distribution to the recipient; and
181
+
182
+ (b) You may distribute such Executable Form under the terms of this
183
+ License, or sublicense it under different terms, provided that the
184
+ license for the Executable Form does not attempt to limit or alter
185
+ the recipients' rights in the Source Code Form under this License.
186
+
187
+ 3.3. Distribution of a Larger Work
188
+
189
+ You may create and distribute a Larger Work under terms of Your choice,
190
+ provided that You also comply with the requirements of this License for
191
+ the Covered Software. If the Larger Work is a combination of Covered
192
+ Software with a work governed by one or more Secondary Licenses, and the
193
+ Covered Software is not Incompatible With Secondary Licenses, this
194
+ License permits You to additionally distribute such Covered Software
195
+ under the terms of such Secondary License(s), so that the recipient of
196
+ the Larger Work may, at their option, further distribute the Covered
197
+ Software under the terms of either this License or such Secondary
198
+ License(s).
199
+
200
+ 3.4. Notices
201
+
202
+ You may not remove or alter the substance of any license notices
203
+ (including copyright notices, patent notices, disclaimers of warranty,
204
+ or limitations of liability) contained within the Source Code Form of
205
+ the Covered Software, except that You may alter any license notices to
206
+ the extent required to remedy known factual inaccuracies.
207
+
208
+ 3.5. Application of Additional Terms
209
+
210
+ You may choose to offer, and to charge a fee for, warranty, support,
211
+ indemnity or liability obligations to one or more recipients of Covered
212
+ Software. However, You may do so only on Your own behalf, and not on
213
+ behalf of any Contributor. You must make it absolutely clear that any
214
+ such warranty, support, indemnity, or liability obligation is offered by
215
+ You alone, and You hereby agree to indemnify every Contributor for any
216
+ liability incurred by such Contributor as a result of warranty, support,
217
+ indemnity or liability terms You offer. You may include additional
218
+ disclaimers of warranty and limitations of liability specific to any
219
+ jurisdiction.
220
+
221
+ 4. Inability to Comply Due to Statute or Regulation
222
+
223
+ ---
224
+
225
+ If it is impossible for You to comply with any of the terms of this
226
+ License with respect to some or all of the Covered Software due to
227
+ statute, judicial order, or regulation then You must: (a) comply with
228
+ the terms of this License to the maximum extent possible; and (b)
229
+ describe the limitations and the code they affect. Such description must
230
+ be placed in a text file included with all distributions of the Covered
231
+ Software under this License. Except to the extent prohibited by statute
232
+ or regulation, such description must be sufficiently detailed for a
233
+ recipient of ordinary skill to be able to understand it.
234
+
235
+ 5. Termination
236
+
237
+ ---
238
+
239
+ 5.1. The rights granted under this License will terminate automatically
240
+ if You fail to comply with any of its terms. However, if You become
241
+ compliant, then the rights granted under this License from a particular
242
+ Contributor are reinstated (a) provisionally, unless and until such
243
+ Contributor explicitly and finally terminates Your grants, and (b) on an
244
+ ongoing basis, if such Contributor fails to notify You of the
245
+ non-compliance by some reasonable means prior to 60 days after You have
246
+ come back into compliance. Moreover, Your grants from a particular
247
+ Contributor are reinstated on an ongoing basis if such Contributor
248
+ notifies You of the non-compliance by some reasonable means, this is the
249
+ first time You have received notice of non-compliance with this License
250
+ from such Contributor, and You become compliant prior to 30 days after
251
+ Your receipt of the notice.
252
+
253
+ 5.2. If You initiate litigation against any entity by asserting a patent
254
+ infringement claim (excluding declaratory judgment actions,
255
+ counter-claims, and cross-claims) alleging that a Contributor Version
256
+ directly or indirectly infringes any patent, then the rights granted to
257
+ You by any and all Contributors for the Covered Software under Section
258
+ 2.1 of this License shall terminate.
259
+
260
+ 5.3. In the event of termination under Sections 5.1 or 5.2 above, all
261
+ end user license agreements (excluding distributors and resellers) which
262
+ have been validly granted by You or Your distributors under this License
263
+ prior to termination shall survive termination.
264
+
265
+ ---
266
+
267
+ - *
268
+ - 6. Disclaimer of Warranty \*
269
+ - ------------------------- \*
270
+ - *
271
+ - Covered Software is provided under this License on an "as is" \*
272
+ - basis, without warranty of any kind, either expressed, implied, or \*
273
+ - statutory, including, without limitation, warranties that the \*
274
+ - Covered Software is free of defects, merchantable, fit for a \*
275
+ - particular purpose or non-infringing. The entire risk as to the \*
276
+ - quality and performance of the Covered Software is with You. \*
277
+ - Should any Covered Software prove defective in any respect, You \*
278
+ - (not any Contributor) assume the cost of any necessary servicing, \*
279
+ - repair, or correction. This disclaimer of warranty constitutes an \*
280
+ - essential part of this License. No use of any Covered Software is \*
281
+ - authorized under this License except under this disclaimer. \*
282
+ - *
283
+
284
+ ---
285
+
286
+ ---
287
+
288
+ - *
289
+ - 7. Limitation of Liability \*
290
+ - -------------------------- \*
291
+ - *
292
+ - Under no circumstances and under no legal theory, whether tort \*
293
+ - (including negligence), contract, or otherwise, shall any \*
294
+ - Contributor, or anyone who distributes Covered Software as \*
295
+ - permitted above, be liable to You for any direct, indirect, \*
296
+ - special, incidental, or consequential damages of any character \*
297
+ - including, without limitation, damages for lost profits, loss of \*
298
+ - goodwill, work stoppage, computer failure or malfunction, or any \*
299
+ - and all other commercial damages or losses, even if such party \*
300
+ - shall have been informed of the possibility of such damages. This \*
301
+ - limitation of liability shall not apply to liability for death or \*
302
+ - personal injury resulting from such party's negligence to the \*
303
+ - extent applicable law prohibits such limitation. Some \*
304
+ - jurisdictions do not allow the exclusion or limitation of \*
305
+ - incidental or consequential damages, so this exclusion and \*
306
+ - limitation may not apply to You. \*
307
+ - *
308
+
309
+ ---
310
+
311
+ 8. Litigation
312
+
313
+ ---
314
+
315
+ Any litigation relating to this License may be brought only in the
316
+ courts of a jurisdiction where the defendant maintains its principal
317
+ place of business and such litigation shall be governed by laws of that
318
+ jurisdiction, without reference to its conflict-of-law provisions.
319
+ Nothing in this Section shall prevent a party's ability to bring
320
+ cross-claims or counter-claims.
321
+
322
+ 9. Miscellaneous
323
+
324
+ ---
325
+
326
+ This License represents the complete agreement concerning the subject
327
+ matter hereof. If any provision of this License is held to be
328
+ unenforceable, such provision shall be reformed only to the extent
329
+ necessary to make it enforceable. Any law or regulation which provides
330
+ that the language of a contract shall be construed against the drafter
331
+ shall not be used to construe this License against a Contributor.
332
+
333
+ 10. Versions of the License
334
+
335
+ ---
336
+
337
+ 10.1. New Versions
338
+
339
+ Mozilla Foundation is the license steward. Except as provided in Section
340
+ 10.3, no one other than the license steward has the right to modify or
341
+ publish new versions of this License. Each version will be given a
342
+ distinguishing version number.
343
+
344
+ 10.2. Effect of New Versions
345
+
346
+ You may distribute the Covered Software under the terms of the version
347
+ of the License under which You originally received the Covered Software,
348
+ or under the terms of any subsequent version published by the license
349
+ steward.
350
+
351
+ 10.3. Modified Versions
352
+
353
+ If you create software not governed by this License, and you want to
354
+ create a new license for such software, you may create and use a
355
+ modified version of this License if you rename the license and remove
356
+ any references to the name of the license steward (except to note that
357
+ such modified license differs from this License).
358
+
359
+ 10.4. Distributing Source Code Form that is Incompatible With Secondary
360
+ Licenses
361
+
362
+ If You choose to distribute Source Code Form that is Incompatible With
363
+ Secondary Licenses under the terms of this version of the License, the
364
+ notice described in Exhibit B of this License must be attached.
365
+
366
+ ## Exhibit A - Source Code Form License Notice
367
+
368
+ This Source Code Form is subject to the terms of the Mozilla Public
369
+ License, v. 2.0. If a copy of the MPL was not distributed with this
370
+ file, You can obtain one at https://mozilla.org/MPL/2.0/.
371
+
372
+ If it is not possible or desirable to put the notice in a particular
373
+ file, then You may include the notice in a location (such as a LICENSE
374
+ file in a relevant directory) where a recipient would be likely to look
375
+ for such a notice.
376
+
377
+ You may add additional accurate notices of copyright ownership.
378
+
379
+ ## Exhibit B - "Incompatible With Secondary Licenses" Notice
380
+
381
+ This Source Code Form is "Incompatible With Secondary Licenses", as
382
+ defined by the Mozilla Public License, v. 2.0.
package/README.md ADDED
@@ -0,0 +1,90 @@
1
+ # RapidMX: Autodiscover
2
+
3
+ [![CI](https://github.com/RapidMX/autodiscover/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/RapidMX/autodiscover/actions/workflows/build.yml)
4
+ [![Coverage Status](https://coveralls.io/repos/github/RapidMX/autodiscover/badge.svg?branch=main)](https://coveralls.io/github/RapidMX/autodiscover?branch=main)
5
+ [![npm version](https://img.shields.io/npm/v/@rapidmx/autodiscover)](https://www.npmjs.com/package/@rapidmx/autodiscover)
6
+
7
+ Autodiscover support for a [RapidMX](https://rapidmx.io) mail server. Lets a real mail client find this
8
+ deployment's [`@rapidmx/activesync`](https://github.com/RapidMX/activesync) (EAS) and
9
+ [`@rapidmx/mapi`](https://github.com/RapidMX/mapi) server URLs from just an email address: classic
10
+ POX (`POST /autodiscover/autodiscover.xml`, serving either the EAS-only MobileSync response or, when a real
11
+ Outlook desktop client requests it via `AcceptableResponseSchema`, an Outlook/EXCH response pointing at the
12
+ MAPI/HTTP endpoint) and the modern JSON variant Microsoft calls "Autodiscover v2"
13
+ (`GET /autodiscover/autodiscover.json/v1.0/<email>?Protocol=ActiveSync`, EAS only — this package has no
14
+ separate JSON discovery variant for MAPI).
15
+
16
+ Both endpoints are intentionally unauthenticated, matching Autodiscover v2's own spec design: they reveal
17
+ nothing but deployment-wide server URLs (not secrets) once the requested address is confirmed to belong to a
18
+ real mailbox — real mailbox access is still fully gated by the JWT-protected EAS/MAPI/REST layers. For a real
19
+ device to find these endpoints at all, the deployment's DNS needs a `CNAME` record for
20
+ `autodiscover.<your-domain>` (and, optionally, a `_autodiscover._tcp` `SRV` record) pointing at wherever this
21
+ server is mounted — an ops/deployment task, not something this package configures.
22
+
23
+ ## Features
24
+
25
+ * Classic POX Autodiscover (`POST /autodiscover/autodiscover.xml`) per `[MS-ASCMD]`'s MobileSync request/
26
+ response schema
27
+ * A real Outlook desktop response shape per `[MS-OXDSCLI]`'s Outlook/EXCH `2006a` schema, served automatically
28
+ instead of the MobileSync response whenever a request's `AcceptableResponseSchema` asks for it — points a
29
+ real Outlook client at this deployment's MAPI/HTTP endpoint instead of EAS
30
+ * Autodiscover v2 (JSON) (`GET /autodiscover/autodiscover.json/v1.0/:email?Protocol=ActiveSync`) for modern
31
+ clients that skip the POX request/response XML entirely
32
+ * Mailbox resolution against both `Mailbox.primarySmtpAddress` and `Mailbox.aliasAddresses`
33
+ * Deliberately unauthenticated by design — reveals only deployment-wide server URLs, never a per-mailbox
34
+ secret
35
+ * MongoDB and SQL persistence backends (`@rapidmx/autodiscover/mongo`, `@rapidmx/autodiscover/sql`)
36
+
37
+ ## Installation
38
+
39
+ ### NPM
40
+
41
+ ```
42
+ npm i @rapidmx/autodiscover
43
+ ```
44
+
45
+ ### Yarn
46
+
47
+ ```
48
+ yarn add @rapidmx/autodiscover
49
+ ```
50
+
51
+ ## Requirements
52
+
53
+ This package targets Node.js `>=24.0.0` and is published as an ESM-only package.
54
+
55
+ The following peer dependencies are required:
56
+
57
+ | Peer dependency | Required for |
58
+ | -------------------------- | ------------ |
59
+ | `@rapidmx/restapi` | Always |
60
+ | `@rapidrest/core` | Always |
61
+ | `@rapidrest/service-core` | Always |
62
+
63
+ ## Usage
64
+
65
+ Mount `AutodiscoverRouteMongo`/`AutodiscoverRouteSQL` (from `@rapidmx/autodiscover/mongo` or `/sql`) with a
66
+ one-line subclass supplying your deployment's EAS and MAPI URLs:
67
+
68
+ ```ts
69
+ import { AutodiscoverRouteMongo } from "@rapidmx/autodiscover/mongo";
70
+ import { RouteDecorators } from "@rapidrest/service-core";
71
+ const { Route } = RouteDecorators;
72
+
73
+ @Route("/autodiscover")
74
+ export class MyAutodiscoverRoute extends AutodiscoverRouteMongo {
75
+ protected readonly easUrl = "https://mail.example.com/Microsoft-Server-ActiveSync";
76
+ protected readonly mapiUrl = "https://mail.example.com/mapi/emsmdb";
77
+ }
78
+ ```
79
+
80
+ Requires a [`@rapidmx/restapi`](https://github.com/RapidMX/restapi)-backed `Mailbox` model to resolve
81
+ addresses against.
82
+
83
+ ## Status
84
+
85
+ Complete. This package was carved out of the former `@rapidrest/mail` monolith — see `.claude/NOTES.md` for
86
+ the split's own rationale and history.
87
+
88
+ ## License
89
+
90
+ MPL v2.0 — see [LICENSE](./LICENSE).
@@ -0,0 +1,137 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2026 Jean-Philippe Steinmetz. All rights reserved.
3
+ // SPDX-License-Identifier: MPL-2.0
4
+ ///////////////////////////////////////////////////////////////////////////////
5
+ /**
6
+ * Minimal, purpose-built XML handling for the classic POX Autodiscover request/response (`[MS-ASCMD]`'s
7
+ * "MobileSync" schema) - deliberately NOT a general-purpose XML/DOM parser. `BaseAutodiscoverRoute`'s POX
8
+ * endpoint is unauthenticated and internet-facing (see its own doc comment for why), and the real request
9
+ * schema has exactly one field this library ever reads (`EMailAddress`), so pulling in a general XML parser -
10
+ * especially one not hardened against XXE/entity-expansion - would be real attack surface for zero benefit.
11
+ * This follows the same "hand-build the wire format precisely, no library" approach Phase 2's WBXML codec
12
+ * already took, just for text XML instead of binary.
13
+ */
14
+ const EMAIL_ELEMENT_PATTERN = /<[\w:]*EMailAddress[^>]*>\s*([^<]*?)\s*<\/[\w:]*EMailAddress>/i;
15
+ /**
16
+ * Extracts the request's `<EMailAddress>` text content via a small, tightly-scoped regex rather than a DOM
17
+ * parse. Never resolves entities/DTDs - only the literal text between the open/close tags is ever inspected.
18
+ */
19
+ export function extractEmailAddress(xml) {
20
+ const match = EMAIL_ELEMENT_PATTERN.exec(xml);
21
+ const value = match?.[1]?.trim();
22
+ return value ? decodeXmlEntities(value) : undefined;
23
+ }
24
+ /** Escapes the 5 XML-predefined-entity characters for safe inclusion as element text content. */
25
+ export function escapeXml(value) {
26
+ return value
27
+ .replace(/&/g, "&amp;")
28
+ .replace(/</g, "&lt;")
29
+ .replace(/>/g, "&gt;")
30
+ .replace(/"/g, "&quot;")
31
+ .replace(/'/g, "&apos;");
32
+ }
33
+ function decodeXmlEntities(value) {
34
+ return value
35
+ .replace(/&lt;/g, "<")
36
+ .replace(/&gt;/g, ">")
37
+ .replace(/&quot;/g, '"')
38
+ .replace(/&apos;/g, "'")
39
+ .replace(/&amp;/g, "&");
40
+ }
41
+ const ACCEPTABLE_RESPONSE_SCHEMA_PATTERN = /<[\w:]*AcceptableResponseSchema[^>]*>\s*([^<]*?)\s*<\/[\w:]*AcceptableResponseSchema>/i;
42
+ /** The `AcceptableResponseSchema` value a real Outlook desktop client sends to request the Outlook/EXCH
43
+ * response shape (`buildOutlookSuccessXml`) instead of the EAS-only MobileSync one - confirmed against
44
+ * `[MS-OXDSCLI]`'s own Autodiscover Response XSD, whose target namespace is exactly this value. */
45
+ export const OUTLOOK_RESPONSE_SCHEMA = "http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a";
46
+ /**
47
+ * Extracts the request's `<AcceptableResponseSchema>` text content via the same small, tightly-scoped regex
48
+ * approach as `extractEmailAddress` - never a DOM parse, same rationale (unauthenticated, internet-facing
49
+ * endpoint).
50
+ */
51
+ export function extractAcceptableResponseSchema(xml) {
52
+ const match = ACCEPTABLE_RESPONSE_SCHEMA_PATTERN.exec(xml);
53
+ return match?.[1]?.trim() || undefined;
54
+ }
55
+ /**
56
+ * Builds a real `mobilesync:Response` success document per `[MS-ASCMD]`'s `AutodiscoverMobileSync.xsd` -
57
+ * `Culture`/`User`/`Action.Settings.Server{Type=MobileSync,Url,Name}`, matching the shape confirmed against
58
+ * Microsoft's own "Autodiscover for Exchange ActiveSync developers" example response. A real response can also
59
+ * carry a `CertEnroll` server block for client-certificate enrollment - deliberately omitted, same "pragmatic
60
+ * subset" scoping as Phase 2's own documented gaps, since this library has no certificate-enrollment support.
61
+ */
62
+ export function buildPoxSuccessXml({ emailAddress, displayName, easUrl }) {
63
+ const email = escapeXml(emailAddress);
64
+ const url = escapeXml(easUrl);
65
+ const displayNameElement = displayName
66
+ ? `\n <autodiscover:DisplayName>${escapeXml(displayName)}</autodiscover:DisplayName>`
67
+ : "";
68
+ return `<?xml version="1.0" encoding="utf-8"?>
69
+ <Autodiscover xmlns:autodiscover="https://schemas.microsoft.com/exchange/autodiscover/mobilesync/responseschema/2006">
70
+ <autodiscover:Response>
71
+ <autodiscover:Culture>en:us</autodiscover:Culture>
72
+ <autodiscover:User>${displayNameElement}
73
+ <autodiscover:EMailAddress>${email}</autodiscover:EMailAddress>
74
+ </autodiscover:User>
75
+ <autodiscover:Action>
76
+ <autodiscover:Settings>
77
+ <autodiscover:Server>
78
+ <autodiscover:Type>MobileSync</autodiscover:Type>
79
+ <autodiscover:Url>${url}</autodiscover:Url>
80
+ <autodiscover:Name>${url}</autodiscover:Name>
81
+ </autodiscover:Server>
82
+ </autodiscover:Settings>
83
+ </autodiscover:Action>
84
+ </autodiscover:Response>
85
+ </Autodiscover>`;
86
+ }
87
+ /**
88
+ * Builds a real Outlook/EXCH `2006a` response per `[MS-OXDSCLI]`'s confirmed Autodiscover Response XSD -
89
+ * an `Autodiscover`(namespace `.../responseschema/2006`) element wrapping a `Response`
90
+ * (namespace `.../outlook/responseschema/2006a`) with `User`/`Account` children.
91
+ *
92
+ * Since this library only speaks MAPI/HTTP (no classic RPC/TCP MAPI transport), the response always
93
+ * advertises exactly one `Protocol`, using `Type`/`Version` as XML ATTRIBUTES rather than the classic
94
+ * `<Type>EXCH</Type>` child element - `[MS-OXDSCLI]`'s "Processing the X-MapiHttpCapability Header" section
95
+ * confirms a mapiHttp-capable client's response "MUST include a Protocol element that contains a Type
96
+ * attribute set to 'mapiHttp' and a Version attribute" and "MUST NOT include a Protocol element that contains
97
+ * a Type element set to 'EXCH' or 'EXPR'" - the two forms are mutually exclusive by design, not merely
98
+ * alternatives. This deployment has no classic RPC/TCP MAPI endpoint to fall back to, so every Outlook-schema
99
+ * request always gets the mapiHttp form - the real `X-MapiHttpCapability` request-header negotiation a full
100
+ * implementation would consult to choose between EXCH/mapiHttp is not implemented, a documented gap.
101
+ * `MailStore.InternalUrl`/`ExternalUrl` are both set to the same `mapiUrl`, since this library serves one URL
102
+ * per deployment with no separate internal/external network split.
103
+ *
104
+ * `LegacyDN`/`DeploymentId` are schema-required fields this library has no real backing value for (no X.500
105
+ * DN resolution, no multi-tenant deployment identity) - both are synthesized placeholders. Real Outlook does
106
+ * not validate their exact content for MAPI/HTTP connectivity; they matter for classic RPC/TCP MAPI
107
+ * free-busy/permissions lookups this library doesn't implement anyway.
108
+ */
109
+ export function buildOutlookSuccessXml({ emailAddress, displayName, mapiUrl }) {
110
+ const email = escapeXml(emailAddress);
111
+ const url = escapeXml(mapiUrl);
112
+ const name = escapeXml(displayName ?? emailAddress);
113
+ const legacyDn = escapeXml(`/o=ExchangeLabs/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Recipients/cn=${emailAddress}`);
114
+ return `<?xml version="1.0" encoding="utf-8"?>
115
+ <Autodiscover xmlns="http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006">
116
+ <Response xmlns="${OUTLOOK_RESPONSE_SCHEMA}">
117
+ <User>
118
+ <DisplayName>${name}</DisplayName>
119
+ <LegacyDN>${legacyDn}</LegacyDN>
120
+ <AutoDiscoverSMTPAddress>${email}</AutoDiscoverSMTPAddress>
121
+ <DeploymentId>00000000-0000-0000-0000-000000000000</DeploymentId>
122
+ </User>
123
+ <Account>
124
+ <AccountType>email</AccountType>
125
+ <Action>settings</Action>
126
+ <MicrosoftOnline>False</MicrosoftOnline>
127
+ <Protocol Type="mapiHttp" Version="1">
128
+ <MailStore>
129
+ <InternalUrl>${url}</InternalUrl>
130
+ <ExternalUrl>${url}</ExternalUrl>
131
+ </MailStore>
132
+ </Protocol>
133
+ </Account>
134
+ </Response>
135
+ </Autodiscover>`;
136
+ }
137
+ //# sourceMappingURL=AutodiscoverXml.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AutodiscoverXml.js","sourceRoot":"","sources":["../../src/AutodiscoverXml.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,mEAAmE;AACnE,mCAAmC;AACnC,+EAA+E;AAE/E;;;;;;;;GAQG;AAEH,MAAM,qBAAqB,GAAG,gEAAgE,CAAC;AAE/F;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,GAAW;IAC3C,MAAM,KAAK,GAAG,qBAAqB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC9C,MAAM,KAAK,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC;IACjC,OAAO,KAAK,CAAC,CAAC,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACxD,CAAC;AAED,iGAAiG;AACjG,MAAM,UAAU,SAAS,CAAC,KAAa;IACnC,OAAO,KAAK;SACP,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC;SACtB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC;SACvB,OAAO,C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AY,CAAC,CAAC;IACtC,MAAM,GAAG,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;IAC/B,MAAM,IAAI,GAAG,SAAS,CAAC,WAAW,IAAI,YAAY,CAAC,CAAC;IACpD,MAAM,QAAQ,GAAG,SAAS,CACtB,uFAAuF,YAAY,EAAE,CACxG,CAAC;IACF,OAAO;;uBAEY,uBAAuB;;2BAEnB,IAAI;wBACP,QAAQ;uCACO,KAAK;;;;;;;;;mCAST,GAAG;mCACH,GAAG;;;;;gBAKtB,CAAC;AACjB,CAAC"}
@@ -0,0 +1,185 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
11
+ return function (target, key) { decorator(target, key, paramIndex); }
12
+ };
13
+ ///////////////////////////////////////////////////////////////////////////////
14
+ // Copyright (C) 2026 Jean-Philippe Steinmetz. All rights reserved.
15
+ // SPDX-License-Identifier: MPL-2.0
16
+ ///////////////////////////////////////////////////////////////////////////////
17
+ import { ObjectDecorators } from "@rapidrest/core";
18
+ import { RepoUtils, RouteDecorators } from "@rapidrest/service-core";
19
+ import { buildOutlookSuccessXml, buildPoxSuccessXml, extractAcceptableResponseSchema, extractEmailAddress, OUTLOOK_RESPONSE_SCHEMA, } from "./AutodiscoverXml.js";
20
+ const { Init, Logger } = ObjectDecorators;
21
+ const { Get, Param, Post, Query, Request, Response } = RouteDecorators;
22
+ /**
23
+ * Abstract base for the two Autodiscover endpoints a real mail client uses to find this deployment's EAS
24
+ * server URL from just an email address - classic POX (`POST /autodiscover/autodiscover.xml`, per
25
+ * `[MS-ASCMD]`'s "MobileSync" response schema) and the modern JSON variant Microsoft calls "Autodiscover v2"
26
+ * (`GET /autodiscover/autodiscover.json/v1.0/<email>?Protocol=ActiveSync`). Like `BaseMailIngestRoute`/
27
+ * `BaseEasRoute`, this class is undecorated - the consuming application mounts it:
28
+ * ```ts
29
+ * import { AutodiscoverRouteMongo } from "@rapidrest/mail/mongo";
30
+ * import { RouteDecorators } from "@rapidrest/service-core";
31
+ * const { Route } = RouteDecorators;
32
+ *
33
+ * @Route("/autodiscover")
34
+ * export class MyAutodiscoverRoute extends AutodiscoverRouteMongo {
35
+ * protected readonly easUrl = "https://mail.example.com/Microsoft-Server-ActiveSync";
36
+ * protected readonly mapiUrl = "https://mail.example.com/mapi/emsmdb";
37
+ * }
38
+ * ```
39
+ * which composes with this class's own relative method paths to land exactly on the real spec's conventional
40
+ * paths (`/autodiscover/autodiscover.xml`, `/autodiscover/autodiscover.json/v1.0/:email`).
41
+ *
42
+ * **Auth: deliberately none.** Real classic Autodiscover conventionally expects the client to send HTTP Basic
43
+ * credentials (email+password), with the server free to answer `401` and force re-entry - a model this
44
+ * library's JWT-only, no-credential-verification-of-our-own boundary (see `BaseEasRoute`'s own doc comment on
45
+ * why per-request Basic Auth was rejected there) can't and shouldn't absorb; no credential-verification
46
+ * function exists in this codebase or its dependencies. Instead, both endpoints here follow Microsoft's own
47
+ * Autodiscover v2 design intent exactly: answer anonymously, and reveal nothing but a deployment-wide,
48
+ * config-supplied EAS server URL - not a per-mailbox secret - once the request email is confirmed to belong to
49
+ * a real `Mailbox` in this deployment. The actual security boundary is unchanged from Phase 2: real mailbox
50
+ * access still requires a JWT at `BaseEasRoute`, exactly as today.
51
+ *
52
+ * **Known gap, deliberately out of scope**: `Action.Redirect` (for multi-tenant hosted providers whose mailbox
53
+ * moved to a different domain) is not implemented - this library serves exactly one EAS URL for its whole
54
+ * deployment, so there's never a different domain to redirect to. The client-side well-known-URL discovery
55
+ * sequence (`MS-OXDISCO`: root domain -> `autodiscover.` subdomain -> unauthenticated HTTP redirect probe ->
56
+ * DNS SRV record -> cache) and the DNS `CNAME`/`SRV` record setup it depends on are also out of scope here -
57
+ * both are client/deployment concerns, not application code; this class only needs to answer correctly once a
58
+ * request actually arrives at one of its two paths.
59
+ *
60
+ * `mailboxClass` is supplied by the Mongo/SQL concrete subclasses following the exact one-line-per-backend
61
+ * pattern used throughout this library. `easUrl`/`mapiUrl` remain abstract even after that - both are
62
+ * deployment-specific values only the consuming application's own subclass can supply.
63
+ *
64
+ * @author Jean-Philippe Steinmetz
65
+ */
66
+ export class BaseAutodiscoverRoute {
67
+ /**
68
+ * Builds the query value used to match `Mailbox.aliasAddresses` against the given address. See
69
+ * `BaseMailIngestRoute.aliasQueryValue()`'s identical doc comment - same Mongo-array vs.
70
+ * SQL-`simple-json`-column backend split, same override point (`AutodiscoverRouteSQL` overrides this
71
+ * identically to `MailIngestRouteSQL`).
72
+ */
73
+ aliasQueryValue(address) {
74
+ return address;
75
+ }
76
+ async init() {
77
+ this.mailboxRepo = await this._objectFactory.newInstance(RepoUtils, {
78
+ name: this.mailboxClass.name,
79
+ args: [this.mailboxClass],
80
+ });
81
+ }
82
+ async resolveMailbox(email) {
83
+ const address = email.trim().toLowerCase();
84
+ const [byPrimary, byAlias] = await Promise.all([
85
+ this.mailboxRepo.find({ primarySmtpAddress: address }, { ignoreACL: true, limit: 1 }),
86
+ this.mailboxRepo.find({ aliasAddresses: this.aliasQueryValue(address) }, { ignoreACL: true, limit: 1 }),
87
+ ]);
88
+ return byPrimary[0] ?? byAlias[0];
89
+ }
90
+ /**
91
+ * Classic POX Autodiscover. Per Microsoft's own client-behavior documentation, a permanent failure is just
92
+ * as validly conveyed via a plain HTTP status as via an inner `Error` element, so this uses the HTTP-status
93
+ * form for both error cases rather than inventing values for `[MS-ASCMD]`'s provider-specific numeric
94
+ * error-code table.
95
+ *
96
+ * Branches on the request's `AcceptableResponseSchema` to decide which response shape to build: a real
97
+ * Outlook desktop client sends `[MS-OXDSCLI]`'s Outlook/EXCH schema (`OUTLOOK_RESPONSE_SCHEMA`) to locate
98
+ * this deployment's MAPI/HTTP endpoint (`buildOutlookSuccessXml`); any other value (or a mobile/EAS-only
99
+ * client that omits the field entirely) gets the original MobileSync/EAS response (`buildPoxSuccessXml`).
100
+ */
101
+ async pox(req, res) {
102
+ if (!this.mailboxRepo) {
103
+ res.status(500).send();
104
+ return;
105
+ }
106
+ const body = req.rawBody ? req.rawBody.toString("utf-8") : "";
107
+ const email = extractEmailAddress(body);
108
+ if (!email) {
109
+ res.status(400).send();
110
+ return;
111
+ }
112
+ const mailbox = await this.resolveMailbox(email);
113
+ if (!mailbox) {
114
+ res.status(404).send();
115
+ return;
116
+ }
117
+ const xml = extractAcceptableResponseSchema(body) === OUTLOOK_RESPONSE_SCHEMA
118
+ ? buildOutlookSuccessXml({
119
+ emailAddress: email,
120
+ displayName: mailbox.displayName,
121
+ mapiUrl: this.mapiUrl,
122
+ })
123
+ : buildPoxSuccessXml({
124
+ emailAddress: email,
125
+ displayName: mailbox.displayName,
126
+ easUrl: this.easUrl,
127
+ });
128
+ res.setHeader("Content-Type", "application/xml; charset=utf-8").status(200).send(xml);
129
+ }
130
+ /**
131
+ * Autodiscover v2 (JSON). Only the `ActiveSync` protocol is served - this library has no EWS/other
132
+ * protocol surface to advertise - so any other `Protocol` value is rejected outright rather than silently
133
+ * answered with an EAS URL under the wrong protocol name.
134
+ */
135
+ async v2(email, protocol, res) {
136
+ if (!this.mailboxRepo) {
137
+ res.status(500).send();
138
+ return;
139
+ }
140
+ if (protocol !== "ActiveSync") {
141
+ res.status(400).json({
142
+ ErrorCode: "ProtocolNotSupported",
143
+ ErrorMessage: `Unsupported protocol: ${protocol ?? ""}`,
144
+ });
145
+ return;
146
+ }
147
+ const mailbox = await this.resolveMailbox(decodeURIComponent(email));
148
+ if (!mailbox) {
149
+ res.status(404).json({
150
+ ErrorCode: "UserNotFound",
151
+ ErrorMessage: "No mailbox exists for the given address.",
152
+ });
153
+ return;
154
+ }
155
+ res.status(200).json({ Protocol: "ActiveSync", Url: this.easUrl });
156
+ }
157
+ }
158
+ __decorate([
159
+ Logger,
160
+ __metadata("design:type", Object)
161
+ ], BaseAutodiscoverRoute.prototype, "logger", void 0);
162
+ __decorate([
163
+ Init,
164
+ __metadata("design:type", Function),
165
+ __metadata("design:paramtypes", []),
166
+ __metadata("design:returntype", Promise)
167
+ ], BaseAutodiscoverRoute.prototype, "init", null);
168
+ __decorate([
169
+ Post("/autodiscover.xml"),
170
+ __param(0, Request),
171
+ __param(1, Response),
172
+ __metadata("design:type", Function),
173
+ __metadata("design:paramtypes", [Object, Object]),
174
+ __metadata("design:returntype", Promise)
175
+ ], BaseAutodiscoverRoute.prototype, "pox", null);
176
+ __decorate([
177
+ Get("/autodiscover.json/v1.0/:email"),
178
+ __param(0, Param("email")),
179
+ __param(1, Query("Protocol")),
180
+ __param(2, Response),
181
+ __metadata("design:type", Function),
182
+ __metadata("design:paramtypes", [String, Object, Object]),
183
+ __metadata("design:returntype", Promise)
184
+ ], BaseAutodiscoverRoute.prototype, "v2", null);
185
+ //# sourceMappingURL=BaseAutodiscoverRoute.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BaseAutodiscoverRoute.js","sourceRoot":"","sources":["../../src/BaseAutodiscoverRoute.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+EAA+E;AAC/E,mEAAmE;AACnE,mCAAmC;AACnC,+EAA+E;AAC/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAA4C,SAAS,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/G,OAAO,EACH,sBAAsB,EACtB,kBAAkB,EAClB,+BAA+B,EAC/B,mBAAmB,EACn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////////////
2
+ // Copyright (C) 2026 Jean-Philippe Steinmetz. All rights reserved.
3
+ // SPDX-License-Identifier: MPL-2.0
4
+ ///////////////////////////////////////////////////////////////////////////////
5
+ /**
6
+ * Autodiscover protocol compatibility: the mechanism a real mail client uses to find this deployment's EAS
7
+ * server URL from just an email address, before it has any credentials or JWT of its own. Exports the
8
+ * backend-agnostic surface - the request/response XML helpers and the abstract route base class. The concrete
9
+ * Mongo/SQL classes a deployment actually instantiates (`AutodiscoverRouteMongo`/`AutodiscoverRouteSQL`) are
10
+ * exported from this package's `./mongo`/`./sql` subpaths instead, alongside every other entity/route/job this
11
+ * library defines - see `src/eas/index.ts`'s identical doc comment for the same convention.
12
+ *
13
+ * A deployment mounts Autodiscover with a trivial subclass supplying its own EAS URL:
14
+ * ```ts
15
+ * import { AutodiscoverRouteMongo } from "@rapidrest/mail/mongo";
16
+ * import { RouteDecorators } from "@rapidrest/service-core";
17
+ * const { Route } = RouteDecorators;
18
+ *
19
+ * @Route("/autodiscover")
20
+ * export class MyAutodiscoverRoute extends AutodiscoverRouteMongo {
21
+ * protected readonly easUrl = "https://mail.example.com/Microsoft-Server-ActiveSync";
22
+ * protected readonly mapiUrl = "https://mail.example.com/mapi/emsmdb";
23
+ * }
24
+ * ```
25
+ */
26
+ export * from "./AutodiscoverXml.js";
27
+ export * from "./BaseAutodiscoverRoute.js";
28
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,mEAAmE;AACnE,mCAAmC;AACnC,+EAA+E;AAE/E;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,cAAc,sBAAsB,CAAC;AACrC,cAAc,4BAA4B,CAAC"}
@@ -0,0 +1,20 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2026 Jean-Philippe Steinmetz. All rights reserved.
3
+ // SPDX-License-Identifier: MPL-2.0
4
+ ///////////////////////////////////////////////////////////////////////////////
5
+ import { MailboxMongo } from "@rapidmx/restapi/mongo";
6
+ import { BaseAutodiscoverRoute } from "../BaseAutodiscoverRoute.js";
7
+ /**
8
+ * Mongo-backed concrete `BaseAutodiscoverRoute`. `easUrl` remains abstract - the deployment's own
9
+ * `@Route("/autodiscover")` subclass supplies it. See `EasRouteMongo.ts`'s doc comment for the identical
10
+ * mounting pattern.
11
+ *
12
+ * @author Jean-Philippe Steinmetz
13
+ */
14
+ export class AutodiscoverRouteMongo extends BaseAutodiscoverRoute {
15
+ constructor() {
16
+ super(...arguments);
17
+ this.mailboxClass = MailboxMongo;
18
+ }
19
+ }
20
+ //# sourceMappingURL=AutodiscoverRouteMongo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AutodiscoverRouteMongo.js","sourceRoot":"","sources":["../../../src/mongo/AutodiscoverRouteMongo.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,mEAAmE;AACnE,mCAAmC;AACnC,+EAA+E;AAC/E,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAEpE;;;;;;GAMG;AACH,MAAM,OAAgB,sBAAuB,SAAQ,qBAAmC;IAAxF;;QACc,iBAAY,GAAQ,YAAY,CAAC;IAC/C,CAAC;CAAA"}
@@ -0,0 +1,6 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2026 Jean-Philippe Steinmetz. All rights reserved.
3
+ // SPDX-License-Identifier: MPL-2.0
4
+ ///////////////////////////////////////////////////////////////////////////////
5
+ export * from "./AutodiscoverRouteMongo.js";
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/mongo/index.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,mEAAmE;AACnE,mCAAmC;AACnC,+EAA+E;AAC/E,cAAc,6BAA6B,CAAC"}
@@ -0,0 +1,6 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2026 Jean-Philippe Steinmetz. All rights reserved.
3
+ // SPDX-License-Identifier: MPL-2.0
4
+ ///////////////////////////////////////////////////////////////////////////////
5
+ export * from "./mongo/index.js";
6
+ //# sourceMappingURL=mongo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongo.js","sourceRoot":"","sources":["../../src/mongo.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,mEAAmE;AACnE,mCAAmC;AACnC,+EAA+E;AAC/E,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,27 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2026 Jean-Philippe Steinmetz. All rights reserved.
3
+ // SPDX-License-Identifier: MPL-2.0
4
+ ///////////////////////////////////////////////////////////////////////////////
5
+ import { Raw } from "typeorm";
6
+ import { MailboxSQL } from "@rapidmx/restapi/sql";
7
+ import { BaseAutodiscoverRoute } from "../BaseAutodiscoverRoute.js";
8
+ /**
9
+ * SQL-backed concrete `BaseAutodiscoverRoute`. See `AutodiscoverRouteMongo.ts`'s doc comment - the same
10
+ * mounting pattern applies here. `aliasQueryValue()` is overridden identically to `MailIngestRouteSQL` - see
11
+ * that class's doc comment for the full vulnerability rationale (unescaped `%`/`_` enabling alias-enumeration
12
+ * and cross-mailbox matches) this same escaping closes here too, since `resolveMailbox()` is reached by
13
+ * unauthenticated callers exactly like `MailIngestRoute.resolve()` is.
14
+ *
15
+ * @author Jean-Philippe Steinmetz
16
+ */
17
+ export class AutodiscoverRouteSQL extends BaseAutodiscoverRoute {
18
+ constructor() {
19
+ super(...arguments);
20
+ this.mailboxClass = MailboxSQL;
21
+ }
22
+ aliasQueryValue(address) {
23
+ const escaped = address.replace(/[\\%_]/g, (ch) => `\\${ch}`);
24
+ return Raw((alias) => `${alias} LIKE :pattern ESCAPE '\\'`, { pattern: `%"${escaped}"%` });
25
+ }
26
+ }
27
+ //# sourceMappingURL=AutodiscoverRouteSQL.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AutodiscoverRouteSQL.js","sourceRoot":"","sources":["../../../src/sql/AutodiscoverRouteSQL.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,mEAAmE;AACnE,mCAAmC;AACnC,+EAA+E;AAC/E,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAEpE;;;;;;;;GAQG;AACH,MAAM,OAAgB,oBAAqB,SAAQ,qBAAiC;IAApF;;QACc,iBAAY,GAAQ,UAAU,CAAC;IAM7C,CAAC;IAJa,eAAe,CAAC,OAAe;QACrC,MAAM,OAAO,GAAW,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACtE,OAAO,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,KAAK,4BAA4B,EAAE,EAAE,OAAO,EAAE,KAAK,OAAO,IAAI,EAAE,CAAC,CAAC;IAC/F,CAAC;CACJ"}
@@ -0,0 +1,6 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2026 Jean-Philippe Steinmetz. All rights reserved.
3
+ // SPDX-License-Identifier: MPL-2.0
4
+ ///////////////////////////////////////////////////////////////////////////////
5
+ export * from "./AutodiscoverRouteSQL.js";
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/sql/index.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,mEAAmE;AACnE,mCAAmC;AACnC,+EAA+E;AAC/E,cAAc,2BAA2B,CAAC"}
@@ -0,0 +1,6 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2026 Jean-Philippe Steinmetz. All rights reserved.
3
+ // SPDX-License-Identifier: MPL-2.0
4
+ ///////////////////////////////////////////////////////////////////////////////
5
+ export * from "./sql/index.js";
6
+ //# sourceMappingURL=sql.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sql.js","sourceRoot":"","sources":["../../src/sql.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,mEAAmE;AACnE,mCAAmC;AACnC,+EAA+E;AAC/E,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Extracts the request's `<EMailAddress>` text content via a small, tightly-scoped regex rather than a DOM
3
+ * parse. Never resolves entities/DTDs - only the literal text between the open/close tags is ever inspected.
4
+ */
5
+ export declare function extractEmailAddress(xml: string): string | undefined;
6
+ /** Escapes the 5 XML-predefined-entity characters for safe inclusion as element text content. */
7
+ export declare function escapeXml(value: string): string;
8
+ export interface AutodiscoverPoxSuccess {
9
+ emailAddress: string;
10
+ displayName?: string;
11
+ easUrl: string;
12
+ }
13
+ /** The `AcceptableResponseSchema` value a real Outlook desktop client sends to request the Outlook/EXCH
14
+ * response shape (`buildOutlookSuccessXml`) instead of the EAS-only MobileSync one - confirmed against
15
+ * `[MS-OXDSCLI]`'s own Autodiscover Response XSD, whose target namespace is exactly this value. */
16
+ export declare const OUTLOOK_RESPONSE_SCHEMA = "http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a";
17
+ /**
18
+ * Extracts the request's `<AcceptableResponseSchema>` text content via the same small, tightly-scoped regex
19
+ * approach as `extractEmailAddress` - never a DOM parse, same rationale (unauthenticated, internet-facing
20
+ * endpoint).
21
+ */
22
+ export declare function extractAcceptableResponseSchema(xml: string): string | undefined;
23
+ /**
24
+ * Builds a real `mobilesync:Response` success document per `[MS-ASCMD]`'s `AutodiscoverMobileSync.xsd` -
25
+ * `Culture`/`User`/`Action.Settings.Server{Type=MobileSync,Url,Name}`, matching the shape confirmed against
26
+ * Microsoft's own "Autodiscover for Exchange ActiveSync developers" example response. A real response can also
27
+ * carry a `CertEnroll` server block for client-certificate enrollment - deliberately omitted, same "pragmatic
28
+ * subset" scoping as Phase 2's own documented gaps, since this library has no certificate-enrollment support.
29
+ */
30
+ export declare function buildPoxSuccessXml({ emailAddress, displayName, easUrl }: AutodiscoverPoxSuccess): string;
31
+ export interface AutodiscoverOutlookSuccess {
32
+ emailAddress: string;
33
+ displayName?: string;
34
+ mapiUrl: string;
35
+ }
36
+ /**
37
+ * Builds a real Outlook/EXCH `2006a` response per `[MS-OXDSCLI]`'s confirmed Autodiscover Response XSD -
38
+ * an `Autodiscover`(namespace `.../responseschema/2006`) element wrapping a `Response`
39
+ * (namespace `.../outlook/responseschema/2006a`) with `User`/`Account` children.
40
+ *
41
+ * Since this library only speaks MAPI/HTTP (no classic RPC/TCP MAPI transport), the response always
42
+ * advertises exactly one `Protocol`, using `Type`/`Version` as XML ATTRIBUTES rather than the classic
43
+ * `<Type>EXCH</Type>` child element - `[MS-OXDSCLI]`'s "Processing the X-MapiHttpCapability Header" section
44
+ * confirms a mapiHttp-capable client's response "MUST include a Protocol element that contains a Type
45
+ * attribute set to 'mapiHttp' and a Version attribute" and "MUST NOT include a Protocol element that contains
46
+ * a Type element set to 'EXCH' or 'EXPR'" - the two forms are mutually exclusive by design, not merely
47
+ * alternatives. This deployment has no classic RPC/TCP MAPI endpoint to fall back to, so every Outlook-schema
48
+ * request always gets the mapiHttp form - the real `X-MapiHttpCapability` request-header negotiation a full
49
+ * implementation would consult to choose between EXCH/mapiHttp is not implemented, a documented gap.
50
+ * `MailStore.InternalUrl`/`ExternalUrl` are both set to the same `mapiUrl`, since this library serves one URL
51
+ * per deployment with no separate internal/external network split.
52
+ *
53
+ * `LegacyDN`/`DeploymentId` are schema-required fields this library has no real backing value for (no X.500
54
+ * DN resolution, no multi-tenant deployment identity) - both are synthesized placeholders. Real Outlook does
55
+ * not validate their exact content for MAPI/HTTP connectivity; they matter for classic RPC/TCP MAPI
56
+ * free-busy/permissions lookups this library doesn't implement anyway.
57
+ */
58
+ export declare function buildOutlookSuccessXml({ emailAddress, displayName, mapiUrl }: AutodiscoverOutlookSuccess): string;
@@ -0,0 +1,86 @@
1
+ import { HttpRequest, HttpResponse } from "@rapidrest/service-core";
2
+ import { Mailbox } from "@rapidmx/restapi";
3
+ /**
4
+ * Abstract base for the two Autodiscover endpoints a real mail client uses to find this deployment's EAS
5
+ * server URL from just an email address - classic POX (`POST /autodiscover/autodiscover.xml`, per
6
+ * `[MS-ASCMD]`'s "MobileSync" response schema) and the modern JSON variant Microsoft calls "Autodiscover v2"
7
+ * (`GET /autodiscover/autodiscover.json/v1.0/<email>?Protocol=ActiveSync`). Like `BaseMailIngestRoute`/
8
+ * `BaseEasRoute`, this class is undecorated - the consuming application mounts it:
9
+ * ```ts
10
+ * import { AutodiscoverRouteMongo } from "@rapidrest/mail/mongo";
11
+ * import { RouteDecorators } from "@rapidrest/service-core";
12
+ * const { Route } = RouteDecorators;
13
+ *
14
+ * @Route("/autodiscover")
15
+ * export class MyAutodiscoverRoute extends AutodiscoverRouteMongo {
16
+ * protected readonly easUrl = "https://mail.example.com/Microsoft-Server-ActiveSync";
17
+ * protected readonly mapiUrl = "https://mail.example.com/mapi/emsmdb";
18
+ * }
19
+ * ```
20
+ * which composes with this class's own relative method paths to land exactly on the real spec's conventional
21
+ * paths (`/autodiscover/autodiscover.xml`, `/autodiscover/autodiscover.json/v1.0/:email`).
22
+ *
23
+ * **Auth: deliberately none.** Real classic Autodiscover conventionally expects the client to send HTTP Basic
24
+ * credentials (email+password), with the server free to answer `401` and force re-entry - a model this
25
+ * library's JWT-only, no-credential-verification-of-our-own boundary (see `BaseEasRoute`'s own doc comment on
26
+ * why per-request Basic Auth was rejected there) can't and shouldn't absorb; no credential-verification
27
+ * function exists in this codebase or its dependencies. Instead, both endpoints here follow Microsoft's own
28
+ * Autodiscover v2 design intent exactly: answer anonymously, and reveal nothing but a deployment-wide,
29
+ * config-supplied EAS server URL - not a per-mailbox secret - once the request email is confirmed to belong to
30
+ * a real `Mailbox` in this deployment. The actual security boundary is unchanged from Phase 2: real mailbox
31
+ * access still requires a JWT at `BaseEasRoute`, exactly as today.
32
+ *
33
+ * **Known gap, deliberately out of scope**: `Action.Redirect` (for multi-tenant hosted providers whose mailbox
34
+ * moved to a different domain) is not implemented - this library serves exactly one EAS URL for its whole
35
+ * deployment, so there's never a different domain to redirect to. The client-side well-known-URL discovery
36
+ * sequence (`MS-OXDISCO`: root domain -> `autodiscover.` subdomain -> unauthenticated HTTP redirect probe ->
37
+ * DNS SRV record -> cache) and the DNS `CNAME`/`SRV` record setup it depends on are also out of scope here -
38
+ * both are client/deployment concerns, not application code; this class only needs to answer correctly once a
39
+ * request actually arrives at one of its two paths.
40
+ *
41
+ * `mailboxClass` is supplied by the Mongo/SQL concrete subclasses following the exact one-line-per-backend
42
+ * pattern used throughout this library. `easUrl`/`mapiUrl` remain abstract even after that - both are
43
+ * deployment-specific values only the consuming application's own subclass can supply.
44
+ *
45
+ * @author Jean-Philippe Steinmetz
46
+ */
47
+ export declare abstract class BaseAutodiscoverRoute<M extends Mailbox> {
48
+ protected abstract mailboxClass: any;
49
+ /** The EAS endpoint URL to report - e.g. `https://mail.example.com/Microsoft-Server-ActiveSync`, matching
50
+ * whatever `@Route(...)` path the deployment mounted its `BaseEasRoute` subclass at. */
51
+ protected abstract readonly easUrl: string;
52
+ /** The MAPI/HTTP `emsmdb` endpoint URL to report to a real Outlook desktop client - e.g.
53
+ * `https://mail.example.com/mapi/emsmdb`, matching whatever `@Route(...)` path the deployment mounted its
54
+ * `BaseMapiEmsmdbRoute` subclass at. Only used by `pox()`'s Outlook/EXCH response branch. */
55
+ protected abstract readonly mapiUrl: string;
56
+ private _objectFactory?;
57
+ private mailboxRepo?;
58
+ private logger;
59
+ /**
60
+ * Builds the query value used to match `Mailbox.aliasAddresses` against the given address. See
61
+ * `BaseMailIngestRoute.aliasQueryValue()`'s identical doc comment - same Mongo-array vs.
62
+ * SQL-`simple-json`-column backend split, same override point (`AutodiscoverRouteSQL` overrides this
63
+ * identically to `MailIngestRouteSQL`).
64
+ */
65
+ protected aliasQueryValue(address: string): any;
66
+ init(): Promise<void>;
67
+ private resolveMailbox;
68
+ /**
69
+ * Classic POX Autodiscover. Per Microsoft's own client-behavior documentation, a permanent failure is just
70
+ * as validly conveyed via a plain HTTP status as via an inner `Error` element, so this uses the HTTP-status
71
+ * form for both error cases rather than inventing values for `[MS-ASCMD]`'s provider-specific numeric
72
+ * error-code table.
73
+ *
74
+ * Branches on the request's `AcceptableResponseSchema` to decide which response shape to build: a real
75
+ * Outlook desktop client sends `[MS-OXDSCLI]`'s Outlook/EXCH schema (`OUTLOOK_RESPONSE_SCHEMA`) to locate
76
+ * this deployment's MAPI/HTTP endpoint (`buildOutlookSuccessXml`); any other value (or a mobile/EAS-only
77
+ * client that omits the field entirely) gets the original MobileSync/EAS response (`buildPoxSuccessXml`).
78
+ */
79
+ pox(req: HttpRequest, res: HttpResponse): Promise<void>;
80
+ /**
81
+ * Autodiscover v2 (JSON). Only the `ActiveSync` protocol is served - this library has no EWS/other
82
+ * protocol surface to advertise - so any other `Protocol` value is rejected outright rather than silently
83
+ * answered with an EAS URL under the wrong protocol name.
84
+ */
85
+ v2(email: string, protocol: string | undefined, res: HttpResponse): Promise<void>;
86
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Autodiscover protocol compatibility: the mechanism a real mail client uses to find this deployment's EAS
3
+ * server URL from just an email address, before it has any credentials or JWT of its own. Exports the
4
+ * backend-agnostic surface - the request/response XML helpers and the abstract route base class. The concrete
5
+ * Mongo/SQL classes a deployment actually instantiates (`AutodiscoverRouteMongo`/`AutodiscoverRouteSQL`) are
6
+ * exported from this package's `./mongo`/`./sql` subpaths instead, alongside every other entity/route/job this
7
+ * library defines - see `src/eas/index.ts`'s identical doc comment for the same convention.
8
+ *
9
+ * A deployment mounts Autodiscover with a trivial subclass supplying its own EAS URL:
10
+ * ```ts
11
+ * import { AutodiscoverRouteMongo } from "@rapidrest/mail/mongo";
12
+ * import { RouteDecorators } from "@rapidrest/service-core";
13
+ * const { Route } = RouteDecorators;
14
+ *
15
+ * @Route("/autodiscover")
16
+ * export class MyAutodiscoverRoute extends AutodiscoverRouteMongo {
17
+ * protected readonly easUrl = "https://mail.example.com/Microsoft-Server-ActiveSync";
18
+ * protected readonly mapiUrl = "https://mail.example.com/mapi/emsmdb";
19
+ * }
20
+ * ```
21
+ */
22
+ export * from "./AutodiscoverXml.js";
23
+ export * from "./BaseAutodiscoverRoute.js";
@@ -0,0 +1,12 @@
1
+ import { MailboxMongo } from "@rapidmx/restapi/mongo";
2
+ import { BaseAutodiscoverRoute } from "../BaseAutodiscoverRoute.js";
3
+ /**
4
+ * Mongo-backed concrete `BaseAutodiscoverRoute`. `easUrl` remains abstract - the deployment's own
5
+ * `@Route("/autodiscover")` subclass supplies it. See `EasRouteMongo.ts`'s doc comment for the identical
6
+ * mounting pattern.
7
+ *
8
+ * @author Jean-Philippe Steinmetz
9
+ */
10
+ export declare abstract class AutodiscoverRouteMongo extends BaseAutodiscoverRoute<MailboxMongo> {
11
+ protected mailboxClass: any;
12
+ }
@@ -0,0 +1 @@
1
+ export * from "./AutodiscoverRouteMongo.js";
@@ -0,0 +1 @@
1
+ export * from "./mongo/index.js";
@@ -0,0 +1,15 @@
1
+ import { MailboxSQL } from "@rapidmx/restapi/sql";
2
+ import { BaseAutodiscoverRoute } from "../BaseAutodiscoverRoute.js";
3
+ /**
4
+ * SQL-backed concrete `BaseAutodiscoverRoute`. See `AutodiscoverRouteMongo.ts`'s doc comment - the same
5
+ * mounting pattern applies here. `aliasQueryValue()` is overridden identically to `MailIngestRouteSQL` - see
6
+ * that class's doc comment for the full vulnerability rationale (unescaped `%`/`_` enabling alias-enumeration
7
+ * and cross-mailbox matches) this same escaping closes here too, since `resolveMailbox()` is reached by
8
+ * unauthenticated callers exactly like `MailIngestRoute.resolve()` is.
9
+ *
10
+ * @author Jean-Philippe Steinmetz
11
+ */
12
+ export declare abstract class AutodiscoverRouteSQL extends BaseAutodiscoverRoute<MailboxSQL> {
13
+ protected mailboxClass: any;
14
+ protected aliasQueryValue(address: string): any;
15
+ }
@@ -0,0 +1 @@
1
+ export * from "./AutodiscoverRouteSQL.js";
@@ -0,0 +1 @@
1
+ export * from "./sql/index.js";
package/package.json ADDED
@@ -0,0 +1,90 @@
1
+ {
2
+ "name": "@rapidmx/autodiscover",
3
+ "version": "1.0.0-beta.0",
4
+ "description": "Autodiscover protocol support for RapidREST mail servers.",
5
+ "repository": "https://github.com/RapidMX/autodiscover.git",
6
+ "author": "RapidREST <rapidrests@gmail.com>",
7
+ "license": "MPL-2.0",
8
+ "contributors": [
9
+ "Jean-Philippe Steinmetz"
10
+ ],
11
+ "scripts": {
12
+ "build": "yarn lint && rimraf dist && tsc",
13
+ "lint": "eslint ./src ./test",
14
+ "local-audit": "yarn install && yarn npm audit -A -R \"$@\"",
15
+ "checkup": "yarn dlx @yarnpkg/doctor \"$@\"",
16
+ "dependency-check": "yarn dlx depcheck \"$@\"",
17
+ "report-coverage": "cat ./coverage/lcov.info | coveralls",
18
+ "test": "vitest run",
19
+ "test:prod": "npm run lint && vitest run --coverage",
20
+ "test:watch": "vitest",
21
+ "release": "rapidrest release"
22
+ },
23
+ "peerDependencies": {
24
+ "@rapidmx/restapi": "0.1.x",
25
+ "@rapidrest/core": "5.x",
26
+ "@rapidrest/service-core": "1.x"
27
+ },
28
+ "devDependencies": {
29
+ "@rapidmx/restapi": "^0.2.0",
30
+ "@rapidrest/cli": "^1.0.1",
31
+ "@rapidrest/core": "^5.2.2",
32
+ "@rapidrest/service-core": "^1.7.2",
33
+ "@swc/core": "^1.16.2",
34
+ "@types/nconf": "^0.10.7",
35
+ "@types/node": "^26.5.0",
36
+ "@typescript-eslint/eslint-plugin": "^8.70.0",
37
+ "@typescript-eslint/parser": "^8.70.0",
38
+ "@vitest/coverage-v8": "^5.0.0",
39
+ "better-sqlite3": "^13.0.3",
40
+ "eslint": "^10.10.0",
41
+ "eslint-config-prettier": "^10.1.8",
42
+ "eslint-plugin-import": "^2.32.0",
43
+ "eslint-plugin-jsdoc": "^64.3.6",
44
+ "globals": "^17.12.0",
45
+ "lodash-es": "^4.18.1",
46
+ "mongodb": "^7.6.0",
47
+ "mongodb-memory-server": "^11.2.0",
48
+ "nconf": "^0.13.0",
49
+ "openapi3-ts": "^4.6.1",
50
+ "prom-client": "^15.1.3",
51
+ "redis": "^6.2.1",
52
+ "reflect-metadata": "^0.2.2",
53
+ "rimraf": "^6.1.3",
54
+ "ts-node": "^10.9.2",
55
+ "tsx": "^4.23.13",
56
+ "typeorm": "^1.1.1",
57
+ "typescript": "^6.0.3",
58
+ "unplugin-swc": "^1.6.0",
59
+ "vite": "^8.2.2",
60
+ "vitest": "^5.0.0",
61
+ "winston": "^3.19.0"
62
+ },
63
+ "packageManager": "yarn@4.5.3",
64
+ "engines": {
65
+ "node": ">=24.0.0"
66
+ },
67
+ "publishConfig": {
68
+ "registry": "https://registry.npmjs.org/"
69
+ },
70
+ "type": "module",
71
+ "main": "dist/lib/index.js",
72
+ "exports": {
73
+ ".": {
74
+ "import": "./dist/lib/index.js",
75
+ "types": "./dist/types/index.d.ts"
76
+ },
77
+ "./mongo": {
78
+ "import": "./dist/lib/mongo.js",
79
+ "types": "./dist/types/mongo.d.ts"
80
+ },
81
+ "./sql": {
82
+ "import": "./dist/lib/sql.js",
83
+ "types": "./dist/types/sql.d.ts"
84
+ }
85
+ },
86
+ "typings": "dist/types/index.d.ts",
87
+ "files": [
88
+ "dist"
89
+ ]
90
+ }