@jskit-ai/auth-core 0.2.4 → 0.2.6

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/CHANGELOG.md CHANGED
@@ -1,5 +1,68 @@
1
1
  # Changelog
2
2
 
3
+ ## Unreleased
4
+
5
+ - Every auth command's field messages (sign-in, registration, one-time codes, OAuth, password reset and recovery, dev sign-in) are sent in the coded form `{ code, message, params }`, so their field errors translate. The English is unchanged.
6
+ - The default access-denied texts carry the messageCodes `auth.denied.notAllowlistedDefault`, `auth.denied.blockedDefault` and `auth.denied.unspecified`; `./shared/authDenied` adds `AUTH_DENIED_DEFAULT_TEXTS` and `AUTH_DENIED_FALLBACK_TEXT` (`{ message, messageCode }`). `AUTH_DENIED_DEFAULT_MESSAGES` and the English are unchanged.
7
+
8
+ ### New codes (22)
9
+
10
+ <details><summary>Code list</summary>
11
+
12
+ - `auth.dev.userIdInvalid`
13
+ - `auth.dev.userInvalid`
14
+ - `auth.validation.unexpectedField`
15
+ - `auth.validation.emailAddressInvalid`
16
+ - `auth.validation.passwordMinLength`
17
+ - `auth.validation.oauthProviderRequired`
18
+ - `auth.validation.oauthProviderInvalid`
19
+ - `auth.validation.oauthCodeInvalid`
20
+ - `auth.validation.oauthStateInvalid`
21
+ - `auth.validation.oauthIssuerInvalid`
22
+ - `auth.validation.accessTokenInvalid`
23
+ - `auth.validation.refreshTokenInvalid`
24
+ - `auth.validation.returnToInvalid`
25
+ - `auth.validation.otpCodeRequired`
26
+ - `auth.validation.otpTokenHashInvalid`
27
+ - `auth.validation.otpTypeUnsupported`
28
+ - `auth.validation.recoveryCodeInvalid`
29
+ - `auth.validation.recoveryTokenHashInvalid`
30
+ - `auth.validation.recoveryTypeUnsupported`
31
+ - `auth.denied.notAllowlistedDefault`
32
+ - `auth.denied.blockedDefault`
33
+ - `auth.denied.unspecified`
34
+
35
+ </details>
36
+
37
+ ### New message keys (22)
38
+
39
+ <details><summary>Key list</summary>
40
+
41
+ - `jskit.auth.dev.userIdInvalid`
42
+ - `jskit.auth.dev.userInvalid`
43
+ - `jskit.auth.validation.unexpectedField`
44
+ - `jskit.auth.validation.emailAddressInvalid`
45
+ - `jskit.auth.validation.passwordMinLength`
46
+ - `jskit.auth.validation.oauthProviderRequired`
47
+ - `jskit.auth.validation.oauthProviderInvalid`
48
+ - `jskit.auth.validation.oauthCodeInvalid`
49
+ - `jskit.auth.validation.oauthStateInvalid`
50
+ - `jskit.auth.validation.oauthIssuerInvalid`
51
+ - `jskit.auth.validation.accessTokenInvalid`
52
+ - `jskit.auth.validation.refreshTokenInvalid`
53
+ - `jskit.auth.validation.returnToInvalid`
54
+ - `jskit.auth.validation.otpCodeRequired`
55
+ - `jskit.auth.validation.otpTokenHashInvalid`
56
+ - `jskit.auth.validation.otpTypeUnsupported`
57
+ - `jskit.auth.validation.recoveryCodeInvalid`
58
+ - `jskit.auth.validation.recoveryTokenHashInvalid`
59
+ - `jskit.auth.validation.recoveryTypeUnsupported`
60
+ - `jskit.auth.denied.notAllowlistedDefault`
61
+ - `jskit.auth.denied.blockedDefault`
62
+ - `jskit.auth.denied.unspecified`
63
+
64
+ </details>
65
+
3
66
  ## 0.2.0 - 2026-10-29
4
67
 
5
68
  - Translation ready: every user-visible text is a message key with its English in `locales/en.json`, so an app translates it by supplying translation files only. With no translations, texts and behaviour are unchanged. See the guide "Translating a JSKIT app".
package/locales/en.json CHANGED
@@ -19,7 +19,9 @@
19
19
  "localhostOnly": "Dev auth bootstrap is only available from localhost.",
20
20
  "exchangeUnauthorized": "Dev auth exchange is not authorized.",
21
21
  "userRequired": "Provide a user id or email.",
22
- "userNotFound": "User not found."
22
+ "userNotFound": "User not found.",
23
+ "userIdInvalid": "Provide a valid user id.",
24
+ "userInvalid": "Provide a valid user id or email."
23
25
  },
