Skip to content

Commit 0225759

Browse files
committed
feat(spec): declare the served auth config features keys and pin the registry to the schema
Claude-Session: https://claude.ai/code/session_01JQwxbaRoocSDkgqwRAGseR Co-authored-by: Claude <noreply@anthropic.com>
1 parent 390bd2a commit 0225759

3 files changed

Lines changed: 165 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
'@objectstack/spec': minor
3+
---
4+
5+
feat(spec): declare the nine remaining served `features` keys on the `GET /api/v1/auth/config` response
6+
7+
Clause-②: yes (widening)
8+
Metadata-protocol: added
9+
10+
`AuthFeaturesConfigSchema` gains nine optional keys that the server already serves in `features` and the console already reads. The contract did not declare them, so a client that parsed the response through `GetAuthConfigResponseSchema` lost all nine, because a plain object schema strips keys it does not know.
11+
12+
- **Flags (booleans):** `multiOrgEnabled` (an organization wall is enforced; default-on, so absent reads as on), `degradedTenancy` (isolation was asked for but is not active), `oidcProvider` (the embedded OIDC authorization server is wired; default-on), `deviceAuthorization` (the device-code CLI login is wired), `admin` (the admin plugin is wired, forced on by SCIM).
13+
- **Values:** `tenancyPosture` (`single` | `group` | `isolated`, the same vocabulary as `TenancyPostureSchema`), `audiencePosture` (`invite_only` | `email_domain` | `open`, the same vocabulary as `AUDIENCE_POSTURES`), `termsUrl` and `privacyUrl` (the legal links under the login card; absent when the operator suppressed them).
14+
- None carries a default: a key the server does not send stays absent.
15+
- A new test holds the schema's declared keys equal to `PUBLIC_AUTH_FEATURES` plus `PUBLIC_AUTH_CONFIG_NON_FLAG_KEYS` (the retired `passkeys` / `magicLink` tombstones excepted), so the next served and classified key cannot be left undeclared.
16+
- The development-only top-level `devSeedAdmin` hint stays undeclared on purpose: it carries the seeded admin's password and no production deployment serves it.
17+
18+
What to do: nothing. Every payload accepted before is accepted unchanged. A client that typed the response from `@objectstack/spec` (for example through `@objectstack/client`'s re-exported `AuthFeaturesConfig`) now sees the nine keys as optional.

‎packages/spec/src/api/auth-endpoints.test.ts‎

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ import {
1111
EndpointMapping,
1212
getAuthEndpointUrl,
1313
} from './auth-endpoints.zod';
14+
import {
15+
PUBLIC_AUTH_CONFIG_NON_FLAG_KEYS,
16+
PUBLIC_AUTH_FEATURE_NAMES,
17+
PUBLIC_AUTH_FEATURES_NOT_ADVERTISED,
18+
} from '../kernel/public-auth-features';
1419

1520
describe('AuthEndpointPaths', () => {
1621
it('should define email/password authentication endpoints', () => {
@@ -176,6 +181,100 @@ describe('AuthFeaturesConfig.sso (served, now declared)', () => {
176181
});
177182
});
178183

184+
// The registry-to-schema pin. plugin-auth's drift guard holds the served
185+
// `features` keys equal to PUBLIC_AUTH_FEATURES plus the non-flag list; this
186+
// holds those same keys equal to what the contract declares, so a key can no
187+
// longer be served and classified while a contract parse strips it.
188+
describe('AuthFeaturesConfig declares every classified served key', () => {
189+
const shape = AuthFeaturesConfigSchema.shape;
190+
const declared = Object.keys(shape);
191+
const retired: readonly string[] = PUBLIC_AUTH_FEATURES_NOT_ADVERTISED;
192+
const classified = [...PUBLIC_AUTH_FEATURE_NAMES, ...PUBLIC_AUTH_CONFIG_NON_FLAG_KEYS];
193+
194+
it('declared keys, retired tombstones excepted, equal the flag registry plus the non-flag list', () => {
195+
expect(declared.filter((key) => !retired.includes(key)).sort()).toEqual([...classified].sort());
196+
});
197+
198+
it('keeps a tombstone for every reserved-but-unadvertised key', () => {
199+
for (const key of retired) expect(declared).toContain(key);
200+
});
201+
202+
it.each([...PUBLIC_AUTH_FEATURE_NAMES])('declares the flag `%s` as an optional boolean', (name) => {
203+
expect(AuthFeaturesConfigSchema.parse({ [name]: true })[name]).toBe(true);
204+
expect(AuthFeaturesConfigSchema.parse({ [name]: false })[name]).toBe(false);
205+
const refused = AuthFeaturesConfigSchema.safeParse({ [name]: 'yes' });
206+
expect(refused.success).toBe(false);
207+
if (refused.success) return;
208+
expect(refused.error.issues).toEqual([
209+
expect.objectContaining({ code: 'invalid_type', expected: 'boolean', path: [name] }),
210+
]);
211+
});
212+
213+
it.each(declared.filter((key) => !retired.includes(key)))('`%s` carries a describe with no tracker id', (key) => {
214+
const description = shape[key as keyof typeof shape].description ?? '';
215+
expect(description.length).toBeGreaterThan(0);
216+
expect(description).not.toMatch(/#\d{3,}/);
217+
});
218+
219+
// The served shape, every key `getPublicConfig()` can put in `features`.
220+
const served = {
221+
twoFactor: false,
222+
organization: true,
223+
multiOrgEnabled: true,
224+
tenancyPosture: 'group',
225+
audiencePosture: 'invite_only',
226+
degradedTenancy: false,
227+
oidcProvider: true,
228+
sso: false,
229+
ssoEnforced: false,
230+
deviceAuthorization: true,
231+
admin: true,
232+
phoneNumber: false,
233+
phoneNumberOtp: false,
234+
cloudManaged: false,
235+
termsUrl: 'https://objectstack.ai/terms',
236+
privacyUrl: 'https://objectstack.ai/privacy',
237+
turnstileSiteKey: '0x4AAAAAAA',
238+
} as const;
239+
240+
it('the served fixture names every classified key, so the parse below covers them all', () => {
241+
expect(Object.keys(served).sort()).toEqual([...classified].sort());
242+
});
243+
244+
it('a whole GET /auth/config response keeps every served features key through a parse', () => {
245+
const parsed = GetAuthConfigResponseSchema.parse({
246+
emailPassword: { enabled: true },
247+
socialProviders: [],
248+
features: served,
249+
});
250+
expect(parsed.features).toEqual(served);
251+
});
252+
253+
it('CONTROL: absent new keys stay absent (no default is invented)', () => {
254+
const parsed = AuthFeaturesConfigSchema.parse({ twoFactor: false, organization: true });
255+
expect(Object.keys(parsed).sort()).toEqual(['organization', 'twoFactor']);
256+
});
257+
258+
it.each([
259+
['tenancyPosture', 'multi'],
260+
['audiencePosture', 'public'],
261+
])('refuses an off-vocabulary `%s` (%j)', (key, value) => {
262+
const result = AuthFeaturesConfigSchema.safeParse({ [key]: value });
263+
expect(result.success).toBe(false);
264+
if (result.success) return;
265+
expect(result.error.issues).toEqual([expect.objectContaining({ code: 'invalid_value', path: [key] })]);
266+
});
267+
268+
it.each(['termsUrl', 'privacyUrl'])('refuses a non-string `%s`', (key) => {
269+
const result = AuthFeaturesConfigSchema.safeParse({ [key]: true });
270+
expect(result.success).toBe(false);
271+
if (result.success) return;
272+
expect(result.error.issues).toEqual([
273+
expect.objectContaining({ code: 'invalid_type', expected: 'string', path: [key] }),
274+
]);
275+
});
276+
});
277+
179278
describe('AuthEndpointAliases', () => {
180279
it('should map common names to canonical endpoints', () => {
181280
expect(AuthEndpointAliases.login).toBe('/sign-in/email');

‎packages/spec/src/api/auth-endpoints.zod.ts‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import { z } from 'zod';
2525
*/
2626
import { lazySchema } from '../shared/lazy-schema';
2727
import { retiredKey } from '../shared/retired-key';
28+
import { TenancyPostureSchema } from '../security/tenancy-posture';
29+
import { AUDIENCE_POSTURES } from '../system/auth-config.zod';
2830
export const AuthEndpointPaths = {
2931
// Email/Password Authentication
3032
signInEmail: '/sign-in/email',
@@ -254,13 +256,59 @@ export const AuthFeaturesConfigSchema = lazySchema(() => z.object({
254256
turnstileSiteKey: z.string().optional().describe(
255257
'Public Cloudflare Turnstile site key, present only while the opt-in sign-up challenge is on: the sign-up form renders the widget and sends its token in the x-captcha-response header; absent means no challenge',
256258
),
259+
// The keys below are served by plugin-auth `getPublicConfig()` (auth-manager.ts,
260+
// the `features` literal) and classified in PUBLIC_AUTH_FEATURES (flags) or
261+
// PUBLIC_AUTH_CONFIG_NON_FLAG_KEYS (values); the registry-to-schema pin in
262+
// auth-endpoints.test.ts keeps the three key sets equal (#29473).
263+
multiOrgEnabled: z.boolean().optional().describe(
264+
'Multi-organization capability: true when the effective tenancy posture enforces an organization wall (group or isolated), the same answer the create-organization door gives; '
265+
+ 'false on a single posture, and on a degraded deployment that asked for isolation but has none. The console offers creating, switching and leaving organizations only when it is on; '
266+
+ 'the flag is default-on, so absent reads as on',
267+
),
268+
tenancyPosture: TenancyPostureSchema.optional().describe(
269+
'Which tenancy posture is in force (single, group or isolated): the effective posture, from the same derivation as multiOrgEnabled. A value, not a gate: multiOrgEnabled stays the capability flag, '
270+
+ 'while this tells the console how to render organization context (under group the organization switcher picks the write target and reads span every organization the member belongs to)',
271+
),
272+
audiencePosture: z.enum(AUDIENCE_POSTURES).optional().describe(
273+
'Who may self-register into this environment (invite_only, email_domain or open): the posture the sign-up path enforces, reported as invite_only when the configured value is off-vocabulary. '
274+
+ 'A value, not a gate: emailPassword.disableSignUp stays the boolean that hides the sign-up form, while this lets the login page say that registration is by invitation instead of offering a form the server refuses',
275+
),
276+
degradedTenancy: z.boolean().optional().describe(
277+
'Degraded tenancy: true when multi-organization isolation was requested but is not active (the deployment booted only because OS_ALLOW_DEGRADED_TENANCY=1), so no engine enforces organization boundaries; '
278+
+ 'the console can raise an operator warning off it. A status signal, not a capability gate; absent means not degraded',
279+
),
280+
oidcProvider: z.boolean().optional().describe(
281+
'Embedded OIDC authorization server wired, from the same decision that mounts it, so OAuth applications can be registered and managed; on by default alongside the MCP surface. '
282+
+ 'It says nothing about sign-in providers, which socialProviders lists; the flag is default-on, so absent reads as on',
283+
),
284+
deviceAuthorization: z.boolean().optional().describe(
285+
'Device authorization (browser-approved CLI login) wired, so the device-code endpoints answer; when false the console device-approval page says device authorization is not enabled instead of calling them. '
286+
+ 'Absent means not wired',
287+
),
288+
admin: z.boolean().optional().describe(
289+
'Admin plugin wired (forced on whenever SCIM is enabled), so user administration (creating, banning, unlocking and impersonating users, setting their passwords) is available; '
290+
+ 'the console shows those actions only when it is true. Absent means not wired',
291+
),
292+
termsUrl: z.string().optional().describe(
293+
'Terms-of-service link shown beneath the login and register cards: the OS_TERMS_URL value when set, otherwise the public ObjectStack terms page; absent when the operator set OS_TERMS_URL to an empty string to suppress the link',
294+
),
295+
privacyUrl: z.string().optional().describe(
296+
'Privacy-policy link shown beneath the login and register cards: the OS_PRIVACY_URL value when set, otherwise the public ObjectStack privacy page; absent when the operator set OS_PRIVACY_URL to an empty string to suppress the link',
297+
),
257298
}));
258299

259300
/**
260301
* Get Auth Config Response
261302
*
262303
* Returns the public authentication configuration that the frontend
263304
* can use to render appropriate login UI (social provider buttons, etc.)
305+
*
306+
* `devSeedAdmin` is deliberately NOT declared here. plugin-auth adds it at the
307+
* top level only under NODE_ENV=development, while the auto-seeded admin still
308+
* signs in with its default password, and it carries that email and password.
309+
* A published response contract would advertise a credential-bearing field that
310+
* no production deployment serves; its one reader, the console LoginPage, reads
311+
* the raw response and never parses it through this schema.
264312
*/
265313
export const GetAuthConfigResponseSchema = lazySchema(() => z.object({
266314
emailPassword: EmailPasswordConfigPublicSchema.describe('Email/password authentication config'),

0 commit comments

Comments
 (0)