|
1 | 1 | import { CloudEvent } from "../event/cloudevent"; |
2 | | -import { axiosEmitter } from "./http"; |
3 | | -import { Protocol } from "./protocols"; |
4 | | -import { Agent } from "http"; |
5 | 2 | import { HTTP, Message, Mode } from "../message"; |
6 | 3 |
|
7 | | -/** |
8 | | - * Options supplied to the Emitter when sending an event. |
9 | | - * In addition to url and protocol, TransportOptions may |
10 | | - * also accept custom options that will be passed to the |
11 | | - * Node.js http functions. |
12 | | - * @deprecated will be removed in 4.0.0 |
13 | | - */ |
14 | | -export interface TransportOptions { |
15 | | - /** |
16 | | - * The endpoint that will receieve the event. |
17 | | - * @example http://cncf.example.com/receiver |
18 | | - */ |
19 | | - url?: string; |
20 | | - /** |
21 | | - * The network protocol over which the event will be sent. |
22 | | - * @example HTTPStructured |
23 | | - * @example HTTPBinary |
24 | | - */ |
25 | | - protocol?: Protocol; |
26 | | - |
27 | | - [key: string]: string | Record<string, unknown> | Protocol | Agent | undefined; |
28 | | -} |
29 | | - |
30 | 4 | /** |
31 | 5 | * Options is an additional, optional dictionary of options that may |
32 | 6 | * be passed to an EmitterFunction and TransportFunction |
@@ -84,51 +58,3 @@ export function emitterFor(fn: TransportFunction, options = { binding: HTTP, mod |
84 | 58 | } |
85 | 59 | }; |
86 | 60 | } |
87 | | - |
88 | | -/** |
89 | | - * A class to send binary and structured CloudEvents to a remote endpoint. |
90 | | - * Currently, supported protocols are HTTPBinary and HTTPStructured. |
91 | | - * |
92 | | - * @see https://github.com/cloudevents/spec/blob/v1.0/http-protocol-binding.md |
93 | | - * @see https://github.com/cloudevents/spec/blob/v1.0/http-protocol-binding.md#13-content-modes |
94 | | - * @deprecated Will be removed in 4.0.0. Consider using the emitterFactory |
95 | | - * |
96 | | - */ |
97 | | -export class Emitter { |
98 | | - url?: string; |
99 | | - protocol: Protocol; |
100 | | - binaryEmitter: EmitterFunction; |
101 | | - structuredEmitter: EmitterFunction; |
102 | | - |
103 | | - constructor(options: TransportOptions = { protocol: Protocol.HTTPBinary }) { |
104 | | - this.protocol = options.protocol as Protocol; |
105 | | - this.url = options.url; |
106 | | - |
107 | | - this.binaryEmitter = emitterFor(axiosEmitter(this.url as string)); |
108 | | - this.structuredEmitter = emitterFor(axiosEmitter(this.url as string), { binding: HTTP, mode: Mode.STRUCTURED }); |
109 | | - } |
110 | | - |
111 | | - /** |
112 | | - * Sends the {CloudEvent} to an event receiver over HTTP POST |
113 | | - * |
114 | | - * @param {CloudEvent} event the CloudEvent to be sent |
115 | | - * @param {Object} [options] The configuration options for this event. Options |
116 | | - * provided will be passed along to Node.js `http.request()`. |
117 | | - * https://nodejs.org/api/http.html#http_http_request_options_callback |
118 | | - * @param {string} [options.url] The HTTP/S url that should receive this event. |
119 | | - * The URL is optional if one was provided when this emitter was constructed. |
120 | | - * In that case, it will be used as the recipient endpoint. The endpoint can |
121 | | - * be overridden by providing a URL here. |
122 | | - * @returns {Promise} Promise with an eventual response from the receiver |
123 | | - * @deprecated Will be removed in 4.0.0. Consider using the emitterFactory |
124 | | - */ |
125 | | - send(event: CloudEvent, options?: TransportOptions): Promise<unknown> { |
126 | | - options = options || {}; |
127 | | - options.url = options.url || this.url; |
128 | | - if (options.protocol != this.protocol) { |
129 | | - if (this.protocol === Protocol.HTTPBinary) return this.binaryEmitter(event, options); |
130 | | - return this.structuredEmitter(event, options); |
131 | | - } |
132 | | - return this.binaryEmitter(event, options); |
133 | | - } |
134 | | -} |
0 commit comments