@jskit-ai/auth-provider-supabase-core 0.1.244 → 0.2.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/CHANGELOG.md ADDED
@@ -0,0 +1,119 @@
1
+ # Changelog
2
+
3
+ ## 0.2.0 - 2026-10-29
4
+
5
+ - 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".
6
+
7
+ ### New message keys (49)
8
+
9
+ All keys in `locales/en.json` (exported as `./locales/en.json`) are new in this version.
10
+
11
+ <details><summary>Key list</summary>
12
+
13
+ - `jskit.auth.supabase.config.missing`
14
+ - `jskit.auth.supabase.config.passwordSettingsMissing`
15
+ - `jskit.auth.supabase.request.failed`
16
+ - `jskit.auth.supabase.register.emailTaken`
17
+ - `jskit.auth.supabase.register.noUser`
18
+ - `jskit.auth.supabase.register.confirmationSent`
19
+ - `jskit.auth.supabase.login.rateLimited`
20
+ - `jskit.auth.supabase.login.emailUnconfirmed`
21
+ - `jskit.auth.supabase.otp.sent`
22
+ - `jskit.auth.supabase.otp.codeRequired`
23
+ - `jskit.auth.supabase.otp.invalid`
24
+ - `jskit.auth.supabase.oauth.disabled`
25
+ - `jskit.auth.supabase.oauth.providerInvalid`
26
+ - `jskit.auth.supabase.oauth.cancelled`
27
+ - `jskit.auth.supabase.oauth.failed`
28
+ - `jskit.auth.supabase.oauth.codeRequired`
29
+ - `jskit.auth.supabase.tokens.accessTokenRequired`
30
+ - `jskit.auth.supabase.tokens.refreshTokenRequired`
31
+ - `jskit.auth.supabase.token.subjectMissing`
32
+ - `jskit.auth.supabase.token.emailMissing`
33
+ - `jskit.auth.supabase.recovery.requested`
34
+ - `jskit.auth.supabase.recovery.rateLimited`
35
+ - `jskit.auth.supabase.recovery.linkInvalid`
36
+ - `jskit.auth.supabase.password.sameAsCurrent`
37
+ - `jskit.auth.supabase.password.updateFailed`
38
+ - `jskit.auth.supabase.password.currentIncorrect`
39
+ - `jskit.auth.supabase.password.currentUnverified`
40
+ - `jskit.auth.supabase.password.signInDisabled`
41
+ - `jskit.auth.supabase.session.emailUnresolved`
42
+ - `jskit.auth.supabase.methods.lastEnabled`
43
+ - `jskit.auth.supabase.methods.enabledNotBoolean`
44
+ - `jskit.auth.supabase.methods.passwordUnresolved`
45
+ - `jskit.auth.supabase.methods.passwordNotSet`
46
+ - `jskit.auth.supabase.link.alreadyLinked`
47
+ - `jskit.auth.supabase.link.manualLinkingDisabled`
48
+ - `jskit.auth.supabase.link.lastIdentity`
49
+ - `jskit.auth.supabase.link.notLinked`
50
+ - `jskit.auth.supabase.link.unsupported`
51
+ - `jskit.auth.supabase.unlink.unsupported`
52
+ - `jskit.auth.supabase.unlink.notLinked`
53
+ - `jskit.auth.supabase.unlink.identityUnresolved`
54
+ - `jskit.auth.supabase.profile.invalid`
55
+ - `jskit.auth.supabase.profile.updateFailed`
56
+ - `jskit.auth.supabase.profile.syncFailed`
57
+ - `jskit.auth.supabase.profile.emailConflict`
58
+ - `jskit.auth.supabase.profile.payloadIncomplete`
59
+ - `jskit.auth.supabase.dev.sessionInvalid`
60
+ - `jskit.auth.supabase.dev.findByIdMissing`
61
+ - `jskit.auth.supabase.dev.findByEmailMissing`
62
+
63
+ </details>
64
+
65
+ ### Codes (49)
66
+
67
+ Error, field-error and message codes this package sends, with their English. Undotted codes kept their existing values and render from `jskit.errors.<code>`.
68
+
69
+ | Code | English |
70
+ | --- | --- |
71
+ | `auth.supabase.config.missing` | Auth provider is not configured. |
72
+ | `auth.supabase.config.passwordSettingsMissing` | Password sign-in settings repository is not configured. |
73
+ | `auth.supabase.request.failed` | Authentication request could not be processed. |
74
+ | `auth.supabase.register.emailTaken` | Email is already registered. |
75
+ | `auth.supabase.register.noUser` | Supabase sign-up did not return a user. |
76
+ | `auth.supabase.register.confirmationSent` | If an account exists for that email, a confirmation email has been sent. |
77
+ | `auth.supabase.login.rateLimited` | Too many authentication attempts. Please wait and try again. |
78
+ | `auth.supabase.login.emailUnconfirmed` | Account exists but email confirmation is required before login. |
79
+ | `auth.supabase.otp.sent` | If an account exists for that email, a one-time code has been sent. |
80
+ | `auth.supabase.otp.codeRequired` | One-time code is required. |
81
+ | `auth.supabase.otp.invalid` | One-time code is invalid or expired. |
82
+ | `auth.supabase.oauth.disabled` | OAuth sign-in is not enabled. |
83
+ | `auth.supabase.oauth.providerInvalid` | OAuth provider must be one of: {providers}. |
84
+ | `auth.supabase.oauth.cancelled` | OAuth sign-in was cancelled. |
85
+ | `auth.supabase.oauth.failed` | OAuth sign-in failed. |
86
+ | `auth.supabase.oauth.codeRequired` | OAuth code is required when access/refresh tokens are not provided. |
87
+ | `auth.supabase.tokens.accessTokenRequired` | Access token is required when a refresh token is provided. |
88
+ | `auth.supabase.tokens.refreshTokenRequired` | Refresh token is required when an access token is provided. |
89
+ | `auth.supabase.token.subjectMissing` | Token is missing subject claim. |
90
+ | `auth.supabase.token.emailMissing` | Token is missing email claim. |
91
+ | `auth.supabase.recovery.requested` | If an account exists for that email, a password reset link has been sent. |
92
+ | `auth.supabase.recovery.rateLimited` | Too many recovery attempts. Please wait and try again. |
93
+ | `auth.supabase.recovery.linkInvalid` | Recovery link is invalid or has expired. |
94
+ | `auth.supabase.password.sameAsCurrent` | New password must be different from the current password. |
95
+ | `auth.supabase.password.updateFailed` | Unable to update password with the provided value. |
96
+ | `auth.supabase.password.currentIncorrect` | Current password is incorrect. |
97
+ | `auth.supabase.password.currentUnverified` | Unable to verify current password. |
98
+ | `auth.supabase.password.signInDisabled` | Password sign-in is disabled for this account. |
99
+ | `auth.supabase.session.emailUnresolved` | Authenticated user email could not be resolved. |
100
+ | `auth.supabase.methods.lastEnabled` | At least one sign-in method must remain enabled. |
101
+ | `auth.supabase.methods.enabledNotBoolean` | Enabled must be a boolean. |
102
+ | `auth.supabase.methods.passwordUnresolved` | Password method configuration could not be resolved. |
103
+ | `auth.supabase.methods.passwordNotSet` | Set a password before enabling password sign-in. |
104
+ | `auth.supabase.link.alreadyLinked` | This sign-in method is already linked. |
105
+ | `auth.supabase.link.manualLinkingDisabled` | Provider linking is disabled in Supabase. Enable Manual Linking in Supabase Auth settings to link or unlink providers. |
106
+ | `auth.supabase.link.lastIdentity` | At least one linked sign-in method must remain available. |
107
+ | `auth.supabase.link.notLinked` | This sign-in method is not currently linked. |
108
+ | `auth.supabase.link.unsupported` | Supabase client does not support identity linking in this environment. |
109
+ | `auth.supabase.unlink.unsupported` | Supabase client does not support identity unlinking in this environment. |
110
+ | `auth.supabase.unlink.notLinked` | {provider} is not linked to this account. |
111
+ | `auth.supabase.unlink.identityUnresolved` | Linked identity details could not be resolved for this provider. |
112
+ | `auth.supabase.profile.invalid` | {context} is invalid. |
113
+ | `auth.supabase.profile.updateFailed` | Unable to update profile details. |
114
+ | `auth.supabase.profile.syncFailed` | Authentication profile synchronization failed. Please retry. |
115
+ | `auth.supabase.profile.emailConflict` | This email is already registered with another sign-in method. Sign in with that method, then link this provider in Settings > Security. |
116
+ | `auth.supabase.profile.payloadIncomplete` | Auth provider user payload is missing required fields. |
117
+ | `auth.supabase.dev.sessionInvalid` | Dev session is invalid. |
118
+ | `auth.supabase.dev.findByIdMissing` | Dev auth bootstrap requires internal.repository.user-profiles.findById(). |
119
+ | `auth.supabase.dev.findByEmailMissing` | Dev auth bootstrap requires internal.repository.user-profiles.findByEmail() for email lookup. |
@@ -0,0 +1,89 @@
1
+ {
2
+ "jskit": {
3
+ "auth": {
4
+ "supabase": {
5
+ "config": {
6
+ "missing": "Auth provider is not configured.",
7
+ "passwordSettingsMissing": "Password sign-in settings repository is not configured."
8
+ },
9
+ "request": {
10
+ "failed": "Authentication request could not be processed."
11
+ },
12
+ "register": {
13
+ "emailTaken": "Email is already registered.",
14
+ "noUser": "Supabase sign-up did not return a user.",
15
+ "confirmationSent": "If an account exists for that email, a confirmation email has been sent."
16
+ },
17
+ "login": {
18
+ "rateLimited": "Too many authentication attempts. Please wait and try again.",
19
+ "emailUnconfirmed": "Account exists but email confirmation is required before login."
20
+ },
21
+ "otp": {
22
+ "sent": "If an account exists for that email, a one-time code has been sent.",
23
+ "codeRequired": "One-time code is required.",
24
+ "invalid": "One-time code is invalid or expired."
25
+ },
26
+ "oauth": {
27
+ "disabled": "OAuth sign-in is not enabled.",
28
+ "providerInvalid": "OAuth provider must be one of: {providers}.",
29
+ "cancelled": "OAuth sign-in was cancelled.",
30
+ "failed": "OAuth sign-in failed.",
31
+ "codeRequired": "OAuth code is required when access/refresh tokens are not provided."
32
+ },
33
+ "tokens": {
34
+ "accessTokenRequired": "Access token is required when a refresh token is provided.",
35
+ "refreshTokenRequired": "Refresh token is required when an access token is provided."
36
+ },
37
+ "token": {
38
+ "subjectMissing": "Token is missing subject claim.",
39
+ "emailMissing": "Token is missing email claim."
40
+ },
41
+ "recovery": {
42
+ "requested": "If an account exists for that email, a password reset link has been sent.",
43
+ "rateLimited": "Too many recovery attempts. Please wait and try again.",
44
+ "linkInvalid": "Recovery link is invalid or has expired."
45
+ },
46
+ "password": {
47
+ "sameAsCurrent": "New password must be different from the current password.",
48
+ "updateFailed": "Unable to update password with the provided value.",
49
+ "currentIncorrect": "Current password is incorrect.",
50
+ "currentUnverified": "Unable to verify current password.",
51
+ "signInDisabled": "Password sign-in is disabled for this account."
52
+ },
53
+ "session": {
54
+ "emailUnresolved": "Authenticated user email could not be resolved."
55
+ },
56
+ "methods": {
57
+ "lastEnabled": "At least one sign-in method must remain enabled.",
58
+ "enabledNotBoolean": "Enabled must be a boolean.",
59
+ "passwordUnresolved": "Password method configuration could not be resolved.",
60
+ "passwordNotSet": "Set a password before enabling password sign-in."
61
+ },
62
+ "link": {
63
+ "alreadyLinked": "This sign-in method is already linked.",
64
+ "manualLinkingDisabled": "Provider linking is disabled in Supabase. Enable Manual Linking in Supabase Auth settings to link or unlink providers.",
65
+ "lastIdentity": "At least one linked sign-in method must remain available.",
66
+ "notLinked": "This sign-in method is not currently linked.",
67
+ "unsupported": "Supabase client does not support identity linking in this environment."
68
+ },
69
+ "unlink": {
70
+ "unsupported": "Supabase client does not support identity unlinking in this environment.",
71
+ "notLinked": "{provider} is not linked to this account.",
72
+ "identityUnresolved": "Linked identity details could not be resolved for this provider."
73
+ },
74
+ "profile": {
75
+ "invalid": "{context} is invalid.",
76
+ "updateFailed": "Unable to update profile details.",
77
+ "syncFailed": "Authentication profile synchronization failed. Please retry.",
78
+ "emailConflict": "This email is already registered with another sign-in method. Sign in with that method, then link this provider in Settings > Security.",
79
+ "payloadIncomplete": "Auth provider user payload is missing required fields."
80
+ },
81
+ "dev": {
82
+ "sessionInvalid": "Dev session is invalid.",
83
+ "findByIdMissing": "Dev auth bootstrap requires internal.repository.user-profiles.findById().",
84
+ "findByEmailMissing": "Dev auth bootstrap requires internal.repository.user-profiles.findByEmail() for email lookup."
85
+ }
86
+ }
87
+ }
88
+ }
89
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/auth-provider-supabase-core",
3
- "version": "0.1.244",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "node --test --test-concurrency=1"
@@ -8,7 +8,8 @@
8
8
  "exports": {
9
9
  "./server/providers/AuthSupabaseProvider": "./src/server/providers/AuthSupabaseProvider.js",
10
10
  "./server/lib/index": "./src/server/lib/index.js",
11
- "./client": "./src/client/index.js"
11
+ "./client": "./src/client/index.js",
12
+ "./locales/en.json": "./locales/en.json"
12
13
  },
13
14
  "dependencies": {
14
15
  "@supabase/supabase-js": "^2.57.4",
@@ -59,7 +60,7 @@
59
60
  }
60
61
  },