24
26
  "operation": {
25
27
  "unsupported": "Auth operation \"{operation}\" is not supported by the active provider."
@@ -31,7 +33,24 @@
31
33
  "passwordLength": "Password must be between {min} and {max} characters.",
32
34
  "passwordTooLong": "Password must be at most {max} characters.",
33
35
  "confirmPasswordRequired": "Confirm your password.",
34
- "passwordsMismatch": "Passwords do not match."
36
+ "passwordsMismatch": "Passwords do not match.",
37
+ "unexpectedField": "Unexpected field.",
38
+ "emailAddressInvalid": "Enter a valid email address.",
39
+ "passwordMinLength": "Password must be at least {min} characters.",
40
+ "oauthProviderRequired": "OAuth provider is required.",
41
+ "oauthProviderInvalid": "OAuth provider id is invalid.",
42
+ "oauthCodeInvalid": "OAuth code is invalid.",
43
+ "oauthStateInvalid": "OAuth state is invalid.",
44
+ "oauthIssuerInvalid": "OAuth issuer is invalid.",
45
+ "accessTokenInvalid": "Access token is invalid.",
46
+ "refreshTokenInvalid": "Refresh token is invalid.",
47
+ "returnToInvalid": "Return target must be an absolute path or URL.",
48
+ "otpCodeRequired": "One-time code is required.",
49
+ "otpTokenHashInvalid": "One-time token hash is invalid.",
50
+ "otpTypeUnsupported": "Only email OTP verification is supported.",
51
+ "recoveryCodeInvalid": "Recovery code is invalid.",
52
+ "recoveryTokenHashInvalid": "Recovery token hash is invalid.",
53
+ "recoveryTypeUnsupported": "Only recovery links are supported."
35
54
  },
36
55
  "profile": {
37
56
  "displayNameRequired": "Display name is required."
@@ -44,7 +63,10 @@
44
63
  },
45
64
  "denied": {
46
65
  "notAllowlisted": "Sign-in succeeded, but this account is not allowed to access this application.",
47
- "blocked": "Sign-in succeeded, but this account has been blocked from accessing this application."
66
+ "blocked": "Sign-in succeeded, but this account has been blocked from accessing this application.",
67
+ "notAllowlistedDefault": "This account is not allowed to access this application.",
68
+ "blockedDefault": "This account has been blocked from accessing this application.",
69
+ "unspecified": "This account cannot access this application."
48
70
  }
49
71
  }
50
72
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/auth-core",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "node --test --test-concurrency=1"
@@ -143,6 +143,6 @@
143
143
  }
144
144
  },
145
145
  "peerDependencies": {
146
- "@jskit-ai/kernel": "0.2.4"
146
+ "@jskit-ai/kernel": "0.2.6"
147
147
  }
148
148
  }
@@ -7,10 +7,26 @@ const AUTH_DENIED_CODES = Object.freeze({
7
7
  BLOCKED: "blocked"
8
8
  });
9
9
 
