@fabrika/auth-core 0.9.0-dev.36 → 0.9.0-dev.38
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 +1 -1
- package/src/contract-canonical.ts +5 -1
- package/src/contract.ts +3 -0
- package/src/index.ts +1 -0
- package/src/scope-values.ts +36 -0
- package/src/types.ts +3 -0
- package/types/src/contract.d.ts +3 -0
- package/types/src/index.d.ts +1 -0
- package/types/src/scope-values.d.ts +14 -0
- package/types/src/types.d.ts +3 -0
package/package.json
CHANGED
|
@@ -32,7 +32,11 @@ export function canonicalizeArtifact(artifact: ContractArtifact): ContractArtifa
|
|
|
32
32
|
return {
|
|
33
33
|
format: artifact.format,
|
|
34
34
|
app: artifact.app,
|
|
35
|
-
dimensions:
|
|
35
|
+
dimensions: mapValues(
|
|
36
|
+
artifact.dimensions,
|
|
37
|
+
(dimension) =>
|
|
38
|
+
dimension.values === undefined ? dimension : { ...dimension, values: [...dimension.values].sort((a, b) => compare(a.value, b.value)) },
|
|
39
|
+
),
|
|
36
40
|
actions: artifact.actions,
|
|
37
41
|
roles: mapValues(artifact.roles, canonicalRole),
|
|
38
42
|
...(artifact.relations === undefined ? {} : { relations: artifact.relations }),
|
package/src/contract.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import type { Locale } from './locale'
|
|
5
5
|
import type { MailTemplates } from './mail'
|
|
6
6
|
import type { DeclaredEgress } from './public-egress'
|
|
7
|
+
import type { DimensionValue } from './scope-values'
|
|
7
8
|
import type { TerminalArtifact } from './terminal'
|
|
8
9
|
|
|
9
10
|
/**
|
|
@@ -497,6 +498,8 @@ export interface DimensionArtifact {
|
|
|
497
498
|
readonly members: { readonly manage: string; readonly list: string } | null
|
|
498
499
|
/** `labels`: the member directory shows labels to `members.list` holders. Absent unless declared, so digests stay. */
|
|
499
500
|
readonly directory?: 'labels'
|
|
501
|
+
/** The values the console offers for a grant in this dimension (ADR-0085). Absent unless declared, so digests stay. */
|
|
502
|
+
readonly values?: readonly DimensionValue[]
|
|
500
503
|
}
|
|
501
504
|
|
|
502
505
|
export interface RoleArtifact {
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// The values a dimension lists for the person who grants (ADR-0085): information for the console, never authorization.
|
|
2
|
+
|
|
3
|
+
import { MAX_MEMBERSHIP_SCOPE_PART_LENGTH } from './membership'
|
|
4
|
+
|
|
5
|
+
/** One value a dimension lists, with the text the console shows beside it. */
|
|
6
|
+
export interface DimensionValue {
|
|
7
|
+
readonly value: string
|
|
8
|
+
readonly label?: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** The most values a dimension lists. */
|
|
12
|
+
export const MAX_DIMENSION_VALUES = 500
|
|
13
|
+
|
|
14
|
+
/** The longest label of a listed value. */
|
|
15
|
+
export const MAX_DIMENSION_VALUE_LABEL_LENGTH = 120
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Why `values` is not a dimension's list, or `null`: at least one and at most `MAX_DIMENSION_VALUES` values, each a
|
|
19
|
+
* non-empty value no longer than a scope value IAM takes, listed once, with a non-empty label when it has one.
|
|
20
|
+
*/
|
|
21
|
+
export function dimensionValuesProblem(values: readonly DimensionValue[]): string | null {
|
|
22
|
+
if (values.length === 0) return 'lists no value (allowed: at least one, or no values field)'
|
|
23
|
+
if (values.length > MAX_DIMENSION_VALUES) return `lists ${values.length} values (allowed: at most ${MAX_DIMENSION_VALUES})`
|
|
24
|
+
const seen = new Set<string>()
|
|
25
|
+
for (const { value, label } of values) {
|
|
26
|
+
if (value === '' || value.length > MAX_MEMBERSHIP_SCOPE_PART_LENGTH) {
|
|
27
|
+
return `lists the value '${value}' (allowed: 1 to ${MAX_MEMBERSHIP_SCOPE_PART_LENGTH} characters)`
|
|
28
|
+
}
|
|
29
|
+
if (seen.has(value)) return `lists the value '${value}' twice`
|
|
30
|
+
seen.add(value)
|
|
31
|
+
if (label !== undefined && (label.trim() === '' || label.length > MAX_DIMENSION_VALUE_LABEL_LENGTH)) {
|
|
32
|
+
return `labels the value '${value}' with '${label}' (allowed: 1 to ${MAX_DIMENSION_VALUE_LABEL_LENGTH} characters)`
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return null
|
|
36
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Locale } from './locale'
|
|
2
2
|
import type { MailTemplates } from './mail'
|
|
3
|
+
import type { DimensionValue } from './scope-values'
|
|
3
4
|
|
|
4
5
|
export type PrincipalType = 'user' | 'service'
|
|
5
6
|
|
|
@@ -163,6 +164,8 @@ export interface AppScopeDef {
|
|
|
163
164
|
* answers a lookup only for one of them, held on the directory's value. Absent, no endpoint looks one up.
|
|
164
165
|
*/
|
|
165
166
|
lookups?: string[]
|
|
167
|
+
/** The values the console offers for a grant in this dimension (ADR-0085); absent, it takes free text. */
|
|
168
|
+
values?: DimensionValue[]
|
|
166
169
|
}
|
|
167
170
|
|
|
168
171
|
/**
|
package/types/src/contract.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Locale } from './locale';
|
|
2
2
|
import type { MailTemplates } from './mail';
|
|
3
3
|
import type { DeclaredEgress } from './public-egress';
|
|
4
|
+
import type { DimensionValue } from './scope-values';
|
|
4
5
|
import type { TerminalArtifact } from './terminal';
|
|
5
6
|
/**
|
|
6
7
|
* The artifact format this release writes. A release that changes the artifact raises it, and Control upcasts every
|
|
@@ -444,6 +445,8 @@ export interface DimensionArtifact {
|
|
|
444
445
|
} | null;
|
|
445
446
|
/** `labels`: the member directory shows labels to `members.list` holders. Absent unless declared, so digests stay. */
|
|
446
447
|
readonly directory?: 'labels';
|
|
448
|
+
/** The values the console offers for a grant in this dimension (ADR-0085). Absent unless declared, so digests stay. */
|
|
449
|
+
readonly values?: readonly DimensionValue[];
|
|
447
450
|
}
|
|
448
451
|
export interface RoleArtifact {
|
|
449
452
|
readonly grants: readonly string[];
|
package/types/src/index.d.ts
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** One value a dimension lists, with the text the console shows beside it. */
|
|
2
|
+
export interface DimensionValue {
|
|
3
|
+
readonly value: string;
|
|
4
|
+
readonly label?: string;
|
|
5
|
+
}
|
|
6
|
+
/** The most values a dimension lists. */
|
|
7
|
+
export declare const MAX_DIMENSION_VALUES = 500;
|
|
8
|
+
/** The longest label of a listed value. */
|
|
9
|
+
export declare const MAX_DIMENSION_VALUE_LABEL_LENGTH = 120;
|
|
10
|
+
/**
|
|
11
|
+
* Why `values` is not a dimension's list, or `null`: at least one and at most `MAX_DIMENSION_VALUES` values, each a
|
|
12
|
+
* non-empty value no longer than a scope value IAM takes, listed once, with a non-empty label when it has one.
|
|
13
|
+
*/
|
|
14
|
+
export declare function dimensionValuesProblem(values: readonly DimensionValue[]): string | null;
|
package/types/src/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Locale } from './locale';
|
|
2
2
|
import type { MailTemplates } from './mail';
|
|
3
|
+
import type { DimensionValue } from './scope-values';
|
|
3
4
|
export type PrincipalType = 'user' | 'service';
|
|
4
5
|
/**
|
|
5
6
|
* Whether a person belongs to the organization (ADR-0051). An `external` principal holds only grants of a role its
|
|
@@ -132,6 +133,8 @@ export interface AppScopeDef {
|
|
|
132
133
|
* answers a lookup only for one of them, held on the directory's value. Absent, no endpoint looks one up.
|
|
133
134
|
*/
|
|
134
135
|
lookups?: string[];
|
|
136
|
+
/** The values the console offers for a grant in this dimension (ADR-0085); absent, it takes free text. */
|
|
137
|
+
values?: DimensionValue[];
|
|
135
138
|
}
|
|
136
139
|
/**
|
|
137
140
|
* The role keys IAM defines itself for every app. A built-in wins over an app role of the same key at
|