61
62
  "peerDependencies": {
62
- "@jskit-ai/auth-core": "0.1.245",
63
- "@jskit-ai/kernel": "0.1.247"
63
+ "@jskit-ai/auth-core": "0.2.0",
64
+ "@jskit-ai/kernel": "0.2.0"
64
65
  }
65
66
  }
@@ -2,6 +2,6 @@
2
2
  "private": true,
3
3
  "type": "module",
4
4
  "dependencies": {
5
- "@jskit-ai/auth-provider-supabase-core": "0.1.244"
5
+ "@jskit-ai/auth-provider-supabase-core": "0.2.0"
6
6
  }
7
7
  }
@@ -1,4 +1,5 @@
1
1
  import { AppError } from "@jskit-ai/kernel/server/runtime/errors";
2
+ import { AUTH_TEXTS, authFieldError, createAuthError } from "@jskit-ai/auth-core/server/authTexts";
2
3
  import { authRegisterBodyValidator } from "@jskit-ai/auth-core/shared/commands/authRegisterCommand";
3
4
  import { authRegisterConfirmationResendBodyValidator } from "@jskit-ai/auth-core/shared/commands/authRegisterConfirmationResendCommand";
4
5
  import { authLoginPasswordBodyValidator } from "@jskit-ai/auth-core/shared/commands/authLoginPasswordCommand";