10
- const AUTH_DENIED_DEFAULT_MESSAGES = Object.freeze({
11
- [AUTH_DENIED_CODES.NOT_ALLOWLISTED]: "This account is not allowed to access this application.",
12
- [AUTH_DENIED_CODES.BLOCKED]: "This account has been blocked from accessing this application."
10
+ // The denial a built-in reason gets when the app sends no message, and the one
11
+ // any other reason gets: the English and the code a client renders it from.
12
+ const AUTH_DENIED_DEFAULT_TEXTS = Object.freeze({
13
+ [AUTH_DENIED_CODES.NOT_ALLOWLISTED]: Object.freeze({
14
+ message: "This account is not allowed to access this application.",
15
+ messageCode: "auth.denied.notAllowlistedDefault"
16
+ }),
17
+ [AUTH_DENIED_CODES.BLOCKED]: Object.freeze({
18
+ message: "This account has been blocked from accessing this application.",
19
+ messageCode: "auth.denied.blockedDefault"
20
+ })
13
21
  });
22
+ const AUTH_DENIED_FALLBACK_TEXT = Object.freeze({
23
+ message: "This account cannot access this application.",
24
+ messageCode: "auth.denied.unspecified"
25
+ });
26
+
27
+ const AUTH_DENIED_DEFAULT_MESSAGES = Object.freeze(Object.fromEntries(
28
+ Object.entries(AUTH_DENIED_DEFAULT_TEXTS).map(([code, text]) => [code, text.message])
29
+ ));
14
30
 
15
31
  // The sign-in error for each built-in reason: its English and the code a client
16
32
  // renders it from in the user's language.
@@ -50,7 +66,7 @@ function normalizeAuthDenied(input = null) {
50
66
  }
51
67
 
52
68
  const explicitMessage = String(input.message || "").trim();
53
- const message = explicitMessage || AUTH_DENIED_DEFAULT_MESSAGES[code] || "This account cannot access this application.";
69
+ const message = explicitMessage || AUTH_DENIED_DEFAULT_MESSAGES[code] || AUTH_DENIED_FALLBACK_TEXT.message;
54
70
 
55
71
  return Object.freeze({
56
72
  code,
@@ -59,14 +75,18 @@ function normalizeAuthDenied(input = null) {
59
75
  }
60
76
 
61
77
  // { message, messageCode? } for a denied session, or null. A reason the app
62
- // defined itself keeps the message it sent, without a code.
78
+ // defined itself keeps the message it sent, without a code, or the coded fallback
79
+ // when it sent none.
63
80
  function resolveAuthDeniedLoginText(input = null) {
64
81
  const authDenied = normalizeAuthDenied(input);
65
82
  if (!authDenied) {
66
83
  return null;
67
84
  }
68
85
 
69
- return AUTH_DENIED_LOGIN_TEXTS[authDenied.code] || Object.freeze({ message: authDenied.message });
86
+ return AUTH_DENIED_LOGIN_TEXTS[authDenied.code] ||
87
+ (authDenied.message === AUTH_DENIED_FALLBACK_TEXT.message
88
+ ? AUTH_DENIED_FALLBACK_TEXT
89
+ : Object.freeze({ message: authDenied.message }));
70
90
  }
71
91
 
72
92
  function resolveAuthDeniedLoginMessage(input = null) {
@@ -78,6 +98,8 @@ export {
78
98
  AUTH_DENIED_CODE_PATTERN,
79
99
  AUTH_DENIED_CODES,
80
100
  AUTH_DENIED_DEFAULT_MESSAGES,
101
+ AUTH_DENIED_DEFAULT_TEXTS,
102
+ AUTH_DENIED_FALLBACK_TEXT,
81
103
  AUTH_DENIED_LOGIN_MESSAGES,
82
104
  AUTH_DENIED_LOGIN_TEXTS,
83
105
  AUTH_DENIED_MESSAGE_MAX_LENGTH,
@@ -412,19 +412,55 @@ const sessionUnavailableOutputValidator = deepFreeze({
412
412
  mode: "replace"
413
413
  });
414
414
 
415
+ // Each command message: its English and the code a client renders it from in the
416
+ // user's language, the { code, message, params } form of resource field messages.
417
+ const AUTH_FIELD_MESSAGES = deepFreeze({
418
+ validationFailed: { code: "validation_failed", message: "Validation failed." },
419
+ invalidValue: { code: "kernel.validation.invalid", message: "Invalid value." },
420
+ unexpectedField: { code: "auth.validation.unexpectedField", message: "Unexpected field." },
421
+ emailRequired: { code: "auth.validation.emailRequired", message: "Email is required." },
422
+ emailAddressInvalid: { code: "auth.validation.emailAddressInvalid", message: "Enter a valid email address." },
423
+ passwordRequired: { code: "auth.validation.passwordRequired", message: "Password is required." },
424
+ passwordMinLength: {
425
+ code: "auth.validation.passwordMinLength",
426
+ message: `Password must be at least ${AUTH_PASSWORD_MIN_LENGTH} characters.`,
427
+ params: { min: AUTH_PASSWORD_MIN_LENGTH }
428
+ },
429
+ devUserIdInvalid: { code: "auth.dev.userIdInvalid", message: "Provide a valid user id." },
430
+ devUserInvalid: { code: "auth.dev.userInvalid", message: "Provide a valid user id or email." },
431
+ devUserRequired: { code: "auth.dev.userRequired", message: "Provide a user id or email." },
432
+ oauthProviderRequired: { code: "auth.validation.oauthProviderRequired", message: "OAuth provider is required." },
433
+ oauthProviderInvalid: { code: "auth.validation.oauthProviderInvalid", message: "OAuth provider id is invalid." },
434
+ oauthCodeInvalid: { code: "auth.validation.oauthCodeInvalid", message: "OAuth code is invalid." },
435
+ oauthStateInvalid: { code: "auth.validation.oauthStateInvalid", message: "OAuth state is invalid." },
436
+ oauthIssuerInvalid: { code: "auth.validation.oauthIssuerInvalid", message: "OAuth issuer is invalid." },
437
+ accessTokenInvalid: { code: "auth.validation.accessTokenInvalid", message: "Access token is invalid." },
438
+ refreshTokenInvalid: { code: "auth.validation.refreshTokenInvalid", message: "Refresh token is invalid." },
439
+ returnToInvalid: { code: "auth.validation.returnToInvalid", message: "Return target must be an absolute path or URL." },
440
+ otpCodeRequired: { code: "auth.validation.otpCodeRequired", message: "One-time code is required." },
441
+ otpTokenHashInvalid: { code: "auth.validation.otpTokenHashInvalid", message: "One-time token hash is invalid." },
442
+ otpTypeUnsupported: { code: "auth.validation.otpTypeUnsupported", message: "Only email OTP verification is supported." },
443
+ recoveryCodeInvalid: { code: "auth.validation.recoveryCodeInvalid", message: "Recovery code is invalid." },
444
+ recoveryTokenHashInvalid: {
445
+ code: "auth.validation.recoveryTokenHashInvalid",
446
+ message: "Recovery token hash is invalid."
447
+ },
448
+ recoveryTypeUnsupported: { code: "auth.validation.recoveryTypeUnsupported", message: "Only recovery links are supported." }
449
+ });
450
+
415
451
  function createCommandMessages({
416
452
  fields = {},
417
- defaultMessage = "Invalid value."
453
+ defaultMessage = AUTH_FIELD_MESSAGES.invalidValue
418
454
  } = {}) {
419
455
  return deepFreeze({
420
- apiValidation: "Validation failed.",
456
+ apiValidation: AUTH_FIELD_MESSAGES.validationFailed,
421
457
  fields: {
422
458
  ...(fields && typeof fields === "object" ? fields : {})
423
459
  },
424
460
  keywords: {
425
- additionalProperties: "Unexpected field."
461
+ additionalProperties: AUTH_FIELD_MESSAGES.unexpectedField
426
462
  },
427
- default: String(defaultMessage || "Invalid value.")
463
+ default: defaultMessage || AUTH_FIELD_MESSAGES.invalidValue
428
464
  });
429
465
  }
430
466
 
@@ -462,5 +498,6 @@ export {
462
498
  authCapabilitiesOutputSchema,
463
499
  sessionOutputValidator,
464
500
  sessionUnavailableOutputValidator,
501
+ AUTH_FIELD_MESSAGES,
465
502
  createCommandMessages
466
503
  };
@@ -3,6 +3,7 @@ import { recordIdSchema } from "@jskit-ai/kernel/shared/validators";
3
3
  import { deepFreeze } from "@jskit-ai/kernel/shared/support/deepFreeze";
4
4
  import {
5
5
  authEmailValidator,
6
+ AUTH_FIELD_MESSAGES,
6
7
  createCommandMessages,
7
8
  devLoginAsOutputValidator
8
9
  } from "./authCommandValidators.js";
@@ -10,15 +11,15 @@ import {
10
11
  const AUTH_DEV_LOGIN_AS_MESSAGES = createCommandMessages({
11
12
  fields: {
12
13
  userId: {
13
- pattern: "Provide a valid user id.",
14
- default: "Provide a valid user id."
14
+ pattern: AUTH_FIELD_MESSAGES.devUserIdInvalid,
15
+ default: AUTH_FIELD_MESSAGES.devUserIdInvalid
15
16
  },
16
17
  email: {
17
- pattern: "Enter a valid email address.",
18
- default: "Enter a valid email address."
18
+ pattern: AUTH_FIELD_MESSAGES.emailAddressInvalid,
19
+ default: AUTH_FIELD_MESSAGES.emailAddressInvalid
19
20
  }
20
21
  },
21
- defaultMessage: "Provide a valid user id or email."
22
+ defaultMessage: AUTH_FIELD_MESSAGES.devUserInvalid
22
23
  });
23
24
 
24
25
  const authDevLoginAsBodyValidator = deepFreeze({
@@ -37,7 +38,7 @@ const authDevLoginAsBodyValidator = deepFreeze({
37
38
  ...AUTH_DEV_LOGIN_AS_MESSAGES,
38
39
  keywords: {
39
40
  ...AUTH_DEV_LOGIN_AS_MESSAGES.keywords,
40
- anyOf: "Provide a user id or email."
41
+ anyOf: AUTH_FIELD_MESSAGES.devUserRequired
41
42
  }
42
43
  }
43
44
  });
@@ -4,6 +4,7 @@ import {
4
4
  authAccessTokenFieldDefinition,
5
5
  authRecoveryTokenFieldDefinition,
6
6
  authRefreshTokenFieldDefinition,
7
+ AUTH_FIELD_MESSAGES,
7
8
  createCommandMessages,
8
9
  oauthCompleteOutputValidator,
9
10
  oauthProviderFieldDefinition
@@ -12,23 +13,23 @@ import {
12
13
  const AUTH_LOGIN_OAUTH_COMPLETE_MESSAGES = createCommandMessages({
13
14
  fields: {
14
15
  provider: {
15
- pattern: "OAuth provider id is invalid.",
16
- default: "OAuth provider id is invalid."
16
+ pattern: AUTH_FIELD_MESSAGES.oauthProviderInvalid,
17
+ default: AUTH_FIELD_MESSAGES.oauthProviderInvalid
17
18
  },
18
19
  code: {
19
- default: "OAuth code is invalid."
20
+ default: AUTH_FIELD_MESSAGES.oauthCodeInvalid
20
21
  },
21
22
  accessToken: {
22
- default: "Access token is invalid."
23
+ default: AUTH_FIELD_MESSAGES.accessTokenInvalid
23
24
  },
24
25
  refreshToken: {
25
- default: "Refresh token is invalid."
26
+ default: AUTH_FIELD_MESSAGES.refreshTokenInvalid
26
27
  },
27
28
  state: {
28
- default: "OAuth state is invalid."
29
+ default: AUTH_FIELD_MESSAGES.oauthStateInvalid
29
30
  },
30
31
  iss: {
31
- default: "OAuth issuer is invalid."
32
+ default: AUTH_FIELD_MESSAGES.oauthIssuerInvalid
32
33
  }
33
34
  }
34
35
  });
@@ -1,6 +1,7 @@
1
1
  import { createSchema } from "json-rest-schema";
2
2
  import { deepFreeze } from "@jskit-ai/kernel/shared/support/deepFreeze";
3
3
  import {
4
+ AUTH_FIELD_MESSAGES,
4
5
  createCommandMessages,
5
6
  oauthProviderFieldDefinition,
6
7
  oauthReturnToFieldDefinition
@@ -9,13 +10,13 @@ import {
9
10
  const AUTH_LOGIN_OAUTH_START_MESSAGES = createCommandMessages({
10
11
  fields: {
11
12
  provider: {
12
- required: "OAuth provider is required.",
13
- pattern: "OAuth provider id is invalid.",
14
- default: "OAuth provider id is invalid."
13
+ required: AUTH_FIELD_MESSAGES.oauthProviderRequired,
14
+ pattern: AUTH_FIELD_MESSAGES.oauthProviderInvalid,
15
+ default: AUTH_FIELD_MESSAGES.oauthProviderInvalid
15
16
  },
16
17
  returnTo: {
17
- pattern: "Return target must be an absolute path or URL.",
18
- default: "Return target must be an absolute path or URL."
18
+ pattern: AUTH_FIELD_MESSAGES.returnToInvalid,
19
+ default: AUTH_FIELD_MESSAGES.returnToInvalid
19
20
  }
20
21
  }
21
22
  });
@@ -2,6 +2,7 @@ import { createSchema } from "json-rest-schema";
2
2
  import { deepFreeze } from "@jskit-ai/kernel/shared/support/deepFreeze";
3
3
  import {
4
4
  authEmailFieldDefinition,
5
+ AUTH_FIELD_MESSAGES,
5
6
  createCommandMessages,
6
7
  oauthReturnToFieldDefinition,
7
8
  okMessageOutputValidator
@@ -10,14 +11,14 @@ import {
10
11
  const AUTH_LOGIN_OTP_REQUEST_MESSAGES = createCommandMessages({
11
12
  fields: {
12
13
  email: {
13
- required: "Email is required.",
14
- minLength: "Email is required.",
15
- pattern: "Enter a valid email address.",
16
- default: "Enter a valid email address."
14
+ required: AUTH_FIELD_MESSAGES.emailRequired,
15
+ minLength: AUTH_FIELD_MESSAGES.emailRequired,
16
+ pattern: AUTH_FIELD_MESSAGES.emailAddressInvalid,
17
+ default: AUTH_FIELD_MESSAGES.emailAddressInvalid
17
18
  },
18
19
  returnTo: {
19
- pattern: "Return target must be an absolute path or URL.",
20
- default: "Return target must be an absolute path or URL."
20
+ pattern: AUTH_FIELD_MESSAGES.returnToInvalid,
21
+ default: AUTH_FIELD_MESSAGES.returnToInvalid
21
22
  }
22
23
  }
23
24
  });
@@ -3,6 +3,7 @@ import { deepFreeze } from "@jskit-ai/kernel/shared/support/deepFreeze";
3
3
  import {
4
4
  authEmailValidator,
5
5
  authRecoveryTokenValidator,
6
+ AUTH_FIELD_MESSAGES,
6
7
  createCommandMessages,
7
8
  otpVerifyOutputValidator
8
9
  } from "./authCommandValidators.js";
@@ -10,19 +11,19 @@ import {
10
11
  const AUTH_LOGIN_OTP_VERIFY_MESSAGES = createCommandMessages({
11
12
  fields: {
12
13
  email: {
13
- pattern: "Enter a valid email address.",
14
- default: "Enter a valid email address."
14
+ pattern: AUTH_FIELD_MESSAGES.emailAddressInvalid,
15
+ default: AUTH_FIELD_MESSAGES.emailAddressInvalid
15
16
  },
16
17
  token: {
17
- minLength: "One-time code is required.",
18
- default: "One-time code is required."
18
+ minLength: AUTH_FIELD_MESSAGES.otpCodeRequired,
19
+ default: AUTH_FIELD_MESSAGES.otpCodeRequired
19
20
  },
20
21
  tokenHash: {
21
- default: "One-time token hash is invalid."
22
+ default: AUTH_FIELD_MESSAGES.otpTokenHashInvalid
22
23
  },
23
24
  type: {
24
- const: "Only email OTP verification is supported.",
25
- default: "Only email OTP verification is supported."
25
+ const: AUTH_FIELD_MESSAGES.otpTypeUnsupported,
26
+ default: AUTH_FIELD_MESSAGES.otpTypeUnsupported
26
27
  }
27
28
  }
28
29
  });
@@ -3,6 +3,7 @@ import { deepFreeze } from "@jskit-ai/kernel/shared/support/deepFreeze";
3
3
  import {
4
4
  authEmailFieldDefinition,
5
5
  authLoginPasswordFieldDefinition,
6
+ AUTH_FIELD_MESSAGES,
6
7
  createCommandMessages,
7
8
  loginOutputValidator
8
9
  } from "./authCommandValidators.js";
@@ -10,15 +11,15 @@ import {
10
11
  const AUTH_LOGIN_PASSWORD_MESSAGES = createCommandMessages({
11
12
  fields: {
12
13
  email: {
13
- required: "Email is required.",
14
- minLength: "Email is required.",
15
- pattern: "Enter a valid email address.",
16
- default: "Enter a valid email address."
14
+ required: AUTH_FIELD_MESSAGES.emailRequired,
15
+ minLength: AUTH_FIELD_MESSAGES.emailRequired,
16
+ pattern: AUTH_FIELD_MESSAGES.emailAddressInvalid,
17
+ default: AUTH_FIELD_MESSAGES.emailAddressInvalid
17
18
  },
18
19
  password: {
19
- required: "Password is required.",
20
- minLength: "Password is required.",
21
- default: "Password is required."
20
+ required: AUTH_FIELD_MESSAGES.passwordRequired,
21
+ minLength: AUTH_FIELD_MESSAGES.passwordRequired,
22
+ default: AUTH_FIELD_MESSAGES.passwordRequired
22
23
  }
23
24
  }
24
25
  });
@@ -4,6 +4,7 @@ import {
4
4
  authAccessTokenValidator,
5
5
  authRecoveryTokenValidator,
6
6
  authRefreshTokenValidator,
7
+ AUTH_FIELD_MESSAGES,
7
8
  createCommandMessages,
8
9
  okOutputValidator
9
10
  } from "./authCommandValidators.js";
@@ -11,20 +12,20 @@ import {
11
12
  const AUTH_PASSWORD_RECOVERY_COMPLETE_MESSAGES = createCommandMessages({
12
13
  fields: {
13
14
  code: {
14
- default: "Recovery code is invalid."
15
+ default: AUTH_FIELD_MESSAGES.recoveryCodeInvalid
15
16
  },
16
17
  tokenHash: {
17
- default: "Recovery token hash is invalid."
18
+ default: AUTH_FIELD_MESSAGES.recoveryTokenHashInvalid
18
19
  },
19
20
  accessToken: {
20
- default: "Access token is invalid."
21
+ default: AUTH_FIELD_MESSAGES.accessTokenInvalid
21
22
  },
22
23
  refreshToken: {
23
- default: "Refresh token is invalid."
24
+ default: AUTH_FIELD_MESSAGES.refreshTokenInvalid
24
25
  },
25
26
  type: {
26
- const: "Only recovery links are supported.",
27
- default: "Only recovery links are supported."
27
+ const: AUTH_FIELD_MESSAGES.recoveryTypeUnsupported,
28
+ default: AUTH_FIELD_MESSAGES.recoveryTypeUnsupported
28
29
  }
29
30
  }
30
31
  });
@@ -2,6 +2,7 @@ import { createSchema } from "json-rest-schema";
2
2
  import { deepFreeze } from "@jskit-ai/kernel/shared/support/deepFreeze";
3
3
  import {
4
4
  authPasswordFieldDefinition,
5
+ AUTH_FIELD_MESSAGES,
5
6
  createCommandMessages,
6
7
  okMessageOutputValidator
7
8
  } from "./authCommandValidators.js";
@@ -9,9 +10,9 @@ import {
9
10
  const AUTH_PASSWORD_RESET_MESSAGES = createCommandMessages({
10
11
  fields: {
11
12
  password: {
12
- required: "Password is required.",
13
- minLength: "Password must be at least 8 characters.",
14
- default: "Password must be at least 8 characters."
13
+ required: AUTH_FIELD_MESSAGES.passwordRequired,
14
+ minLength: AUTH_FIELD_MESSAGES.passwordMinLength,
15
+ default: AUTH_FIELD_MESSAGES.passwordMinLength
15
16
  }
16
17
  }
17
18
  });
@@ -2,6 +2,7 @@ import { createSchema } from "json-rest-schema";
2
2
  import { deepFreeze } from "@jskit-ai/kernel/shared/support/deepFreeze";
3
3
  import {
4
4
  authEmailFieldDefinition,
5
+ AUTH_FIELD_MESSAGES,
5
6
  createCommandMessages,
6
7
  okMessageOutputValidator
7
8
  } from "./authCommandValidators.js";
@@ -9,10 +10,10 @@ import {
9
10
  const AUTH_PASSWORD_RESET_REQUEST_MESSAGES = createCommandMessages({
10
11
  fields: {
11
12
  email: {
12
- required: "Email is required.",
13
- minLength: "Email is required.",
14
- pattern: "Enter a valid email address.",
15
- default: "Enter a valid email address."
13
+ required: AUTH_FIELD_MESSAGES.emailRequired,
14
+ minLength: AUTH_FIELD_MESSAGES.emailRequired,
15
+ pattern: AUTH_FIELD_MESSAGES.emailAddressInvalid,
16
+ default: AUTH_FIELD_MESSAGES.emailAddressInvalid
16
17
  }
17
18
  }
18
19
  });
@@ -3,6 +3,7 @@ import { deepFreeze } from "@jskit-ai/kernel/shared/support/deepFreeze";
3
3
  import {
4
4
  authEmailFieldDefinition,
5
5
  authPasswordFieldDefinition,
6
+ AUTH_FIELD_MESSAGES,
6
7
  createCommandMessages,
7
8
  registerOutputValidator
8
9
  } from "./authCommandValidators.js";
@@ -10,15 +11,15 @@ import {
10
11
  const AUTH_REGISTER_MESSAGES = createCommandMessages({
11
12
  fields: {
12
13
  email: {
13
- required: "Email is required.",
14
- minLength: "Email is required.",
15
- pattern: "Enter a valid email address.",
16
- default: "Enter a valid email address."
14
+ required: AUTH_FIELD_MESSAGES.emailRequired,
15
+ minLength: AUTH_FIELD_MESSAGES.emailRequired,
16
+ pattern: AUTH_FIELD_MESSAGES.emailAddressInvalid,
17
+ default: AUTH_FIELD_MESSAGES.emailAddressInvalid
17
18
  },
18
19
  password: {
19
- required: "Password is required.",
20
- minLength: "Password must be at least 8 characters.",
21
- default: "Password must be at least 8 characters."
20
+ required: AUTH_FIELD_MESSAGES.passwordRequired,
21
+ minLength: AUTH_FIELD_MESSAGES.passwordMinLength,
22
+ default: AUTH_FIELD_MESSAGES.passwordMinLength
22
23
  }
23
24
  }
24
25
  });
@@ -2,6 +2,7 @@ import { createSchema } from "json-rest-schema";
2
2
  import { deepFreeze } from "@jskit-ai/kernel/shared/support/deepFreeze";
3
3
  import {
4
4
  authEmailFieldDefinition,
5
+ AUTH_FIELD_MESSAGES,
5
6
  createCommandMessages,
6
7
  okMessageOutputValidator
7
8
  } from "./authCommandValidators.js";
@@ -9,10 +10,10 @@ import {
9
10
  const AUTH_REGISTER_CONFIRMATION_RESEND_MESSAGES = createCommandMessages({
10
11
  fields: {
11
12
  email: {
12
- required: "Email is required.",
13
- minLength: "Email is required.",
14
- pattern: "Enter a valid email address.",
15
- default: "Enter a valid email address."
13
+ required: AUTH_FIELD_MESSAGES.emailRequired,
14
+ minLength: AUTH_FIELD_MESSAGES.emailRequired,
15
+ pattern: AUTH_FIELD_MESSAGES.emailAddressInvalid,
16
+ default: AUTH_FIELD_MESSAGES.emailAddressInvalid
16
17
  }
17
18
  }
18
19
  });
@@ -1,10 +1,16 @@
1
1
  import assert from "node:assert/strict";
2
2
  import test from "node:test";
3
+ import { catalogMessage, formatMessage, messageKeyForCode } from "@jskit-ai/kernel/shared/i18n";
3
4
  import {
4
5
  AUTH_DENIED_CODES,
6
+ AUTH_DENIED_DEFAULT_TEXTS,
7
+ AUTH_DENIED_FALLBACK_TEXT,
8
+ AUTH_DENIED_LOGIN_TEXTS,
5
9
  normalizeAuthDenied,
6
- resolveAuthDeniedLoginMessage
10
+ resolveAuthDeniedLoginMessage,
11
+ resolveAuthDeniedLoginText
7
12
  } from "../src/shared/authDenied.js";
13
+ import en from "../locales/en.json" with { type: "json" };
8
14
 
9
15
  test("normalizeAuthDenied preserves stable denial codes and messages", () => {
10
16
  assert.deepEqual(
@@ -43,3 +49,25 @@ test("resolveAuthDeniedLoginMessage maps default denial reasons to post-login me
43
49
  );
44
50
  assert.equal(resolveAuthDeniedLoginMessage(null), "");
45
51
  });
52
+
53
+ test("an app's own denial reason without a message gets the coded fallback", () => {
54
+ assert.deepEqual(normalizeAuthDenied({ code: "trial_expired" }), {
55
+ code: "trial_expired",
56
+ message: "This account cannot access this application."
57
+ });
58
+ assert.equal(resolveAuthDeniedLoginText({ code: "trial_expired" }), AUTH_DENIED_FALLBACK_TEXT);
59
+ assert.deepEqual(resolveAuthDeniedLoginText({ code: "trial_expired", message: "Your trial ended." }), {
60
+ message: "Your trial ended."
61
+ });
62
+ });
63
+
64
+ test("every coded denial text renders its English from the catalog", () => {
65
+ const texts = [
66
+ ...Object.values(AUTH_DENIED_DEFAULT_TEXTS),
67
+ ...Object.values(AUTH_DENIED_LOGIN_TEXTS),
68
+ AUTH_DENIED_FALLBACK_TEXT
69
+ ];
70
+ for (const { message, messageCode } of texts) {
71
+ assert.equal(formatMessage(catalogMessage(en, messageKeyForCode(messageCode))), message, messageCode);
72
+ }
73
+ });
@@ -13,6 +13,10 @@ import { authPasswordRecoveryCompleteCommand } from "../src/shared/commands/auth
13
13
  import { authPasswordResetCommand } from "../src/shared/commands/authPasswordResetCommand.js";
14
14
  import { authLogoutCommand } from "../src/shared/commands/authLogoutCommand.js";
15
15
  import { authSessionReadCommand } from "../src/shared/commands/authSessionReadCommand.js";
16
+ import { authDevLoginAsCommand } from "../src/shared/commands/authDevLoginAsCommand.js";
17
+ import { catalogMessage, formatMessage, mergeCatalogs, messageKeyForCode } from "@jskit-ai/kernel/shared/i18n";
18
+ import kernelEnglish from "@jskit-ai/kernel/locales/en.json" with { type: "json" };
19
+ import authEnglish from "../locales/en.json" with { type: "json" };
16
20
 
17
21
  test("auth commands expose canonical operation validator messages", () => {
18
22
  const commands = {
@@ -35,6 +39,51 @@ test("auth commands expose canonical operation validator messages", () => {
35
39
  }
36
40
  });
37
41
 
42
+ function* messageEntries(value, path) {
43
+ if (value && typeof value === "object" && typeof value.code === "string") {
44
+ yield [path, value];
45
+ return;
46
+ }
47
+ for (const [name, child] of Object.entries(value || {})) {
48
+ yield* messageEntries(child, `${path}.${name}`);
49
+ }
50
+ }
51
+
52
+ test("every auth command message is coded and its English renders from the catalog", () => {
53
+ const english = mergeCatalogs(kernelEnglish, authEnglish);
54
+ const commands = [
55
+ authRegisterCommand,
56
+ authRegisterConfirmationResendCommand,
57
+ authLoginPasswordCommand,
58
+ authLoginOtpRequestCommand,
59
+ authLoginOtpVerifyCommand,
60
+ authLoginOAuthStartCommand,
61
+ authLoginOAuthCompleteCommand,
62
+ authPasswordResetRequestCommand,
63
+ authPasswordRecoveryCompleteCommand,
64
+ authPasswordResetCommand,
65
+ authLogoutCommand,
66
+ authSessionReadCommand,
67
+ authDevLoginAsCommand
68
+ ];
69
+ const sources = commands.flatMap((command) => [
70
+ [`${command.command}.messages`, command.operation.messages],
71
+ ...(command.operation.body ? [[`${command.command}.body.messages`, command.operation.body.messages]] : [])
72
+ ]);
73
+ let checked = 0;
74
+ for (const [label, messages] of sources) {
75
+ const strings = JSON.stringify(messages).match(/"[^"]*":"[^"]*"/g) || [];
76
+ assert.deepEqual(strings.filter((entry) => !/^"(code|message)":/.test(entry)), [], `${label} has an uncoded message`);
77
+ for (const [path, entry] of messageEntries(messages, label)) {
78
+ const template = catalogMessage(english, messageKeyForCode(entry.code));
79
+ assert.equal(typeof template, "string", `${path}: ${entry.code} has no catalog entry`);
80
+ assert.equal(formatMessage(template, entry.params), entry.message, path);
81
+ checked += 1;
82
+ }
83
+ }
84
+ assert.ok(checked > 60);
85
+ });
86
+
38
87
  test("oauth complete command allows provider-less session-pair callbacks", () => {
39
88
  const bodySchema = resolveSchemaTransportSchemaDefinition(
40
89
  authLoginOAuthCompleteCommand.operation.body,