@toa.io/extensions.exposition 1.0.0-alpha.20 → 1.0.0-alpha.22
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/components/context.toa.yaml +2 -2
- package/components/identity.basic/manifest.toa.yaml +18 -9
- package/components/identity.basic/operations/authenticate.d.ts +5 -1
- package/components/identity.basic/operations/authenticate.js +2 -2
- package/components/identity.basic/operations/authenticate.js.map +1 -1
- package/components/identity.basic/operations/incept.d.ts +11 -0
- package/components/identity.basic/operations/incept.js +13 -0
- package/components/identity.basic/operations/incept.js.map +1 -0
- package/components/identity.basic/operations/transit.d.ts +3 -3
- package/components/identity.basic/operations/transit.js +5 -3
- package/components/identity.basic/operations/transit.js.map +1 -1
- package/components/identity.basic/operations/tsconfig.tsbuildinfo +1 -1
- package/components/identity.basic/operations/types.d.ts +2 -0
- package/components/identity.basic/source/authenticate.ts +12 -5
- package/components/identity.basic/source/incept.ts +22 -0
- package/components/identity.basic/source/transit.ts +7 -5
- package/components/identity.basic/source/types.ts +2 -0
- package/components/identity.federation/manifest.toa.yaml +28 -11
- package/components/identity.federation/operations/authenticate.d.ts +2 -2
- package/components/identity.federation/operations/authenticate.js +6 -5
- package/components/identity.federation/operations/authenticate.js.map +1 -1
- package/components/identity.federation/operations/incept.d.ts +11 -0
- package/components/identity.federation/operations/{create.js → incept.js} +6 -7
- package/components/identity.federation/operations/incept.js.map +1 -0
- package/components/identity.federation/operations/lib/jwt.js +3 -3
- package/components/identity.federation/operations/lib/jwt.js.map +1 -1
- package/components/identity.federation/operations/schemas.d.ts +7 -3
- package/components/identity.federation/operations/tsconfig.tsbuildinfo +1 -1
- package/components/identity.federation/operations/types.d.ts +5 -0
- package/components/identity.federation/source/authenticate.ts +9 -6
- package/components/identity.federation/source/{create.ts → incept.ts} +10 -9
- package/components/identity.federation/source/lib/jwt.test.ts +2 -2
- package/components/identity.federation/source/lib/jwt.ts +3 -3
- package/components/identity.federation/source/schemas.ts +7 -3
- package/components/identity.federation/source/types.ts +6 -0
- package/components/identity.tokens/manifest.toa.yaml +7 -1
- package/components/identity.tokens/operations/authenticate.d.ts +2 -2
- package/components/identity.tokens/operations/authenticate.js +5 -2
- package/components/identity.tokens/operations/authenticate.js.map +1 -1
- package/components/identity.tokens/operations/decrypt.js +1 -0
- package/components/identity.tokens/operations/decrypt.js.map +1 -1
- package/components/identity.tokens/operations/encrypt.js +1 -0
- package/components/identity.tokens/operations/encrypt.js.map +1 -1
- package/components/identity.tokens/operations/tsconfig.tsbuildinfo +1 -1
- package/components/identity.tokens/operations/types.d.ts +7 -0
- package/components/identity.tokens/source/authenticate.test.ts +11 -4
- package/components/identity.tokens/source/authenticate.ts +7 -3
- package/components/identity.tokens/source/decrypt.test.ts +5 -3
- package/components/identity.tokens/source/decrypt.ts +9 -8
- package/components/identity.tokens/source/encrypt.test.ts +4 -1
- package/components/identity.tokens/source/encrypt.ts +1 -0
- package/components/identity.tokens/source/types.ts +8 -0
- package/documentation/authorities.md +53 -0
- package/documentation/components.md +3 -3
- package/documentation/identity.md +17 -22
- package/documentation/require.md +1 -1
- package/documentation/vary.md +5 -11
- package/features/access.feature +55 -7
- package/features/annotation.feature +1 -0
- package/features/authorities.basic.feature +140 -0
- package/features/authorities.feature +32 -0
- package/features/authorities.federation.feature +99 -0
- package/features/authorities.tokens.feature +118 -0
- package/features/body.feature +2 -0
- package/features/cache.feature +39 -5
- package/features/cors.feature +4 -0
- package/features/directives.feature +3 -0
- package/features/dynamic.feature +4 -0
- package/features/errors.feature +12 -1
- package/features/etag.feature +6 -0
- package/features/identity.bans.feature +12 -3
- package/features/identity.basic.feature +34 -15
- package/features/identity.feature +7 -2
- package/features/identity.federation.feature +14 -4
- package/features/identity.roles.feature +29 -17
- package/features/identity.tokens.feature +18 -6
- package/features/io.feature +9 -0
- package/features/octets.entries.feature +8 -0
- package/features/octets.feature +22 -0
- package/features/octets.meta.feature +3 -0
- package/features/octets.workflows.feature +13 -0
- package/features/queries.feature +8 -0
- package/features/require.feature +3 -0
- package/features/response.feature +5 -2
- package/features/routes.feature +7 -0
- package/features/steps/Gateway.ts +23 -6
- package/features/streams.feature +1 -0
- package/features/timing.feature +3 -0
- package/features/vary.feature +49 -0
- package/package.json +7 -7
- package/readme.md +19 -14
- package/schemas/annotation.cos.yaml +1 -1
- package/source/Annotation.ts +3 -3
- package/source/Endpoint.ts +1 -1
- package/source/Factory.ts +8 -10
- package/source/Gateway.ts +2 -6
- package/source/HTTP/Context.ts +3 -1
- package/source/HTTP/Server.ts +23 -26
- package/source/HTTP/exceptions.ts +6 -0
- package/source/Query.ts +9 -5
- package/source/deployment.ts +25 -21
- package/source/directives/auth/Authorization.ts +18 -8
- package/source/directives/auth/Incept.ts +2 -1
- package/source/directives/vary/embeddings/Authority.ts +8 -0
- package/source/directives/vary/embeddings/index.ts +3 -1
- package/source/schemas.ts +1 -1
- package/transpiled/Annotation.d.ts +3 -3
- package/transpiled/Endpoint.js +1 -1
- package/transpiled/Endpoint.js.map +1 -1
- package/transpiled/Factory.js +9 -8
- package/transpiled/Factory.js.map +1 -1
- package/transpiled/Gateway.js.map +1 -1
- package/transpiled/HTTP/Context.d.ts +2 -1
- package/transpiled/HTTP/Context.js +3 -1
- package/transpiled/HTTP/Context.js.map +1 -1
- package/transpiled/HTTP/Server.d.ts +8 -1
- package/transpiled/HTTP/Server.js +14 -20
- package/transpiled/HTTP/Server.js.map +1 -1
- package/transpiled/HTTP/exceptions.d.ts +3 -0
- package/transpiled/HTTP/exceptions.js +7 -1
- package/transpiled/HTTP/exceptions.js.map +1 -1
- package/transpiled/Query.js +2 -2
- package/transpiled/Query.js.map +1 -1
- package/transpiled/deployment.d.ts +1 -1
- package/transpiled/deployment.js +21 -19
- package/transpiled/deployment.js.map +1 -1
- package/transpiled/directives/auth/Authorization.js +9 -4
- package/transpiled/directives/auth/Authorization.js.map +1 -1
- package/transpiled/directives/auth/Incept.js +2 -1
- package/transpiled/directives/auth/Incept.js.map +1 -1
- package/transpiled/directives/vary/embeddings/Authority.d.ts +5 -0
- package/transpiled/directives/vary/embeddings/Authority.js +10 -0
- package/transpiled/directives/vary/embeddings/Authority.js.map +1 -0
- package/transpiled/directives/vary/embeddings/index.js +3 -1
- package/transpiled/directives/vary/embeddings/index.js.map +1 -1
- package/transpiled/schemas.d.ts +1 -1
- package/transpiled/schemas.js +2 -2
- package/transpiled/schemas.js.map +1 -1
- package/transpiled/tsconfig.tsbuildinfo +1 -1
- package/components/identity.basic/operations/create.d.ts +0 -10
- package/components/identity.basic/operations/create.js +0 -10
- package/components/identity.basic/operations/create.js.map +0 -1
- package/components/identity.basic/source/create.ts +0 -18
- package/components/identity.federation/operations/create.d.ts +0 -10
- package/components/identity.federation/operations/create.js.map +0 -1
- package/source/HTTP/Server.test.ts +0 -126
package/source/HTTP/Context.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { OutgoingMessage } from './messages'
|
|
|
6
6
|
import type * as http from 'node:http'
|
|
7
7
|
|
|
8
8
|
export class Context {
|
|
9
|
+
public readonly authority: string
|
|
9
10
|
public readonly request: IncomingMessage
|
|
10
11
|
public readonly url: URL
|
|
11
12
|
public readonly subtype: string | null = null
|
|
@@ -17,7 +18,8 @@ export class Context {
|
|
|
17
18
|
response: []
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
public constructor (request: IncomingMessage, trace = false) {
|
|
21
|
+
public constructor (authority: string, request: IncomingMessage, trace = false) {
|
|
22
|
+
this.authority = authority
|
|
21
23
|
this.request = request
|
|
22
24
|
|
|
23
25
|
this.url = new URL(request.url, `https://${request.headers.host}`)
|
package/source/HTTP/Server.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import fs from 'node:fs'
|
|
2
2
|
import os from 'node:os'
|
|
3
3
|
import * as http from 'node:http'
|
|
4
|
-
import assert from 'node:assert'
|
|
5
4
|
import { once } from 'node:events'
|
|
6
5
|
import { Connector } from '@toa.io/core'
|
|
7
|
-
import { promex } from '@toa.io/generic'
|
|
8
6
|
import { type OutgoingMessage, write } from './messages'
|
|
9
7
|
import { ClientError, Exception } from './exceptions'
|
|
10
8
|
import { Context } from './Context'
|
|
@@ -13,12 +11,14 @@ import type { IncomingMessage } from './Context'
|
|
|
13
11
|
export class Server extends Connector {
|
|
14
12
|
private readonly server: http.Server = http.createServer()
|
|
15
13
|
private readonly properties: Properties
|
|
14
|
+
private readonly authorities: Record<string, string>
|
|
16
15
|
private process?: Processing
|
|
17
16
|
|
|
18
17
|
private constructor (properties: Properties) {
|
|
19
18
|
super()
|
|
20
19
|
|
|
21
20
|
this.properties = properties
|
|
21
|
+
this.authorities = Object.fromEntries(Object.entries(properties.authorities).map(([key, value]) => [value, key]))
|
|
22
22
|
|
|
23
23
|
this.server.on('request', (req, res) => this.listener(req, res))
|
|
24
24
|
}
|
|
@@ -35,10 +35,8 @@ export class Server extends Connector {
|
|
|
35
35
|
return address.port
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
public static create (options
|
|
39
|
-
const properties =
|
|
40
|
-
? DEFAULTS
|
|
41
|
-
: { ...DEFAULTS, ...options }
|
|
38
|
+
public static create (options: Options): Server {
|
|
39
|
+
const properties: Properties = Object.assign({}, DEFAULTS, options)
|
|
42
40
|
|
|
43
41
|
return new Server(properties)
|
|
44
42
|
}
|
|
@@ -72,18 +70,16 @@ export class Server extends Connector {
|
|
|
72
70
|
return
|
|
73
71
|
}
|
|
74
72
|
|
|
75
|
-
if (request.
|
|
76
|
-
response.writeHead(
|
|
73
|
+
if (request.headers.host === undefined || !(request.headers.host in this.authorities)) {
|
|
74
|
+
response.writeHead(404).end('Unknown authority')
|
|
77
75
|
|
|
78
76
|
return
|
|
79
77
|
}
|
|
80
78
|
|
|
81
|
-
|
|
82
|
-
|
|
79
|
+
const authority = this.authorities[request.headers.host]
|
|
80
|
+
const context = new Context(authority, request as IncomingMessage, this.properties.trace)
|
|
83
81
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
this.process(context)
|
|
82
|
+
this.process!(context)
|
|
87
83
|
.then(this.success(context, response))
|
|
88
84
|
.catch(this.fail(context, response))
|
|
89
85
|
}
|
|
@@ -112,17 +108,16 @@ export class Server extends Connector {
|
|
|
112
108
|
if (!context.request.complete)
|
|
113
109
|
await adam(context.request)
|
|
114
110
|
|
|
115
|
-
response.statusCode = exception instanceof Exception
|
|
116
|
-
? exception.status
|
|
117
|
-
: 500
|
|
111
|
+
response.statusCode = exception instanceof Exception ? exception.status : 500
|
|
118
112
|
|
|
119
113
|
const message: OutgoingMessage = { status: response.statusCode }
|
|
120
114
|
const verbose = exception instanceof ClientError || this.properties.debug
|
|
121
115
|
|
|
122
116
|
if (verbose)
|
|
123
|
-
message.body =
|
|
124
|
-
|
|
125
|
-
|
|
117
|
+
message.body =
|
|
118
|
+
exception instanceof Exception
|
|
119
|
+
? exception.body
|
|
120
|
+
: exception.stack ?? exception.message
|
|
126
121
|
|
|
127
122
|
write(context, response, message)
|
|
128
123
|
}
|
|
@@ -130,18 +125,15 @@ export class Server extends Connector {
|
|
|
130
125
|
}
|
|
131
126
|
|
|
132
127
|
// https://github.com/whatwg/fetch/issues/1254
|
|
133
|
-
async function adam (request: http.IncomingMessage): Promise<
|
|
134
|
-
const completed = promex()
|
|
128
|
+
async function adam (request: http.IncomingMessage): Promise<any> {
|
|
135
129
|
const devnull = fs.createWriteStream(os.devNull)
|
|
136
130
|
|
|
137
|
-
request
|
|
138
|
-
.on('end', completed.callback)
|
|
139
|
-
.pipe(devnull)
|
|
131
|
+
request.pipe(devnull)
|
|
140
132
|
|
|
141
|
-
return
|
|
133
|
+
return once(request, 'end')
|
|
142
134
|
}
|
|
143
135
|
|
|
144
|
-
const DEFAULTS: Properties = {
|
|
136
|
+
const DEFAULTS: Omit<Properties, 'authorities'> = {
|
|
145
137
|
methods: new Set<string>(['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS']),
|
|
146
138
|
debug: false,
|
|
147
139
|
trace: false,
|
|
@@ -149,10 +141,15 @@ const DEFAULTS: Properties = {
|
|
|
149
141
|
}
|
|
150
142
|
|
|
151
143
|
interface Properties {
|
|
144
|
+
authorities: Record<string, string>
|
|
152
145
|
methods: Set<string>
|
|
153
146
|
debug: boolean
|
|
154
147
|
trace: boolean
|
|
155
148
|
port: number
|
|
156
149
|
}
|
|
157
150
|
|
|
151
|
+
export type Options = { authorities: Properties['authorities'] } & {
|
|
152
|
+
[K in Exclude<keyof Properties, 'authorities'>]?: Properties[K]
|
|
153
|
+
}
|
|
154
|
+
|
|
158
155
|
export type Processing = (input: Context) => Promise<OutgoingMessage>
|
|
@@ -42,6 +42,12 @@ export class Conflict extends ClientError {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
export class UnprocessableEntity extends ClientError {
|
|
46
|
+
public constructor (body?: any) {
|
|
47
|
+
super(422, body)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
45
51
|
export class MethodNotAllowed extends ClientError {
|
|
46
52
|
public constructor () {
|
|
47
53
|
super(405)
|
package/source/Query.ts
CHANGED
|
@@ -12,8 +12,10 @@ export class Query {
|
|
|
12
12
|
if (query.criteria !== undefined) {
|
|
13
13
|
const open = query.criteria[query.criteria.length - 1] === ';'
|
|
14
14
|
|
|
15
|
-
if (open)
|
|
16
|
-
|
|
15
|
+
if (open)
|
|
16
|
+
query.criteria = query.criteria.slice(0, -1)
|
|
17
|
+
else
|
|
18
|
+
this.closed = true
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
this.query = query
|
|
@@ -55,8 +57,10 @@ export class Query {
|
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
if (query.criteria !== undefined)
|
|
58
|
-
if (this.closed)
|
|
59
|
-
|
|
60
|
+
if (this.closed)
|
|
61
|
+
throw new http.BadRequest('Query criteria is closed')
|
|
62
|
+
else
|
|
63
|
+
criteria.push(query.criteria)
|
|
60
64
|
|
|
61
65
|
switch (criteria.length) {
|
|
62
66
|
case 0:
|
|
@@ -99,7 +103,7 @@ function fit (string: string, range: [number, number], name: string): number {
|
|
|
99
103
|
|
|
100
104
|
if (number < range[0] || number > range[1])
|
|
101
105
|
throw new http.BadRequest(`Query ${name} must be between ` +
|
|
102
|
-
`${range[0]} and ${range[1]} inclusive
|
|
106
|
+
`${range[0]} and ${range[1]} inclusive`)
|
|
103
107
|
|
|
104
108
|
return number
|
|
105
109
|
}
|
package/source/deployment.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import assert from 'node:assert'
|
|
1
2
|
import { type Dependency, type Service } from '@toa.io/operations'
|
|
2
3
|
import { encode } from '@toa.io/generic'
|
|
3
4
|
import { type Annotation } from './Annotation'
|
|
@@ -6,7 +7,10 @@ import { shortcuts } from './Directive'
|
|
|
6
7
|
import { components } from './Composition'
|
|
7
8
|
import { parse } from './RTD/syntax'
|
|
8
9
|
|
|
9
|
-
export function deployment (_: unknown, annotation
|
|
10
|
+
export function deployment (_: unknown, annotation?: Annotation): Dependency {
|
|
11
|
+
assert.ok(annotation !== undefined, 'Exposition context annotation is required')
|
|
12
|
+
schemas.annotation.validate(annotation)
|
|
13
|
+
|
|
10
14
|
const labels = components().labels
|
|
11
15
|
|
|
12
16
|
const service: Service = {
|
|
@@ -16,16 +20,10 @@ export function deployment (_: unknown, annotation: Annotation | undefined): Dep
|
|
|
16
20
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
17
21
|
version: require('../package.json').version,
|
|
18
22
|
variables: [],
|
|
19
|
-
components: labels
|
|
23
|
+
components: labels,
|
|
24
|
+
ingress: { hosts: [] }
|
|
20
25
|
}
|
|
21
26
|
|
|
22
|
-
if (annotation?.host !== undefined)
|
|
23
|
-
service.ingress = {
|
|
24
|
-
host: annotation.host,
|
|
25
|
-
class: annotation.class,
|
|
26
|
-
annotations: annotation.annotations
|
|
27
|
-
}
|
|
28
|
-
|
|
29
27
|
if (annotation?.['/'] !== undefined) {
|
|
30
28
|
const tree = parse(annotation['/'], shortcuts)
|
|
31
29
|
|
|
@@ -35,20 +33,26 @@ export function deployment (_: unknown, annotation: Annotation | undefined): Dep
|
|
|
35
33
|
})
|
|
36
34
|
}
|
|
37
35
|
|
|
38
|
-
|
|
39
|
-
service.variables.push({
|
|
40
|
-
name: 'TOA_EXPOSITION_DEBUG',
|
|
41
|
-
value: '1'
|
|
42
|
-
})
|
|
36
|
+
const { debug, trace, authorities } = annotation
|
|
43
37
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
38
|
+
service.ingress.hosts = Object.values(authorities)
|
|
39
|
+
service.ingress.class = annotation.class
|
|
40
|
+
service.ingress.annotations = annotation.annotations
|
|
41
|
+
|
|
42
|
+
const properties: Properties = { authorities }
|
|
43
|
+
|
|
44
|
+
if (debug === true)
|
|
45
|
+
properties.debug = true
|
|
49
46
|
|
|
50
|
-
if (
|
|
51
|
-
|
|
47
|
+
if (trace === true)
|
|
48
|
+
properties.trace = true
|
|
49
|
+
|
|
50
|
+
service.variables.push({
|
|
51
|
+
name: 'TOA_EXPOSITION_PROPERTIES',
|
|
52
|
+
value: encode(properties)
|
|
53
|
+
})
|
|
52
54
|
|
|
53
55
|
return { services: [service] }
|
|
54
56
|
}
|
|
57
|
+
|
|
58
|
+
type Properties = Pick<Annotation, 'authorities' | 'debug' | 'trace'>
|
|
@@ -56,7 +56,7 @@ export class Authorization implements DirectiveFamily<Directive, Extension> {
|
|
|
56
56
|
public async preflight (directives: Directive[],
|
|
57
57
|
input: Input,
|
|
58
58
|
parameters: Parameter[]): Promise<Output> {
|
|
59
|
-
const identity = await this.resolve(input.request.headers.authorization)
|
|
59
|
+
const identity = await this.resolve(input.authority, input.request.headers.authorization)
|
|
60
60
|
|
|
61
61
|
input.identity = identity
|
|
62
62
|
|
|
@@ -80,16 +80,22 @@ export class Authorization implements DirectiveFamily<Directive, Extension> {
|
|
|
80
80
|
|
|
81
81
|
const identity = request.identity
|
|
82
82
|
|
|
83
|
-
if (identity === null)
|
|
83
|
+
if (identity === null)
|
|
84
|
+
return
|
|
84
85
|
|
|
85
|
-
if (identity.scheme === PRIMARY && !identity.refresh)
|
|
86
|
+
if (identity.scheme === PRIMARY && !identity.refresh)
|
|
87
|
+
return
|
|
86
88
|
|
|
87
89
|
// Role directive may have already set the value
|
|
88
|
-
if (identity.roles === undefined)
|
|
90
|
+
if (identity.roles === undefined)
|
|
91
|
+
await Role.set(identity, this.discovery.roles)
|
|
89
92
|
|
|
90
93
|
this.tokens ??= await this.discovery.tokens
|
|
91
94
|
|
|
92
|
-
const token = await this.tokens.invoke<string>('encrypt', {
|
|
95
|
+
const token = await this.tokens.invoke<string>('encrypt', {
|
|
96
|
+
input: { authority: request.authority, identity }
|
|
97
|
+
})
|
|
98
|
+
|
|
93
99
|
const authorization = `Token ${token}`
|
|
94
100
|
|
|
95
101
|
response.headers ??= new Headers()
|
|
@@ -97,8 +103,9 @@ export class Authorization implements DirectiveFamily<Directive, Extension> {
|
|
|
97
103
|
response.headers.append('cache-control', 'no-store')
|
|
98
104
|
}
|
|
99
105
|
|
|
100
|
-
private async resolve (authorization: string | undefined): Promise<Identity | null> {
|
|
101
|
-
if (authorization === undefined)
|
|
106
|
+
private async resolve (authority: string, authorization: string | undefined): Promise<Identity | null> {
|
|
107
|
+
if (authorization === undefined)
|
|
108
|
+
return null
|
|
102
109
|
|
|
103
110
|
const [scheme, credentials] = split(authorization)
|
|
104
111
|
const provider = PROVIDERS[scheme]
|
|
@@ -109,7 +116,10 @@ export class Authorization implements DirectiveFamily<Directive, Extension> {
|
|
|
109
116
|
this.schemes[scheme] ??= await this.discovery[provider]
|
|
110
117
|
|
|
111
118
|
const result = await this.schemes[scheme].invoke<AuthenticationResult>('authenticate', {
|
|
112
|
-
input:
|
|
119
|
+
input: {
|
|
120
|
+
authority,
|
|
121
|
+
credentials
|
|
122
|
+
}
|
|
113
123
|
})
|
|
114
124
|
|
|
115
125
|
if (result instanceof Error) return null
|
|
@@ -31,8 +31,9 @@ export class Incept implements Directive {
|
|
|
31
31
|
this.schemes[scheme] ??= await this.discovery[provider]
|
|
32
32
|
|
|
33
33
|
const identity = await this.schemes[scheme]
|
|
34
|
-
.invoke<Maybe<Identity>>('
|
|
34
|
+
.invoke<Maybe<Identity>>('incept', {
|
|
35
35
|
input: {
|
|
36
|
+
authority: input.authority,
|
|
36
37
|
id,
|
|
37
38
|
credentials
|
|
38
39
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { Language } from './Language'
|
|
2
|
+
import { Authority } from './Authority'
|
|
2
3
|
import type { Embedding } from './Embedding'
|
|
3
4
|
|
|
4
5
|
export const embeddings: Record<string, new () => Embedding> = {
|
|
5
|
-
language: Language
|
|
6
|
+
language: Language,
|
|
7
|
+
authority: Authority
|
|
6
8
|
}
|
|
7
9
|
|
|
8
10
|
export type { Embedding }
|
package/source/schemas.ts
CHANGED
|
@@ -9,5 +9,5 @@ const path = resolve(__dirname, '../schemas')
|
|
|
9
9
|
const namespace = schemas.namespace(path)
|
|
10
10
|
|
|
11
11
|
export const querystring: Schema<Query> = namespace.schema('querystring')
|
|
12
|
-
export const
|
|
12
|
+
export const annotation: Schema<Annotation> = namespace.schema('annotation')
|
|
13
13
|
export const node: Schema<Node> = namespace.schema('node')
|
package/transpiled/Endpoint.js
CHANGED
|
@@ -43,7 +43,7 @@ class Endpoint {
|
|
|
43
43
|
this.remote ??= await this.discovery;
|
|
44
44
|
const reply = await this.remote.invoke(this.endpoint, request);
|
|
45
45
|
if (reply instanceof Error)
|
|
46
|
-
throw new http.
|
|
46
|
+
throw new http.UnprocessableEntity(reply);
|
|
47
47
|
const message = {};
|
|
48
48
|
if (typeof reply === 'object' && reply !== null && '_version' in reply) {
|
|
49
49
|
const etag = context.request.headers['if-none-match'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Endpoint.js","sourceRoot":"","sources":["../source/Endpoint.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,uCAA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,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,SAAS,EAAE,SAAS,CAAA;QAC1E,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,SAAS,EAAE,SAAS,CAAA;QAE1E,IAAI,SAAS,KAAK,SAAS,IAAI,SAAS,KAAK,SAAS;YACpD,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAA;QAElE,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC,CAAA;QAE7D,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,CAAA;IAClE,CAAC;CACF;AAtBD,4CAsBC;AAED,MAAM,IAAI,GAAG,0BAA0B,CAAA;AAEvC,MAAM,SAAS,GAAG,IAAI,CAAA"}
|
package/transpiled/Factory.js
CHANGED
|
@@ -22,19 +22,24 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
25
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
29
|
exports.Factory = void 0;
|
|
30
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
31
|
+
const generic_1 = require("@toa.io/generic");
|
|
27
32
|
const Tenant_1 = require("./Tenant");
|
|
28
33
|
const Gateway_1 = require("./Gateway");
|
|
29
34
|
const Remotes_1 = require("./Remotes");
|
|
30
35
|
const RTD_1 = require("./RTD");
|
|
31
|
-
const HTTP_1 = require("./HTTP");
|
|
32
36
|
const Endpoint_1 = require("./Endpoint");
|
|
33
37
|
const directives_1 = require("./directives");
|
|
34
38
|
const Directive_1 = require("./Directive");
|
|
35
39
|
const Composition_1 = require("./Composition");
|
|
36
40
|
const root = __importStar(require("./root"));
|
|
37
41
|
const Interception_1 = require("./Interception");
|
|
42
|
+
const http = __importStar(require("./HTTP"));
|
|
38
43
|
class Factory {
|
|
39
44
|
boot;
|
|
40
45
|
constructor(boot) {
|
|
@@ -45,14 +50,10 @@ class Factory {
|
|
|
45
50
|
return new Tenant_1.Tenant(broadcast, locator, node);
|
|
46
51
|
}
|
|
47
52
|
service() {
|
|
48
|
-
|
|
49
|
-
const
|
|
53
|
+
node_assert_1.default.ok(process.env.TOA_EXPOSITION_PROPERTIES, 'TOA_EXPOSITION_PROPERTIES is undefined');
|
|
54
|
+
const options = (0, generic_1.decode)(process.env.TOA_EXPOSITION_PROPERTIES);
|
|
50
55
|
const broadcast = this.boot.bindings.broadcast(CHANNEL);
|
|
51
|
-
const server =
|
|
52
|
-
methods: RTD_1.syntax.verbs,
|
|
53
|
-
debug,
|
|
54
|
-
trace
|
|
55
|
-
});
|
|
56
|
+
const server = http.Server.create({ ...options, methods: RTD_1.syntax.verbs });
|
|
56
57
|
const remotes = new Remotes_1.Remotes(this.boot);
|
|
57
58
|
const node = root.resolve();
|
|
58
59
|
const methods = new Endpoint_1.EndpointsFactory(remotes);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Factory.js","sourceRoot":"","sources":["../source/Factory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Factory.js","sourceRoot":"","sources":["../source/Factory.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8DAAgC;AAChC,6CAAwC;AACxC,qCAAiC;AACjC,uCAAmC;AACnC,uCAAmC;AACnC,+BAAoC;AACpC,yCAA6C;AAC7C,6CAAqD;AACrD,2CAA+C;AAC/C,+CAA2C;AAC3C,6CAA8B;AAC9B,iDAA6C;AAC7C,6CAA8B;AAI9B,MAAa,OAAO;IACD,IAAI,CAAY;IAEjC,YAAoB,IAAgB;QA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,CAAC,QAAQ,KAAK,IAAI;YAC1B,MAAM,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAA;QAEnC,OAAO,MAAM,MAAM,CAAC,QAAQ;aACzB,IAAI,CAAC,OAAO,EAAE,UAAU,CAAC;aACzB,KAAK,CAAC,oBAAO,CAAyB,CAAA;IAC3C,CAAC;IAEO,KAAK,CAAC,QAAQ;QACpB,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAAS,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;QACrE,MAAM,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAO,MAAM,EAAE,IAAI,CAAC,CAAA;IACnD,CAAC;IAEO,KAAK,CAAE,MAAc;QAC3B,IAAI,CAAC;YACH,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;YAEpC,OAAO,CAAC,IAAI,CAAC,qBAAqB;gBAChC,IAAI,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,SAAS,oBAAoB,CAAC,CAAA;QACjE,CAAC;QAAC,OAAO,SAAS,EAAE,CAAC;YACnB,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;QAC1B,CAAC;IACH,CAAC;CACF;AAtFD,0BAsFC"}
|
|
@@ -4,13 +4,14 @@ import { type Format } from './formats';
|
|
|
4
4
|
import type { OutgoingMessage } from './messages';
|
|
5
5
|
import type * as http from 'node:http';
|
|
6
6
|
export declare class Context {
|
|
7
|
+
readonly authority: string;
|
|
7
8
|
readonly request: IncomingMessage;
|
|
8
9
|
readonly url: URL;
|
|
9
10
|
readonly subtype: string | null;
|
|
10
11
|
readonly encoder: Format | null;
|
|
11
12
|
readonly timing: Timing;
|
|
12
13
|
readonly pipelines: Pipelines;
|
|
13
|
-
constructor(request: IncomingMessage, trace?: boolean);
|
|
14
|
+
constructor(authority: string, request: IncomingMessage, trace?: boolean);
|
|
14
15
|
body<T>(): Promise<T>;
|
|
15
16
|
}
|
|
16
17
|
export interface IncomingMessage extends http.IncomingMessage {
|
|
@@ -9,6 +9,7 @@ const Timing_1 = require("./Timing");
|
|
|
9
9
|
const formats_1 = require("./formats");
|
|
10
10
|
const messages_1 = require("./messages");
|
|
11
11
|
class Context {
|
|
12
|
+
authority;
|
|
12
13
|
request;
|
|
13
14
|
url;
|
|
14
15
|
subtype = null;
|
|
@@ -18,7 +19,8 @@ class Context {
|
|
|
18
19
|
body: [],
|
|
19
20
|
response: []
|
|
20
21
|
};
|
|
21
|
-
constructor(request, trace = false) {
|
|
22
|
+
constructor(authority, request, trace = false) {
|
|
23
|
+
this.authority = authority;
|
|
22
24
|
this.request = request;
|
|
23
25
|
this.url = new URL(request.url, `https://${request.headers.host}`);
|
|
24
26
|
this.timing = new Timing_1.Timing(trace);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Context.js","sourceRoot":"","sources":["../../source/HTTP/Context.ts"],"names":[],"mappings":";;;;;;AAAA,4DAAmC;AACnC,qCAAiC;AACjC,uCAAuD;AACvD,yCAAiC;AAIjC,MAAa,OAAO;IACF,OAAO,CAAiB;IACxB,GAAG,CAAK;IACR,OAAO,GAAkB,IAAI,CAAA;IAC7B,OAAO,GAAkB,IAAI,CAAA;IAC7B,MAAM,CAAQ;IAEd,SAAS,GAAc;QACrC,IAAI,EAAE,EAAE;QACR,QAAQ,EAAE,EAAE;KACb,CAAA;IAED,YAAoB,OAAwB,EAAE,KAAK,GAAG,KAAK;
|
|
1
|
+
{"version":3,"file":"Context.js","sourceRoot":"","sources":["../../source/HTTP/Context.ts"],"names":[],"mappings":";;;;;;AAAA,4DAAmC;AACnC,qCAAiC;AACjC,uCAAuD;AACvD,yCAAiC;AAIjC,MAAa,OAAO;IACF,SAAS,CAAQ;IACjB,OAAO,CAAiB;IACxB,GAAG,CAAK;IACR,OAAO,GAAkB,IAAI,CAAA;IAC7B,OAAO,GAAkB,IAAI,CAAA;IAC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QAE9B,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC;YACrC,CAAC,CAAC,KAAK;YACP,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAA;IAC/E,CAAC;CACF;AAjDD,0BAiDC;AAYD,MAAM,OAAO,GAAG,4EAA4E,CAAA"}
|
|
@@ -4,10 +4,11 @@ import { Context } from './Context';
|
|
|
4
4
|
export declare class Server extends Connector {
|
|
5
5
|
private readonly server;
|
|
6
6
|
private readonly properties;
|
|
7
|
+
private readonly authorities;
|
|
7
8
|
private process?;
|
|
8
9
|
private constructor();
|
|
9
10
|
get port(): number;
|
|
10
|
-
static create(options
|
|
11
|
+
static create(options: Options): Server;
|
|
11
12
|
attach(process: Processing): void;
|
|
12
13
|
protected open(): Promise<void>;
|
|
13
14
|
protected close(): Promise<void>;
|
|
@@ -16,10 +17,16 @@ export declare class Server extends Connector {
|
|
|
16
17
|
private fail;
|
|
17
18
|
}
|
|
18
19
|
interface Properties {
|
|
20
|
+
authorities: Record<string, string>;
|
|
19
21
|
methods: Set<string>;
|
|
20
22
|
debug: boolean;
|
|
21
23
|
trace: boolean;
|
|
22
24
|
port: number;
|
|
23
25
|
}
|
|
26
|
+
export type Options = {
|
|
27
|
+
authorities: Properties['authorities'];
|
|
28
|
+
} & {
|
|
29
|
+
[K in Exclude<keyof Properties, 'authorities'>]?: Properties[K];
|
|
30
|
+
};
|
|
24
31
|
export type Processing = (input: Context) => Promise<OutgoingMessage>;
|
|
25
32
|
export {};
|
|
@@ -30,20 +30,20 @@ exports.Server = void 0;
|
|
|
30
30
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
31
31
|
const node_os_1 = __importDefault(require("node:os"));
|
|
32
32
|
const http = __importStar(require("node:http"));
|
|
33
|
-
const node_assert_1 = __importDefault(require("node:assert"));
|
|
34
33
|
const node_events_1 = require("node:events");
|
|
35
34
|
const core_1 = require("@toa.io/core");
|
|
36
|
-
const generic_1 = require("@toa.io/generic");
|
|
37
35
|
const messages_1 = require("./messages");
|
|
38
36
|
const exceptions_1 = require("./exceptions");
|
|
39
37
|
const Context_1 = require("./Context");
|
|
40
38
|
class Server extends core_1.Connector {
|
|
41
39
|
server = http.createServer();
|
|
42
40
|
properties;
|
|
41
|
+
authorities;
|
|
43
42
|
process;
|
|
44
43
|
constructor(properties) {
|
|
45
44
|
super();
|
|
46
45
|
this.properties = properties;
|
|
46
|
+
this.authorities = Object.fromEntries(Object.entries(properties.authorities).map(([key, value]) => [value, key]));
|
|
47
47
|
this.server.on('request', (req, res) => this.listener(req, res));
|
|
48
48
|
}
|
|
49
49
|
get port() {
|
|
@@ -55,9 +55,7 @@ class Server extends core_1.Connector {
|
|
|
55
55
|
return address.port;
|
|
56
56
|
}
|
|
57
57
|
static create(options) {
|
|
58
|
-
const properties =
|
|
59
|
-
? DEFAULTS
|
|
60
|
-
: { ...DEFAULTS, ...options };
|
|
58
|
+
const properties = Object.assign({}, DEFAULTS, options);
|
|
61
59
|
return new Server(properties);
|
|
62
60
|
}
|
|
63
61
|
attach(process) {
|
|
@@ -79,12 +77,12 @@ class Server extends core_1.Connector {
|
|
|
79
77
|
response.writeHead(501).end();
|
|
80
78
|
return;
|
|
81
79
|
}
|
|
82
|
-
if (request.
|
|
83
|
-
response.writeHead(
|
|
80
|
+
if (request.headers.host === undefined || !(request.headers.host in this.authorities)) {
|
|
81
|
+
response.writeHead(404).end('Unknown authority');
|
|
84
82
|
return;
|
|
85
83
|
}
|
|
86
|
-
|
|
87
|
-
const context = new Context_1.Context(request, this.properties.trace);
|
|
84
|
+
const authority = this.authorities[request.headers.host];
|
|
85
|
+
const context = new Context_1.Context(authority, request, this.properties.trace);
|
|
88
86
|
this.process(context)
|
|
89
87
|
.then(this.success(context, response))
|
|
90
88
|
.catch(this.fail(context, response));
|
|
@@ -109,15 +107,14 @@ class Server extends core_1.Connector {
|
|
|
109
107
|
return async (exception) => {
|
|
110
108
|
if (!context.request.complete)
|
|
111
109
|
await adam(context.request);
|
|
112
|
-
response.statusCode = exception instanceof exceptions_1.Exception
|
|
113
|
-
? exception.status
|
|
114
|
-
: 500;
|
|
110
|
+
response.statusCode = exception instanceof exceptions_1.Exception ? exception.status : 500;
|
|
115
111
|
const message = { status: response.statusCode };
|
|
116
112
|
const verbose = exception instanceof exceptions_1.ClientError || this.properties.debug;
|
|
117
113
|
if (verbose)
|
|
118
|
-
message.body =
|
|
119
|
-
|
|
120
|
-
|
|
114
|
+
message.body =
|
|
115
|
+
exception instanceof exceptions_1.Exception
|
|
116
|
+
? exception.body
|
|
117
|
+
: exception.stack ?? exception.message;
|
|
121
118
|
(0, messages_1.write)(context, response, message);
|
|
122
119
|
};
|
|
123
120
|
}
|
|
@@ -125,12 +122,9 @@ class Server extends core_1.Connector {
|
|
|
125
122
|
exports.Server = Server;
|
|
126
123
|
// https://github.com/whatwg/fetch/issues/1254
|
|
127
124
|
async function adam(request) {
|
|
128
|
-
const completed = (0, generic_1.promex)();
|
|
129
125
|
const devnull = node_fs_1.default.createWriteStream(node_os_1.default.devNull);
|
|
130
|
-
request
|
|
131
|
-
|
|
132
|
-
.pipe(devnull);
|
|
133
|
-
return completed;
|
|
126
|
+
request.pipe(devnull);
|
|
127
|
+
return (0, node_events_1.once)(request, 'end');
|
|
134
128
|
}
|
|
135
129
|
const DEFAULTS = {
|
|
136
130
|
methods: new Set(['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS']),
|