@@ -9,6 +10,21 @@ import {
9
10
  requireAuthUserSession
10
11
  } from "./flowGuards.js";
11
12
 
13
+ // The answer is the same whether or not an account exists for the email.
14
+ const CONFIRMATION_SENT_RESULT = Object.freeze({
15
+ ok: true,
16
+ message: "If an account exists for that email, a confirmation email has been sent.",
17
+ messageCode: "auth.supabase.register.confirmationSent",
18
+ messageParams: Object.freeze({})
19
+ });
20
+
21
+ const OTP_SENT_RESULT = Object.freeze({
22
+ ok: true,
23
+ message: "If an account exists for that email, a one-time code has been sent.",
24
+ messageCode: "auth.supabase.otp.sent",
25
+ messageParams: Object.freeze({})
26
+ });
27
+
12
28
  function normalizeLocalReturnToPath(value, { fallback = "" } = {}) {
13
29
  const normalized = String(value || "").trim();
14
30
  if (!normalized) {
@@ -107,7 +123,7 @@ function createAccountFlows(deps) {
107
123
  }
108
124
 
109
125
  if (!response.data?.user) {
110
- throw new AppError(500, "Supabase sign-up did not return a user.");
126
+ throw new AppError(500, "Supabase sign-up did not return a user.", { code: "auth.supabase.register.noUser" });
111
127
  }
112
128
 
113
129
  const profile = await syncProfileFromSupabaseUser(response.data.user, parsed.email);
@@ -153,10 +169,7 @@ function createAccountFlows(deps) {
153
169
  throw mapAuthError(error, 503);
154
170
  }
155
171
 
156
- return {
157
- ok: true,
158
- message: "If an account exists for that email, a confirmation email has been sent."
159
- };
172
+ return { ...CONFIRMATION_SENT_RESULT };
160
173
  }
161
174
 
162
175
  if (response.error) {
@@ -165,19 +178,13 @@ function createAccountFlows(deps) {
165
178
  }
166
179
 
167
180
  if (isUserNotFoundLikeAuthError(response.error)) {
168
- return {
169
- ok: true,
170
- message: "If an account exists for that email, a confirmation email has been sent."
171
- };
181
+ return { ...CONFIRMATION_SENT_RESULT };
172
182
  }
173
183
 
174
184
  throw mapAuthError(response.error, Number(response.error?.status || 400));
175
185
  }
176
186
 
177
- return {
178
- ok: true,
179
- message: "If an account exists for that email, a confirmation email has been sent."
180
- };
187
+ return { ...CONFIRMATION_SENT_RESULT };
181
188
  }
182
189
 
