@fabrika/auth 0.9.0-dev.11 → 0.9.0-dev.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabrika/auth",
3
- "version": "0.9.0-dev.11",
3
+ "version": "0.9.0-dev.13",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -23,13 +23,13 @@
23
23
  }
24
24
  },
25
25
  "scripts": {
26
- "typecheck": "tsc --noEmit",
26
+ "typecheck": "tsrs --build tsconfig.test.json",
27
27
  "test": "bun test"
28
28
  },
29
29
  "dependencies": {
30
30
  "zod": "^3.25.76",
31
- "@fabrika/auth-core": "0.9.0-dev.11",
32
- "@fabrika/jwks": "0.9.0-dev.11",
31
+ "@fabrika/auth-core": "0.9.0-dev.13",
32
+ "@fabrika/jwks": "0.9.0-dev.13",
33
33
  "jose": "^5.9.0"
34
34
  }
35
35
  }
package/src/app-schema.ts CHANGED
@@ -4,6 +4,7 @@ import {
4
4
  displayNameProblem,
5
5
  isActionAllowed,
6
6
  isOwnWorkloadName,
7
+ isReservedScopeType,
7
8
  LOCALES,
8
9
  mailTemplateProblems,
9
10
  type MessageKind,
@@ -19,7 +20,7 @@ const quote = (value: string): string => `\`${value.slice(0, 80)}\``
19
20
  const keySchema = z.string().min(1).refine((key) => key !== '__proto__')
20
21
 
21
22
  const scopeSchema = z.object({
22
- type: z.string().min(1),
23
+ type: z.string().min(1).refine((type) => !isReservedScopeType(type), 'a scope type never starts with ~ (IAM reserves it)'),
23
24
  label: z.string().min(1).optional(),
24
25
  in: z.string().min(1).optional(),
25
26
  creator: z.string().min(1).optional(),
@@ -34,6 +35,7 @@ const roleSchema = z.object({
34
35
  permissions: z.array(z.string().min(1)),
35
36
  member: z.object({ scope: z.string().min(1), assignableBy: z.array(z.string().min(1)).optional() }).optional(),
36
37
  external: z.literal(true).optional(),
38
+ via: z.record(z.string().min(1), z.array(z.string().min(1)).min(1)).optional(),
37
39
  })
38
40
  /** A link lives at most a year; the mount's `maxDays` is the bound a contract states below that. */
39
41
  const MAX_LINK_DAYS = 365
@@ -276,6 +278,24 @@ export const appSchemaSchema = appSchemaShape.superRefine((schema, ctx) => {
276
278
  })
277
279
  }
278
280
  }
281
+ for (const [relation, actions] of Object.entries(role.via ?? {})) {
282
+ if (role.member !== undefined || role.external === true) {
283
+ ctx.addIssue({
284
+ code: 'custom',
285
+ path: ['roles', key, 'via'],
286
+ message: `role ${quote(key)} holds actions via a relation and is a membership or external role`,
287
+ })
288
+ }
289
+ for (const [index, action] of actions.entries()) {
290
+ if (!catalog.includes(action)) {
291
+ ctx.addIssue({
292
+ code: 'custom',
293
+ path: ['roles', key, 'via', relation, index],
294
+ message: `role ${quote(key)} holds an unknown action via ${quote(relation)}: ${quote(action)}`,
295
+ })
296
+ }
297
+ }
298
+ }
279
299
  if (role.member !== undefined && !scopes.includes(role.member.scope)) {
280
300
  ctx.addIssue({
281
301
  code: 'custom',
package/src/membership.ts CHANGED
@@ -43,7 +43,10 @@ export class IamMembership {
43
43
  private readonly appId: string,
44
44
  ) {}
45
45
 
46
- /** A single-use grant for one request to `endpoint`, which the app's schema lists as a membership endpoint. */
46
+ /**
47
+ * A single-use grant for one request to `endpoint`. IAM refuses it on every application transport (ADR-0022 rule 6):
48
+ * only the proxy obtains one, and the application spends the grant the proxy forwards.
49
+ */
47
50
  requestDelegation(caller: MembershipRequestCaller, endpoint: string): Promise<RequestDelegationResult> {
48
51
  return this.binding.requestDelegation({ ...this.caller(caller), endpoint })
49
52
  }
@@ -7,7 +7,7 @@ import { z } from 'zod';
7
7
  */
8
8
  export declare const appSchemaSchema: z.ZodEffects<z.ZodObject<{
9
9
  scopes: z.ZodArray<z.ZodObject<{
10
- type: z.ZodString;
10
+ type: z.ZodEffects<z.ZodString, string, string>;
11
11
  label: z.ZodOptional<z.ZodString>;
12
12
  in: z.ZodOptional<z.ZodString>;
13
13
  creator: z.ZodOptional<z.ZodString>;
@@ -71,6 +71,7 @@ export declare const appSchemaSchema: z.ZodEffects<z.ZodObject<{
71
71
  assignableBy?: string[] | undefined;
72
72
  }>>;
73
73
  external: z.ZodOptional<z.ZodLiteral<true>>;
74
+ via: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>>;
74
75
  }, "strip", z.ZodTypeAny, {
75
76
  name: string;
76
77
  permissions: string[];
@@ -79,6 +80,7 @@ export declare const appSchemaSchema: z.ZodEffects<z.ZodObject<{
79
80
  scope: string;
80
81
  assignableBy?: string[] | undefined;
81
82
  } | undefined;
83
+ via?: Record<string, string[]> | undefined;
82
84
  description?: string | undefined;
83
85
  }, {
84
86
  name: string;
@@ -88,6 +90,7 @@ export declare const appSchemaSchema: z.ZodEffects<z.ZodObject<{
88
90
  scope: string;
89
91
  assignableBy?: string[] | undefined;
90
92
  } | undefined;
93
+ via?: Record<string, string[]> | undefined;
91
94
  description?: string | undefined;
92
95
  }>>;
93
96
  contract: z.ZodOptional<z.ZodBoolean>;
@@ -302,6 +305,7 @@ export declare const appSchemaSchema: z.ZodEffects<z.ZodObject<{
302
305
  scope: string;
303
306
  assignableBy?: string[] | undefined;
304
307
  } | undefined;
308
+ via?: Record<string, string[]> | undefined;
305
309
  description?: string | undefined;
306
310
  }>;
307
311
  scopes: {
@@ -386,6 +390,7 @@ export declare const appSchemaSchema: z.ZodEffects<z.ZodObject<{
386
390
  scope: string;
387
391
  assignableBy?: string[] | undefined;
388
392
  } | undefined;
393
+ via?: Record<string, string[]> | undefined;
389
394
  description?: string | undefined;
390
395
  }>;
391
396
  scopes: {
@@ -470,6 +475,7 @@ export declare const appSchemaSchema: z.ZodEffects<z.ZodObject<{
470
475
  scope: string;
471
476
  assignableBy?: string[] | undefined;
472
477
  } | undefined;
478
+ via?: Record<string, string[]> | undefined;
473
479
  description?: string | undefined;
474
480
  }>;
475
481
  scopes: {
@@ -554,6 +560,7 @@ export declare const appSchemaSchema: z.ZodEffects<z.ZodObject<{
554
560
  scope: string;
555
561
  assignableBy?: string[] | undefined;
556
562
  } | undefined;
563
+ via?: Record<string, string[]> | undefined;
557
564
  description?: string | undefined;
558
565
  }>;
559
566
  scopes: {
@@ -23,7 +23,10 @@ export declare class IamMembership {
23
23
  private readonly binding;
24
24
  private readonly appId;
25
25
  constructor(binding: IamMembershipRpc, appId: string);
26
- /** A single-use grant for one request to `endpoint`, which the app's schema lists as a membership endpoint. */
26
+ /**
27
+ * A single-use grant for one request to `endpoint`. IAM refuses it on every application transport (ADR-0022 rule 6):
28
+ * only the proxy obtains one, and the application spends the grant the proxy forwards.
29
+ */
27
30
  requestDelegation(caller: MembershipRequestCaller, endpoint: string): Promise<RequestDelegationResult>;
28
31
  /** A new value of `dimension`, with the caller granted the dimension's creator role in it. */
29
32
  createScope(caller: MembershipRequestCaller, delegation: string, dimension: string): Promise<CreateScopeResult>;