@remit/backend 0.0.84 → 0.0.86
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/package.json
CHANGED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { afterEach, describe, it } from "node:test";
|
|
3
|
+
import { getMsOAuthConfig } from "./msoauth.js";
|
|
4
|
+
|
|
5
|
+
const MSOAUTH_KEYS = [
|
|
6
|
+
"MSOAUTH_AUTHORITY",
|
|
7
|
+
"MSOAUTH_REDIRECT_URI",
|
|
8
|
+
"MSOAUTH_SECRET_ARN",
|
|
9
|
+
"MSOAUTH_CLIENT_ID",
|
|
10
|
+
"MSOAUTH_CLIENT_SECRET",
|
|
11
|
+
"MSOAUTH_TOKEN_ENDPOINT",
|
|
12
|
+
] as const;
|
|
13
|
+
|
|
14
|
+
describe("getMsOAuthConfig", () => {
|
|
15
|
+
const original = new Map(
|
|
16
|
+
MSOAUTH_KEYS.map((key) => [key, process.env[key]] as const),
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
afterEach(() => {
|
|
20
|
+
for (const [key, value] of original) {
|
|
21
|
+
if (value === undefined) delete process.env[key];
|
|
22
|
+
else process.env[key] = value;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("resolves on a self-host deployment, where no authority is wired", () => {
|
|
27
|
+
for (const key of MSOAUTH_KEYS) delete process.env[key];
|
|
28
|
+
process.env.MSOAUTH_REDIRECT_URI =
|
|
29
|
+
"https://mail.example.com/api/accounts/oauth/microsoft/callback";
|
|
30
|
+
process.env.MSOAUTH_CLIENT_ID = "client-id";
|
|
31
|
+
process.env.MSOAUTH_CLIENT_SECRET = "client-secret";
|
|
32
|
+
|
|
33
|
+
assert.deepEqual(getMsOAuthConfig(), {
|
|
34
|
+
secretArn: undefined,
|
|
35
|
+
redirectUri:
|
|
36
|
+
"https://mail.example.com/api/accounts/oauth/microsoft/callback",
|
|
37
|
+
clientId: "client-id",
|
|
38
|
+
clientSecret: "client-secret",
|
|
39
|
+
tokenEndpoint: undefined,
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("names PUBLIC_ORIGIN when the redirect URI is missing", () => {
|
|
44
|
+
for (const key of MSOAUTH_KEYS) delete process.env[key];
|
|
45
|
+
|
|
46
|
+
assert.throws(getMsOAuthConfig, /MSOAUTH_REDIRECT_URI.*PUBLIC_ORIGIN/s);
|
|
47
|
+
});
|
|
48
|
+
});
|
package/src/config/msoauth.ts
CHANGED
|
@@ -1,28 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Typed reads for Microsoft OAuth (Entra) environment variables.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* - `MSOAUTH_AUTHORITY` — OIDC authority base URL (baked in at deploy time).
|
|
8
|
-
* - `MSOAUTH_REDIRECT_URI`— OAuth callback URI (baked in at deploy time).
|
|
4
|
+
* `MSOAUTH_REDIRECT_URI` is derived from `PUBLIC_ORIGIN` by the compose file
|
|
5
|
+
* (deploy/vps/docker-compose.sqlite.yml) and must match the redirect URI
|
|
6
|
+
* registered on the Entra app registration.
|
|
9
7
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
8
|
+
* Credentials come either from `MSOAUTH_CLIENT_ID` / `MSOAUTH_CLIENT_SECRET`
|
|
9
|
+
* in the deploy env file, or from Secrets Manager via `MSOAUTH_SECRET_ARN`.
|
|
12
10
|
*
|
|
13
|
-
*
|
|
11
|
+
* The Microsoft authorization and token endpoints are fixed in
|
|
12
|
+
* `@remit/mail-oauth-service`; no authority URL is read from the environment.
|
|
14
13
|
*/
|
|
15
14
|
|
|
16
15
|
export interface MsOAuthConfig {
|
|
17
|
-
/** Secrets Manager ARN —
|
|
16
|
+
/** Secrets Manager ARN — an alternative to the client id/secret pair. */
|
|
18
17
|
readonly secretArn: string | undefined;
|
|
19
|
-
/** OIDC authority, e.g. `https://login.microsoftonline.com/common`. */
|
|
20
|
-
readonly authority: string;
|
|
21
18
|
/** OAuth redirect URI registered in the Entra app. */
|
|
22
19
|
readonly redirectUri: string;
|
|
23
|
-
/** Client ID —
|
|
20
|
+
/** Client ID — set directly to bypass Secrets Manager. */
|
|
24
21
|
readonly clientId: string | undefined;
|
|
25
|
-
/** Client secret —
|
|
22
|
+
/** Client secret — set directly to bypass Secrets Manager. */
|
|
26
23
|
readonly clientSecret: string | undefined;
|
|
27
24
|
/** Token endpoint override — used for local stubbing (bypasses default OIDC discovery). */
|
|
28
25
|
readonly tokenEndpoint: string | undefined;
|
|
@@ -30,28 +27,19 @@ export interface MsOAuthConfig {
|
|
|
30
27
|
|
|
31
28
|
/**
|
|
32
29
|
* Read Microsoft OAuth configuration from the environment.
|
|
33
|
-
* Throws when
|
|
34
|
-
* are absent — both are always present in deployed Lambdas and should be set
|
|
35
|
-
* in `localhost-dev-aws.env` for local development.
|
|
30
|
+
* Throws when `MSOAUTH_REDIRECT_URI` is absent.
|
|
36
31
|
*/
|
|
37
32
|
export const getMsOAuthConfig = (): MsOAuthConfig => {
|
|
38
|
-
const authority = process.env.MSOAUTH_AUTHORITY;
|
|
39
33
|
const redirectUri = process.env.MSOAUTH_REDIRECT_URI;
|
|
40
34
|
|
|
41
|
-
if (!authority) {
|
|
42
|
-
throw new Error(
|
|
43
|
-
"MSOAUTH_AUTHORITY is not set. Wire via CDK (infra/stacks/dev/stacks/remit-api-stack.ts) or set in localhost-dev-aws.env.",
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
35
|
if (!redirectUri) {
|
|
47
36
|
throw new Error(
|
|
48
|
-
"MSOAUTH_REDIRECT_URI is not set.
|
|
37
|
+
"MSOAUTH_REDIRECT_URI is not set. It is derived from PUBLIC_ORIGIN — set PUBLIC_ORIGIN in the deploy env file (deploy/vps/.env) and restart, or set MSOAUTH_REDIRECT_URI directly.",
|
|
49
38
|
);
|
|
50
39
|
}
|
|
51
40
|
|
|
52
41
|
return {
|
|
53
42
|
secretArn: process.env.MSOAUTH_SECRET_ARN,
|
|
54
|
-
authority,
|
|
55
43
|
redirectUri,
|
|
56
44
|
clientId: process.env.MSOAUTH_CLIENT_ID,
|
|
57
45
|
clientSecret: process.env.MSOAUTH_CLIENT_SECRET,
|
|
@@ -330,6 +330,7 @@ export const createRemitClient = (deps: RemitClientDeps): RemitClient => {
|
|
|
330
330
|
threadMessageService: repositories.threadMessage,
|
|
331
331
|
markerService: repositories.placementMove,
|
|
332
332
|
addressService: repositories.address,
|
|
333
|
+
mailboxSpecialUseService: repositories.mailboxSpecialUse,
|
|
333
334
|
sqsQueueUrl: placementMoveQueueUrl,
|
|
334
335
|
})
|
|
335
336
|
: undefined;
|
package/src/service/organize.ts
CHANGED
|
@@ -594,6 +594,7 @@ export const buildOrganizeMoveService = (
|
|
|
594
594
|
threadMessageService: client.threadMessage,
|
|
595
595
|
markerService: client.placementMove,
|
|
596
596
|
addressService: client.address,
|
|
597
|
+
mailboxSpecialUseService: client.mailboxSpecialUse,
|
|
597
598
|
sqsQueueUrl: queueUrl,
|
|
598
599
|
});
|
|
599
600
|
};
|