183
190
  async function login(payload) {
@@ -200,7 +207,7 @@ function createAccountFlows(deps) {
200
207
  const profile = await syncProfileFromSupabaseUser(user, parsed.email);
201
208
  const passwordSignInPolicy = await resolvePasswordSignInPolicyForUserId(profile.id);
202
209
  if (!passwordSignInPolicy.passwordSignInEnabled) {
203
- throw new AppError(401, "Invalid email or password.");
210
+ throw createAuthError(AUTH_TEXTS.invalidCredentials);
204
211
  }
205
212
 
206
213
  return {
@@ -234,10 +241,7 @@ function createAccountFlows(deps) {
234
241
  throw mapAuthError(error, 503);
235
242
  }
236
243
 
237
- return {
238
- ok: true,
239
- message: "If an account exists for that email, a one-time code has been sent."
240
- };
244
+ return { ...OTP_SENT_RESULT };
241
245
  }
242
246
 
243
247
  if (response.error) {
@@ -246,19 +250,13 @@ function createAccountFlows(deps) {
246
250
  }
247
251
 
248
252
  if (isUserNotFoundLikeAuthError(response.error)) {
249
- return {
250
- ok: true,
251
- message: "If an account exists for that email, a one-time code has been sent."
252
- };
253
+ return { ...OTP_SENT_RESULT };
253
254
  }
254
255
 
255
256
  throw mapAuthError(response.error, Number(response.error?.status || 400));
256
257
  }
257
258
 
258
- return {
259
- ok: true,
260
- message: "If an account exists for that email, a one-time code has been sent."
261
- };
259
+ return { ...OTP_SENT_RESULT };
262
260
  }
263
261
 
264
262
  async function verifyOtpLogin(payload) {
@@ -275,11 +273,11 @@ function createAccountFlows(deps) {
275
273
  const type = String(parsed.type || "email").trim().toLowerCase();
276
274
 
277
275
  if (!token && !tokenHash) {
278
- fieldErrors.token = "One-time code is required.";
276
+ fieldErrors.token = { code: "auth.supabase.otp.codeRequired", message: "One-time code is required." };
279
277
  }
280
278
 
281
279
  if (!tokenHash && !parsed.email) {
282
- fieldErrors.email = "Email is required.";
280
+ fieldErrors.email = authFieldError(AUTH_TEXTS.emailRequired);
283
281
  }
284
282
 
285
283
  if (Object.keys(fieldErrors).length > 0) {
@@ -325,7 +323,7 @@ function createAccountFlows(deps) {
325
323
  ).trim();
326
324
  if (!normalizedDisplayName) {
327
325
  throw validationError({
328
- displayName: "Display name is required."
326
+ displayName: authFieldError(AUTH_TEXTS.displayNameRequired)
329
327
  });
330
328
  }
331
329
 
@@ -1,4 +1,5 @@
1
1
  import { AppError, createValidationError } from "@jskit-ai/kernel/server/runtime/errors";
2
+ import { AUTH_TEXTS, createAuthError } from "@jskit-ai/auth-core/server/authTexts";
2
3
 
3
4
  const TRANSIENT_AUTH_MESSAGE_PARTS = [
4
5
  "network",
@@ -44,7 +45,7 @@ function sanitizeAuthMessage(message, fallback = "Authentication request could n
44
45
 
45
46
  function mapAuthError(error, fallbackStatus) {
46
47
  if (isTransientSupabaseError(error)) {
47
- return new AppError(503, "Authentication service temporarily unavailable. Please retry.");
48
+ return createAuthError(AUTH_TEXTS.sessionUnavailable);
48
49
  }
49
50
 
50
51
  const statusFromError = Number(error?.status || error?.statusCode);
@@ -52,19 +53,23 @@ function mapAuthError(error, fallbackStatus) {
52
53
  const lower = message.toLowerCase();
53
54
 
54
55
  if (statusFromError === 429 || lower.includes("rate limit")) {
55
- return new AppError(429, "Too many authentication attempts. Please wait and try again.");
56
+ return new AppError(429, "Too many authentication attempts. Please wait and try again.", {
57
+ code: "auth.supabase.login.rateLimited"
58
+ });
56
59
  }
57
60
 
58
61
  if (lower.includes("already registered") || lower.includes("already been registered")) {
59
- return new AppError(409, "Email is already registered.");
62
+ return new AppError(409, "Email is already registered.", { code: "auth.supabase.register.emailTaken" });
60
63
  }
61
64
 
62
65
  if (lower.includes("email not confirmed") || lower.includes("confirm your email")) {
63
- return new AppError(403, "Account exists but email confirmation is required before login.");
66
+ return new AppError(403, "Account exists but email confirmation is required before login.", {
67
+ code: "auth.supabase.login.emailUnconfirmed"
68
+ });
64
69
  }
65
70
 
66
71
  if (lower.includes("invalid login credentials") || lower.includes("invalid credentials")) {
67
- return new AppError(401, "Invalid email or password.");
72
+ return createAuthError(AUTH_TEXTS.invalidCredentials);
68
73
  }
69
74
 
70
75
  if (
@@ -72,13 +77,14 @@ function mapAuthError(error, fallbackStatus) {
72
77
  lower.includes("identity is already linked") ||
73
78
  (lower.includes("identity") && lower.includes("already exists"))
74
79
  ) {
75
- return new AppError(409, "This sign-in method is already linked.");
80
+ return new AppError(409, "This sign-in method is already linked.", { code: "auth.supabase.link.alreadyLinked" });
76
81
  }
77
82
 
78
83
  if (lower.includes("manual linking is disabled")) {
79
84
  return new AppError(
80
85
  409,
81
- "Provider linking is disabled in Supabase. Enable Manual Linking in Supabase Auth settings to link or unlink providers."
86
+ "Provider linking is disabled in Supabase. Enable Manual Linking in Supabase Auth settings to link or unlink providers.",
87
+ { code: "auth.supabase.link.manualLinkingDisabled" }
82
88
  );
83
89
  }
84
90
 
@@ -87,11 +93,13 @@ function mapAuthError(error, fallbackStatus) {
87
93
  lower.includes("only identity") ||
88
94
  (lower.includes("at least one") && lower.includes("identity"))
89
95
  ) {
90
- return new AppError(409, "At least one linked sign-in method must remain available.");
96
+ return new AppError(409, "At least one linked sign-in method must remain available.", {
97
+ code: "auth.supabase.link.lastIdentity"
98
+ });
91
99
  }
92
100
 
93
101
  if (lower.includes("identity") && lower.includes("not found")) {
94
- return new AppError(409, "This sign-in method is not currently linked.");
102
+ return new AppError(409, "This sign-in method is not currently linked.", { code: "auth.supabase.link.notLinked" });
95
103
  }
96
104
 
97
105
  const status = Number.isInteger(statusFromError)
@@ -100,16 +108,12 @@ function mapAuthError(error, fallbackStatus) {
100
108
  ? Number(fallbackStatus)
101
109
  : 400;
102
110
  if (status >= 500) {
103
- return new AppError(503, "Authentication service temporarily unavailable. Please retry.");
111
+ return createAuthError(AUTH_TEXTS.sessionUnavailable);
104
112
  }
105
113
  if (status === 401) {
106
- return new AppError(401, "Invalid email or password.");
114
+ return createAuthError(AUTH_TEXTS.invalidCredentials);
107
115
  }
108
- if (status >= 400 && status < 500) {
109
- return new AppError(status, "Authentication request could not be processed.");
110
- }
111
-
112
- return new AppError(status, "Authentication request could not be processed.");
116
+ return new AppError(status, "Authentication request could not be processed.", { code: "auth.supabase.request.failed" });
113
117
  }
114
118
 
115
119
  function isUserNotFoundLikeAuthError(error) {
@@ -125,66 +129,71 @@ function isUserNotFoundLikeAuthError(error) {
125
129
 
126
130
  function mapRecoveryError(error) {
127
131
  if (isTransientSupabaseError(error)) {
128
- return new AppError(503, "Authentication service temporarily unavailable. Please retry.");
132
+ return createAuthError(AUTH_TEXTS.sessionUnavailable);
129
133
  }
130
134
 
131
135
  const status = Number(error?.status || error?.statusCode);
132
136
  if (status === 429) {
133
- return new AppError(429, "Too many recovery attempts. Please wait and try again.");
137
+ return new AppError(429, "Too many recovery attempts. Please wait and try again.", {
138
+ code: "auth.supabase.recovery.rateLimited"
139
+ });
134
140
  }
135
141
 
136
- return new AppError(401, "Recovery link is invalid or has expired.");
142
+ return new AppError(401, "Recovery link is invalid or has expired.", { code: "auth.supabase.recovery.linkInvalid" });
137
143
  }
138
144
 
139
145
  function mapPasswordUpdateError(error) {
140
146
  if (isTransientSupabaseError(error)) {
141
- return new AppError(503, "Authentication service temporarily unavailable. Please retry.");
147
+ return createAuthError(AUTH_TEXTS.sessionUnavailable);
142
148
  }
143
149
 
144
150
  const message = String(error?.message || "").toLowerCase();
145
151
  if (message.includes("same") && message.includes("password")) {
146
152
  return createValidationError({
147
- password: "New password must be different from the current password."
153
+ password: {
154
+ code: "auth.supabase.password.sameAsCurrent",
155
+ message: "New password must be different from the current password."
156
+ }
148
157
  });
149
158
  }
150
159
 
151
160
  return createValidationError({
152
- password: "Unable to update password with the provided value."
161
+ password: { code: "auth.supabase.password.updateFailed", message: "Unable to update password with the provided value." }
153
162
  });
154
163
  }
155
164
 
156
165
  function mapOtpVerifyError(error) {
157
166
  if (isTransientSupabaseError(error)) {
158
- return new AppError(503, "Authentication service temporarily unavailable. Please retry.");
167
+ return createAuthError(AUTH_TEXTS.sessionUnavailable);
159
168
  }
160
169
 
161
- return new AppError(401, "One-time code is invalid or expired.");
170
+ return new AppError(401, "One-time code is invalid or expired.", { code: "auth.supabase.otp.invalid" });
162
171
  }
163
172
 
164
173
  function mapProfileUpdateError(error) {
165
174
  if (isTransientSupabaseError(error)) {
166
- return new AppError(503, "Authentication service temporarily unavailable. Please retry.");
175
+ return createAuthError(AUTH_TEXTS.sessionUnavailable);
167
176
  }
168
177
 
169
178
  return validationError({
170
- displayName: "Unable to update profile details."
179
+ displayName: { code: "auth.supabase.profile.updateFailed", message: "Unable to update profile details." }
171
180
  });
172
181
  }
173
182
 
174
183
  function mapCurrentPasswordError(error) {
175
184
  if (isTransientSupabaseError(error)) {
176
- return new AppError(503, "Authentication service temporarily unavailable. Please retry.");
185
+ return createAuthError(AUTH_TEXTS.sessionUnavailable);
177
186
  }
178
187
 
179
188
  const status = Number(error?.status || error?.statusCode);
180
189
  if (status === 400 || status === 401 || status === 403) {
181
190
  return validationError({
182
- currentPassword: "Current password is incorrect."
191
+ currentPassword: { code: "auth.supabase.password.currentIncorrect", message: "Current password is incorrect." }
183
192
  });
184
193
  }
185
194
 
186
195
  return validationError({
187
- currentPassword: "Unable to verify current password."
196
+ currentPassword: { code: "auth.supabase.password.currentUnverified", message: "Unable to verify current password." }
188
197
  });
189
198
  }
190
199
 
@@ -11,7 +11,7 @@ function normalizeOAuthProviderInput(value, options = {}) {
11
11
  const providerIds = resolveConfiguredOAuthProviders(options);
12
12
  if (providerIds.length < 1) {
13
13
  throw validationError({
14
- provider: "OAuth sign-in is not enabled."
14
+ provider: { code: "auth.supabase.oauth.disabled", message: "OAuth sign-in is not enabled." }
15
15
  });
16
16
  }
17
17
 
@@ -23,8 +23,13 @@ function normalizeOAuthProviderInput(value, options = {}) {
23
23
  return provider;
24
24
  }
25
25
 
26
+ const providers = providerIds.join(", ");
26
27
  throw validationError({
27
- provider: `OAuth provider must be one of: ${providerIds.join(", ")}.`
28
+ provider: {
29
+ code: "auth.supabase.oauth.providerInvalid",
30
+ params: { providers },
31
+ message: `OAuth provider must be one of: ${providers}.`
32
+ }
28
33
  });
29
34
  }
30
35
 
@@ -34,10 +39,10 @@ function mapOAuthCallbackError(errorCode) {
34
39
  .toLowerCase();
35
40
 
36
41
  if (normalizedCode === "access_denied") {
37
- return new AppError(401, "OAuth sign-in was cancelled.");
42
+ return new AppError(401, "OAuth sign-in was cancelled.", { code: "auth.supabase.oauth.cancelled" });
38
43
  }
39
44
 
40
- return new AppError(401, "OAuth sign-in failed.");
45
+ return new AppError(401, "OAuth sign-in failed.", { code: "auth.supabase.oauth.failed" });
41
46
  }
42
47
 
43
48
  export {
@@ -69,7 +69,7 @@ function requireAuthenticatedProfile(profileLike, { context = "authenticated pro
69
69
 
70
70
  const { validatedObject, errors } = authenticatedProfileSchema.create(candidate);
71
71
  if (Object.keys(errors).length > 0) {
72
- throw new AppError(500, `${context} is invalid.`);
72
+ throw new AppError(500, `${context} is invalid.`, { code: "auth.supabase.profile.invalid", params: { context } });
73
73
  }
74
74
 
75
75
  return validatedObject;
@@ -6,6 +6,7 @@ import {
6
6
  resolveDevAuthPolicy
7
7
  } from "@jskit-ai/auth-core/server/devAuth";
8
8
  import { normalizeEmail } from "@jskit-ai/auth-core/server/utils";
9
+ import { AUTH_TEXTS, authFieldError } from "@jskit-ai/auth-core/server/authTexts";
9
10
  import { loadJose, isExpiredJwtError } from "./authJwt.js";
10
11
 
11
12
  const DEV_AUTH_TOKEN_PREFIX = "jskit-dev.";
@@ -109,7 +110,7 @@ async function resolveProfileFromTokenClaims(payload, { userProfilesRepository =
109
110
  return profile;
110
111
  }
111
112
 
112
- throw new AppError(401, "Dev session is invalid.");
113
+ throw new AppError(401, "Dev session is invalid.", { code: "auth.supabase.dev.sessionInvalid" });
113
114
  }
114
115
 
115
116
  async function signDevAuthToken(kind, profile, config) {
@@ -191,15 +192,17 @@ async function createDevAuthSession(profile, config) {
191
192
 
192
193
  async function resolveDevAuthProfile(input = {}, { userProfilesRepository = null, validationError } = {}) {
193
194
  if (!userProfilesRepository || typeof userProfilesRepository.findById !== "function") {
194
- throw new AppError(500, "Dev auth bootstrap requires internal.repository.user-profiles.findById().");
195
+ throw new AppError(500, "Dev auth bootstrap requires internal.repository.user-profiles.findById().", {
196
+ code: "auth.supabase.dev.findByIdMissing"
197
+ });
195
198
  }
196
199
 
197
200
  const normalizedUserId = normalizeRecordId(input?.userId, { fallback: null });
198
201
  const normalizedEmail = normalizeEmail(input?.email || "");
199
202
  if (!normalizedUserId && !normalizedEmail) {
200
203
  throw validationError({
201
- userId: "Provide a user id or email.",
202
- email: "Provide a user id or email."
204
+ userId: authFieldError(AUTH_TEXTS.devUserRequired),
205
+ email: authFieldError(AUTH_TEXTS.devUserRequired)
203
206
  });
204
207
  }
205
208
 
@@ -210,19 +213,21 @@ async function resolveDevAuthProfile(input = {}, { userProfilesRepository = null
210
213
  if (byId?.id) {
211
214
  return byId;
212
215
  }
213
- fieldErrors.userId = "User not found.";
216
+ fieldErrors.userId = authFieldError(AUTH_TEXTS.devUserNotFound);
214
217
  }
215
218
 
216
219
  if (normalizedEmail) {
217
220
  if (typeof userProfilesRepository.findByEmail !== "function") {
218
- throw new AppError(500, "Dev auth bootstrap requires internal.repository.user-profiles.findByEmail() for email lookup.");
221
+ throw new AppError(500, "Dev auth bootstrap requires internal.repository.user-profiles.findByEmail() for email lookup.", {
222
+ code: "auth.supabase.dev.findByEmailMissing"
223
+ });
219
224
  }
220
225
 
221
226
  const byEmail = await userProfilesRepository.findByEmail(normalizedEmail);
222
227
  if (byEmail?.id) {
223
228
  return byEmail;
224
229
  }
225
- fieldErrors.email = "User not found.";
230
+ fieldErrors.email = authFieldError(AUTH_TEXTS.devUserNotFound);
226
231
  }
227
232
 
228
233
  throw validationError(fieldErrors);
@@ -109,7 +109,9 @@ function createOauthFlows(deps) {
109
109
  });
110
110
 
111
111
  if (typeof supabase.auth.linkIdentity !== "function") {
112
- throw new AppError(500, "Supabase client does not support identity linking in this environment.");
112
+ throw new AppError(500, "Supabase client does not support identity linking in this environment.", {
113
+ code: "auth.supabase.link.unsupported"
114
+ });
113
115
  }
114
116
 
115
117
  const redirectTo = buildOAuthLinkRedirectUrl({
@@ -146,15 +148,24 @@ function createOauthFlows(deps) {
146
148
 
147
149
  if ((accessToken && !refreshToken) || (!accessToken && refreshToken)) {
148
150
  if (!accessToken) {
149
- fieldErrors.accessToken = "Access token is required when a refresh token is provided.";
151
+ fieldErrors.accessToken = {
152
+ code: "auth.supabase.tokens.accessTokenRequired",
153
+ message: "Access token is required when a refresh token is provided."
154
+ };
150
155
  }
151
156
  if (!refreshToken) {
152
- fieldErrors.refreshToken = "Refresh token is required when an access token is provided.";
157
+ fieldErrors.refreshToken = {
158
+ code: "auth.supabase.tokens.refreshTokenRequired",
159
+ message: "Refresh token is required when an access token is provided."
160
+ };
153
161
  }
154
162
  }
155
163
 
156
164
  if (!code && !errorCode && !hasSessionPair) {
157
- fieldErrors.code = "OAuth code is required when access/refresh tokens are not provided.";
165
+ fieldErrors.code = {
166
+ code: "auth.supabase.oauth.codeRequired",
167
+ message: "OAuth code is required when access/refresh tokens are not provided."
168
+ };
158
169
  }
159
170
 
160
171
  if (Object.keys(fieldErrors).length > 0) {
@@ -204,7 +215,9 @@ function createOauthFlows(deps) {
204
215
  const provider = normalizeOAuthProviderInput(payload.provider);
205
216
  const supabase = getSupabaseClient();
206
217
  if (typeof supabase.auth.unlinkIdentity !== "function") {
207
- throw new AppError(500, "Supabase client does not support identity unlinking in this environment.");
218
+ throw new AppError(500, "Supabase client does not support identity unlinking in this environment.", {
219
+ code: "auth.supabase.unlink.unsupported"
220
+ });
208
221
  }
209
222
 
210
223
  await setSessionFromRequestCookies(request, {
@@ -217,17 +230,19 @@ function createOauthFlows(deps) {
217
230
  const providerMethod = findAuthMethodById(current.authMethodsStatus, methodId);
218
231
  if (!providerMethod || !providerMethod.configured) {
219
232
  throw validationError({
220
- provider: `${provider} is not linked to this account.`
233
+ provider: { code: "auth.supabase.unlink.notLinked", params: { provider }, message: `${provider} is not linked to this account.` }
221
234
  });
222
235
  }
223
236
 
224
237
  if (!providerMethod.canDisable) {
225
- throw new AppError(409, "At least one sign-in method must remain enabled.");
238
+ throw new AppError(409, "At least one sign-in method must remain enabled.", { code: "auth.supabase.methods.lastEnabled" });
226
239
  }
227
240
 
228
241
  const identity = findLinkedIdentityByProvider(current.user, provider);
229
242
  if (!identity) {
230
- throw new AppError(409, "Linked identity details could not be resolved for this provider.");
243
+ throw new AppError(409, "Linked identity details could not be resolved for this provider.", {
244
+ code: "auth.supabase.unlink.identityUnresolved"
245
+ });
231
246
  }
232
247
 
233
248
  let response;
@@ -1,4 +1,5 @@
1
1
  import { AppError } from "@jskit-ai/kernel/server/runtime/errors";
2
+ import { AUTH_TEXTS, authFieldError } from "@jskit-ai/auth-core/server/authTexts";
2
3
  import { authPasswordResetRequestBodyValidator } from "@jskit-ai/auth-core/shared/commands/authPasswordResetRequestCommand";
3
4
  import { authPasswordRecoveryCompleteBodyValidator } from "@jskit-ai/auth-core/shared/commands/authPasswordRecoveryCompleteCommand";
4
5
  import { authPasswordResetBodyValidator } from "@jskit-ai/auth-core/shared/commands/authPasswordResetCommand";
@@ -63,7 +64,9 @@ function createPasswordSecurityFlows(deps) {
63
64
 
64
65
  return {
65
66
  ok: true,
66
- message: "If an account exists for that email, a password reset link has been sent."
67
+ message: "If an account exists for that email, a password reset link has been sent.",
68
+ messageCode: "auth.supabase.recovery.requested",
69
+ messageParams: {}
67
70
  };
68
71
  }
69
72
 
@@ -86,15 +89,21 @@ function createPasswordSecurityFlows(deps) {
86
89
 
87
90
  if ((accessToken && !refreshToken) || (!accessToken && refreshToken)) {
88
91
  if (!accessToken) {
89
- fieldErrors.accessToken = "Access token is required when a refresh token is provided.";
92
+ fieldErrors.accessToken = {
93
+ code: "auth.supabase.tokens.accessTokenRequired",
94
+ message: "Access token is required when a refresh token is provided."
95
+ };
90
96
  }
91
97
  if (!refreshToken) {
92
- fieldErrors.refreshToken = "Refresh token is required when an access token is provided.";
98
+ fieldErrors.refreshToken = {
99
+ code: "auth.supabase.tokens.refreshTokenRequired",
100
+ message: "Refresh token is required when an access token is provided."
101
+ };
93
102
  }
94
103
  }
95
104
 
96
105
  if (!hasCode && !hasTokenHash && !hasSessionPair) {
97
- fieldErrors.recovery = "Recovery token is required.";
106
+ fieldErrors.recovery = authFieldError(AUTH_TEXTS.recoveryTokenRequired);
98
107
  }
99
108
 
100
109
  if (Object.keys(fieldErrors).length > 0) {
@@ -126,7 +135,8 @@ function createPasswordSecurityFlows(deps) {
126
135
  throw mapRecoveryError(response.error);
127
136
  }
128
137
 
129
- const { user, session } = requireAuthUserSession(response, () => new AppError(401, "Recovery link is invalid or has expired."));
138
+ const { user, session } = requireAuthUserSession(response, () =>
139
+ new AppError(401, "Recovery link is invalid or has expired.", { code: "auth.supabase.recovery.linkInvalid" }));
130
140
  const profile = await syncProfileFromSupabaseUser(user, user.email);
131
141
 
132
142
  return {
@@ -157,7 +167,7 @@ function createPasswordSecurityFlows(deps) {
157
167
  );
158
168
  const passwordSignInPolicy = await resolvePasswordSignInPolicyForUserId(profile.id);
159
169
  if (!passwordSignInPolicy.passwordSignInEnabled) {
160
- throw new AppError(409, "Password sign-in is disabled for this account.");
170
+ throw new AppError(409, "Password sign-in is disabled for this account.", { code: "auth.supabase.password.signInDisabled" });
161
171
  }
162
172
 
163
173
  let updateResponse;
@@ -196,7 +206,7 @@ function createPasswordSecurityFlows(deps) {
196
206
 
197
207
  const email = normalizeEmail(sessionResponse.data.user?.email || "");
198
208
  if (!email) {
199
- throw new AppError(500, "Authenticated user email could not be resolved.");
209
+ throw new AppError(500, "Authenticated user email could not be resolved.", { code: "auth.supabase.session.emailUnresolved" });
200
210
  }
201
211
 
202
212
  if (requireCurrentPassword) {
@@ -239,7 +249,7 @@ function createPasswordSecurityFlows(deps) {
239
249
 
240
250
  if (typeof payload?.enabled !== "boolean") {
241
251
  throw validationError({
242
- enabled: "Enabled must be a boolean."
252
+ enabled: { code: "auth.supabase.methods.enabledNotBoolean", message: "Enabled must be a boolean." }
243
253
  });
244
254
  }
245
255
 
@@ -253,17 +263,19 @@ function createPasswordSecurityFlows(deps) {
253
263
  const passwordMethod = findAuthMethodById(current.authMethodsStatus, authMethodPasswordId);
254
264
 
255
265
  if (!passwordMethod) {
256
- throw new AppError(500, "Password method configuration could not be resolved.");
266
+ throw new AppError(500, "Password method configuration could not be resolved.", {
267
+ code: "auth.supabase.methods.passwordUnresolved"
268
+ });
257
269
  }
258
270
 
259
271
  if (payload.enabled && !passwordMethod.configured) {
260
272
  throw validationError({
261
- enabled: "Set a password before enabling password sign-in."
273
+ enabled: { code: "auth.supabase.methods.passwordNotSet", message: "Set a password before enabling password sign-in." }
262
274
  });
263
275
  }
264
276
 
265
277
  if (!payload.enabled && !passwordMethod.canDisable) {
266
- throw new AppError(409, "At least one sign-in method must remain enabled.");
278
+ throw new AppError(409, "At least one sign-in method must remain enabled.", { code: "auth.supabase.methods.lastEnabled" });
267
279
  }
268
280
 
269
281
  if (!payload.enabled && passwordMethod.configured) {
@@ -1,5 +1,6 @@
1
1
  import { createClient } from "@supabase/supabase-js";
2
2
  import { AppError } from "@jskit-ai/kernel/server/runtime/errors";
3
+ import { AUTH_TEXTS, createAuthError } from "@jskit-ai/auth-core/server/authTexts";
3
4
  import { normalizeAuthCapabilities } from "@jskit-ai/auth-core/shared/authCapabilities";
4
5
  import { ensureDevAuthExchangeAvailable } from "@jskit-ai/auth-core/server/devAuth";
5
6
  import { normalizeAuthActor, normalizeAuthResult } from "@jskit-ai/auth-core/server/authActor";
@@ -262,7 +263,7 @@ function createService(options) {
262
263
 
263
264
  function ensureConfigured() {
264
265
  if (!supabaseUrl || !supabasePublishableKey) {
265
- throw new AppError(500, "Auth provider is not configured.");
266
+ throw new AppError(500, "Auth provider is not configured.", { code: "auth.supabase.config.missing" });
266
267
  }
267
268
  }
268
269
 
@@ -363,7 +364,7 @@ function createService(options) {
363
364
  const normalizedRefreshToken = String(refreshToken || "").trim();
364
365
 
365
366
  if (!normalizedAccessToken || !normalizedRefreshToken) {
366
- throw new AppError(401, "Authentication required.");
367
+ throw createAuthError(AUTH_TEXTS.sessionRequired);
367
368
  }
368
369
 
369
370
  const supabase = options.supabaseClient || getSupabaseClient();
@@ -443,7 +444,7 @@ function createService(options) {
443
444
  }
444
445
 
445
446
  if (!user) {
446
- throw new AppError(401, "Authentication required.");
447
+ throw createAuthError(AUTH_TEXTS.sessionRequired);
447
448
  }
448
449
 
449
450
  return {
@@ -562,7 +563,9 @@ function createService(options) {
562
563
  });
563
564
  } catch (error) {
564
565
  if (error instanceof AppError) {
565
- throw new AppError(500, "Authentication profile synchronization failed. Please retry.");
566
+ throw new AppError(500, "Authentication profile synchronization failed. Please retry.", {
567
+ code: "auth.supabase.profile.syncFailed"
568
+ });
566
569
  }
567
570
  throw error;
568
571
  }
@@ -630,7 +633,8 @@ function createService(options) {
630
633
  if (String(error?.code || "") === USER_PROFILE_EMAIL_CONFLICT_CODE) {
631
634
  throw new AppError(
632
635
  409,
633
- "This email is already registered with another sign-in method. Sign in with that method, then link this provider in Settings > Security."
636
+ "This email is already registered with another sign-in method. Sign in with that method, then link this provider in Settings > Security.",
637
+ { code: "auth.supabase.profile.emailConflict" }
634
638
  );
635
639
  }
636
640
 
@@ -643,7 +647,7 @@ function createService(options) {
643
647
  const email = normalizeEmail(supabaseUser?.email || fallbackEmail);
644
648
 
645
649
  if (!supabaseUserId || !email) {
646
- throw new AppError(500, "Auth provider user payload is missing required fields.");
650
+ throw new AppError(500, "Auth provider user payload is missing required fields.", { code: "auth.supabase.profile.payloadIncomplete" });
647
651
  }
648
652
 
649
653
  return syncProfileMirror({
@@ -696,7 +700,7 @@ function createService(options) {
696
700
  async function syncProfileFromJwtClaims(claims) {
697
701
  const supabaseUserId = normalizeProviderUserId(claims?.sub);
698
702
  if (!supabaseUserId) {
699
- throw new AppError(401, "Token is missing subject claim.");
703
+ throw new AppError(401, "Token is missing subject claim.", { code: "auth.supabase.token.subjectMissing" });
700
704
  }
701
705
 
702
706
  const existing = await findProfileByIdentity({
@@ -709,7 +713,7 @@ function createService(options) {
709
713
  if (existing) {
710
714
  return existing;
711
715
  }
712
- throw new AppError(401, "Token is missing email claim.");
716
+ throw new AppError(401, "Token is missing email claim.", { code: "auth.supabase.token.emailMissing" });
713
717
  }
714
718
 
715
719
  return syncProfileMirror({
@@ -737,7 +741,9 @@ function createService(options) {
737
741
 
738
742
  async function setPasswordSignInEnabledForUserId(userId, enabled, options = {}) {
739
743
  if (!userSettingsRepository || typeof userSettingsRepository.updatePasswordSignInEnabled !== "function") {
740
- throw new AppError(500, "Password sign-in settings repository is not configured.");
744
+ throw new AppError(500, "Password sign-in settings repository is not configured.", {
745
+ code: "auth.supabase.config.passwordSettingsMissing"
746
+ });
741
747
  }
742
748
 
743
749
  const updated = await userSettingsRepository.updatePasswordSignInEnabled(userId, enabled, options);
@@ -780,7 +786,7 @@ function createService(options) {
780
786
  }
781
787
 
782
788
  if (devAuthResult.authenticated !== true) {
783
- throw new AppError(401, "Authentication required.");
789
+ throw createAuthError(AUTH_TEXTS.sessionRequired);
784
790
  }
785
791
 
786
792
  const passwordSignInPolicy = await resolvePasswordSignInPolicyForUserId(devAuthResult.actor.id);
@@ -0,0 +1,95 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import { createValidationError } from "@jskit-ai/kernel/server/runtime/errors";
4
+ import { catalogMessage, formatMessage, mergeCatalogs, messageKeyForCode } from "@jskit-ai/kernel/shared/i18n";
5
+ import authCoreEnglish from "@jskit-ai/auth-core/locales/en.json" with { type: "json" };
6
+ import supabaseEnglish from "../locales/en.json" with { type: "json" };
7
+ import {
8
+ mapAuthError,
9
+ mapCurrentPasswordError,
10
+ mapOtpVerifyError,
11
+ mapPasswordUpdateError,
12
+ mapProfileUpdateError,
13
+ mapRecoveryError
14
+ } from "../src/server/lib/authErrorMappers.js";
15
+ import { mapOAuthCallbackError, normalizeOAuthProviderInput } from "../src/server/lib/authInputParsers.js";
16
+ import { requireAuthenticatedProfile } from "../src/server/lib/authenticatedProfile.js";
17
+ import { resolveDevAuthProfile } from "../src/server/lib/devAuthBootstrap.js";
18
+
19
+ const english = mergeCatalogs(authCoreEnglish, supabaseEnglish);
20
+
21
+ function rendered(code, params = {}) {
22
+ const template = catalogMessage(english, messageKeyForCode(code));
23
+ assert.notEqual(template, undefined, `${code} has no English`);
24
+ return formatMessage(template, params);
25
+ }
26
+
27
+ // A coded error says exactly its catalog English; so does each coded field.
28
+ function assertCoded(error, code) {
29
+ assert.equal(error.code, code);
30
+ if (code !== "validation_failed") {
31
+ assert.equal(rendered(error.code, error.params), error.message);
32
+ }
33
+ for (const [field, coded] of Object.entries(error.details?.fieldErrorCodes || {})) {
34
+ assert.equal(rendered(coded.code, coded.params), error.details.fieldErrors[field], field);
35
+ }
36
+ return error;
37
+ }
38
+
39
+ test("Supabase error mappers return coded errors whose English is their message", () => {
40
+ const cases = [
41
+ [mapAuthError({ status: 503, message: "upstream" }), "auth.session.unavailable"],
42
+ [mapAuthError({ status: 429, message: "slow down" }), "auth.supabase.login.rateLimited"],
43
+ [mapAuthError({ message: "User already registered" }), "auth.supabase.register.emailTaken"],
44
+ [mapAuthError({ message: "Email not confirmed" }), "auth.supabase.login.emailUnconfirmed"],
45
+ [mapAuthError({ message: "Invalid login credentials" }), "auth.login.invalidCredentials"],
46
+ [mapAuthError({ message: "Identity is already linked" }), "auth.supabase.link.alreadyLinked"],
47
+ [mapAuthError({ message: "Manual linking is disabled" }), "auth.supabase.link.manualLinkingDisabled"],
48
+ [mapAuthError({ message: "cannot unlink the last identity" }), "auth.supabase.link.lastIdentity"],
49
+ [mapAuthError({ message: "identity not found" }), "auth.supabase.link.notLinked"],
50
+ [mapAuthError({ status: 401, message: "nope" }), "auth.login.invalidCredentials"],
51
+ [mapAuthError({ status: 422, message: "odd" }), "auth.supabase.request.failed"],
52
+ [mapRecoveryError({ status: 429 }), "auth.supabase.recovery.rateLimited"],
53
+ [mapRecoveryError({ status: 400 }), "auth.supabase.recovery.linkInvalid"],
54
+ [mapOtpVerifyError({ status: 400 }), "auth.supabase.otp.invalid"],
55
+ [mapOAuthCallbackError("access_denied"), "auth.supabase.oauth.cancelled"],
56
+ [mapOAuthCallbackError("server_error"), "auth.supabase.oauth.failed"]
57
+ ];
58
+ for (const [error, code] of cases) {
59
+ assertCoded(error, code);
60
+ }
61
+ });
62
+
63
+ test("Supabase field errors carry codes whose English is the field message", async () => {
64
+ const fieldCases = [
65
+ [mapPasswordUpdateError({ message: "New password should be different from the same password" }), "password",
66
+ "auth.supabase.password.sameAsCurrent"],
67
+ [mapPasswordUpdateError({ message: "weak" }), "password", "auth.supabase.password.updateFailed"],
68
+ [mapProfileUpdateError({ status: 400 }), "displayName", "auth.supabase.profile.updateFailed"],
69
+ [mapCurrentPasswordError({ status: 400 }), "currentPassword", "auth.supabase.password.currentIncorrect"],
70
+ [mapCurrentPasswordError({ status: 418 }), "currentPassword", "auth.supabase.password.currentUnverified"]
71
+ ];
72
+ for (const [error, field, code] of fieldCases) {
73
+ assert.equal(assertCoded(error, "validation_failed").details.fieldErrorCodes[field].code, code);
74
+ }
75
+
76
+ assert.throws(() => normalizeOAuthProviderInput("github", { providerIds: [] }),
77
+ (error) => assertCoded(error, "validation_failed").details.fieldErrorCodes.provider.code === "auth.supabase.oauth.disabled");
78
+ assert.throws(() => normalizeOAuthProviderInput("gitlab", { providerIds: ["github", "google"] }), (error) => {
79
+ assert.deepEqual(assertCoded(error, "validation_failed").details.fieldErrorCodes.provider, {
80
+ code: "auth.supabase.oauth.providerInvalid",
81
+ params: { providers: "github, google" }
82
+ });
83
+ return true;
84
+ });
85
+
86
+ await assert.rejects(() => resolveDevAuthProfile({ email: "ghost@example.com" }, {
87
+ userProfilesRepository: { findById: async () => null, findByEmail: async () => null },
88
+ validationError: createValidationError
89
+ }), (error) => assertCoded(error, "validation_failed").details.fieldErrorCodes.email.code === "auth.dev.userNotFound");
90
+ });
91
+
92
+ test("an invalid authenticated profile names its context through params", () => {
93
+ assert.throws(() => requireAuthenticatedProfile({}, { context: "authentication profile" }),
94
+ (error) => Boolean(assertCoded(error, "auth.supabase.profile.invalid")));
95
+ });
@@ -5,7 +5,8 @@ import test from "node:test";
5
5
  const EXPECTED_EXPORTS = Object.freeze({
6
6
  "./server/providers/AuthSupabaseProvider": "./src/server/providers/AuthSupabaseProvider.js",
7
7
  "./server/lib/index": "./src/server/lib/index.js",
8
- "./client": "./src/client/index.js"
8
+ "./client": "./src/client/index.js",
9
+ "./locales/en.json": "./locales/en.json"
9
10
  });
10
11
 
11
12
  test("auth-provider-supabase-core exports only curated entrypoints", async () => {
@@ -0,0 +1,16 @@
1
+ import assert from "node:assert/strict";
2
+ import path from "node:path";
3
+ import test from "node:test";
4
+ import { fileURLToPath } from "node:url";
5
+ import { evaluateI18nCatalogContract } from "../../../tooling/test-support/i18nCatalogContract.mjs";
6
+
7
+ const TEST_DIRECTORY = path.dirname(fileURLToPath(import.meta.url));
8
+ const REPO_ROOT = path.resolve(TEST_DIRECTORY, "..", "..", "..");
9
+
10
+ test("auth-provider-supabase-core English catalog matches its source", () => {
11
+ const { problems } = evaluateI18nCatalogContract({
12
+ repoRoot: REPO_ROOT,
13
+ packageDir: path.join(REPO_ROOT, "packages", "auth-provider-supabase-core")
14
+ });
15
+ assert.deepEqual(problems, []);
16
+ });