@fabrika/auth-core 0.5.1 → 0.5.3
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.ts +13 -0
- package/src/endpoint-digest.ts +9 -4
package/package.json
CHANGED
package/src/contract.ts
CHANGED
|
@@ -108,8 +108,21 @@ interface EndpointRowBase {
|
|
|
108
108
|
readonly admission: BodyAdmission | null
|
|
109
109
|
readonly input: SchemaShape | null
|
|
110
110
|
readonly output: OutputShape | null
|
|
111
|
+
/**
|
|
112
|
+
* Whether a page on another origin may call the endpoint (ADR-0022 "Cross-origin endpoints"): `environment` from
|
|
113
|
+
* the origins its environment lists, `any` (a form only) from every origin. Absent unless declared, so every other
|
|
114
|
+
* row keeps its digest. Only an RPC procedure and a form may carry it.
|
|
115
|
+
*/
|
|
116
|
+
readonly crossOrigin?: CrossOriginForm
|
|
111
117
|
}
|
|
112
118
|
|
|
119
|
+
/** How an endpoint admits another origin: from the environment's list, or (a form only) from any origin. */
|
|
120
|
+
export type CrossOriginForm = 'environment' | 'any'
|
|
121
|
+
|
|
122
|
+
/** The endpoint kinds that may declare `crossOrigin`, and the one of them that may admit any origin. */
|
|
123
|
+
export const CROSS_ORIGIN_KINDS: readonly EndpointKind[] = ['query', 'mutation', 'form']
|
|
124
|
+
export const ANY_ORIGIN_KINDS: readonly EndpointKind[] = ['form']
|
|
125
|
+
|
|
113
126
|
export interface CredentialedEndpoint extends EndpointRowBase {
|
|
114
127
|
readonly kind: CredentialedEndpointKind
|
|
115
128
|
readonly callers: readonly [Caller, ...Caller[]]
|
package/src/endpoint-digest.ts
CHANGED
|
@@ -27,7 +27,7 @@ export type EndpointDelegation = 'members' | 'creates'
|
|
|
27
27
|
* installation row adds its OAuth scopes; an application row has no `oauth` field.
|
|
28
28
|
*/
|
|
29
29
|
export type EndpointRules =
|
|
30
|
-
| (Pick<EndpointRow, 'kind' | 'method' | 'path' | 'callers' | 'requirement' | 'admission'> & {
|
|
30
|
+
| (Pick<EndpointRow, 'kind' | 'method' | 'path' | 'callers' | 'requirement' | 'admission' | 'crossOrigin'> & {
|
|
31
31
|
readonly delegation: EndpointDelegation | null
|
|
32
32
|
})
|
|
33
33
|
| (Pick<InstallationEndpointRow, 'kind' | 'method' | 'path' | 'callers' | 'requirement' | 'admission' | 'oauth'> & {
|
|
@@ -64,7 +64,7 @@ export function endpointDigest(artifact: Pick<ContractArtifact, 'dimensions'>, r
|
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
66
|
* The digest of what the proxy applies to an endpoint: its kind, method, path, callers, requirement, admission and
|
|
67
|
-
* delegation,
|
|
67
|
+
* delegation, an installation row's OAuth scopes, and an application row's cross-origin form.
|
|
68
68
|
* Caller, content-type and scope order carry no meaning, so they do not change it; input and output schemas are not
|
|
69
69
|
* part of it, because the proxy does not apply them.
|
|
70
70
|
*/
|
|
@@ -79,9 +79,14 @@ export function requirementDigest(rules: EndpointRules): string {
|
|
|
79
79
|
admission: rules.admission === null ? null : canonicalAdmission(rules.admission),
|
|
80
80
|
delegation: rules.delegation,
|
|
81
81
|
}
|
|
82
|
-
// Only a row that admits `oauth` adds the key, so every
|
|
82
|
+
// Only a row that admits `oauth` or another origin adds the key, so every other row keeps its digest byte for byte.
|
|
83
83
|
const oauth = 'oauth' in rules ? rules.oauth : null
|
|
84
|
-
|
|
84
|
+
const crossOrigin = 'crossOrigin' in rules ? rules.crossOrigin : undefined
|
|
85
|
+
return digestOf(canonicalJson({
|
|
86
|
+
...applied,
|
|
87
|
+
...(oauth === null ? {} : { oauth: { scopes: sortedCodeUnits(oauth.scopes) } }),
|
|
88
|
+
...(crossOrigin === undefined ? {} : { crossOrigin }),
|
|
89
|
+
}))
|
|
85
90
|
}
|
|
86
91
|
|
|
87
92
|
function sortedCodeUnits(values: readonly string[]): string[] {
|