@yourrentals/cloudevent-receiver-hapi 0.1.4 → 0.4.1
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/README.md +79 -0
- package/index.cjs.d.ts +1 -0
- package/index.cjs.js +412 -0
- package/index.esm.js +404 -0
- package/package.json +10 -4
- package/src/index.d.ts +3 -0
- package/{lib → src/lib}/cloud-event-receiver-plugin.d.ts +1 -1
- package/index.d.ts +0 -3
- package/index.js +0 -16
- package/index.mjs +0 -2908
package/README.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# @yourrentals/cloudevent-receiver-hapi
|
|
2
|
+
|
|
3
|
+
This library defines a plugin for Hapi to receive messages from the message bus.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
yarn add @yourrentals/cloudevent-receiver-hapi
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { cloudEventReceiverPlugin, CloudEventReceiver } from '@yourrentals/message-bus-receiver-nestjs';
|
|
15
|
+
import { RsaVerifier } from '@yourrentals/message-bus-signature-rsa';
|
|
16
|
+
import * as Hapi from '@hapi/hapi';
|
|
17
|
+
|
|
18
|
+
const server = new Hapi.Server({
|
|
19
|
+
port: 3000,
|
|
20
|
+
host: 'localhost',
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const receiver = new CloudEventReceiver({
|
|
24
|
+
queues: [
|
|
25
|
+
{
|
|
26
|
+
name: 'my-queue',
|
|
27
|
+
handler: async (event: CloudEvent) => {
|
|
28
|
+
// ...
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
verifiers: [new RsaVerifier('signature', 'publicKey')],
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
server.register({
|
|
36
|
+
plugin: cloudEventReceiverPlugin,
|
|
37
|
+
options: {
|
|
38
|
+
pathPrefix: '/message-bus',
|
|
39
|
+
receiver,
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// ...
|
|
44
|
+
import Axios from 'axios';
|
|
45
|
+
|
|
46
|
+
const main = async () => {
|
|
47
|
+
// Queue name defined in the receiver are automatically registered
|
|
48
|
+
await Axios.post('http://localhost:3000/message-bus/my-queue', {
|
|
49
|
+
headers: {
|
|
50
|
+
'ce-specversion': '1.0',
|
|
51
|
+
'ce-type': 'my-event',
|
|
52
|
+
'ce-source': 'my-source',
|
|
53
|
+
'ce-id': 'my-id',
|
|
54
|
+
'ce-time': '2020-01-01T00:00:00Z',
|
|
55
|
+
'ce-datacontenttype': 'application/json',
|
|
56
|
+
'ce-dataschema': 'http://myschema.com',
|
|
57
|
+
'ce-subject': 'my-subject',
|
|
58
|
+
'ce-signature': 'my-signature',
|
|
59
|
+
},
|
|
60
|
+
body: {
|
|
61
|
+
foo: 'bar',
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Errors
|
|
68
|
+
|
|
69
|
+
The library defines the following errors:
|
|
70
|
+
|
|
71
|
+
| Error | Description | Expected HTTP status code | Retryable |
|
|
72
|
+
| ---------------------- | --------------------------------------- | ------------------------- | --------- |
|
|
73
|
+
| InvalidSignatureError | The signature of the message is invalid | 401 | No |
|
|
74
|
+
| UnparsableMessageError | The message is not a valid CloudEvent | 400 | No |
|
|
75
|
+
| NotFoundError | The queue name is not registered | 404 | Yes |
|
|
76
|
+
| ConflictError | The queue name is already registered | 409 | Yes |
|
|
77
|
+
| TooManyRequestsError | The queue is currently busy | 429 | Yes |
|
|
78
|
+
| ClientError | Any other client error | 400 | No |
|
|
79
|
+
| ServerError | Any other server error | 500 | Yes |
|
package/index.cjs.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/index";
|
package/index.cjs.js
ADDED
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var utilReceiverError = require('@yourrentals/util-receiver-error');
|
|
6
|
+
var cloudeventReceiverCore = require('@yourrentals/cloudevent-receiver-core');
|
|
7
|
+
|
|
8
|
+
function _regeneratorRuntime() {
|
|
9
|
+
_regeneratorRuntime = function () {
|
|
10
|
+
return e;
|
|
11
|
+
};
|
|
12
|
+
var t,
|
|
13
|
+
e = {},
|
|
14
|
+
r = Object.prototype,
|
|
15
|
+
n = r.hasOwnProperty,
|
|
16
|
+
o = Object.defineProperty || function (t, e, r) {
|
|
17
|
+
t[e] = r.value;
|
|
18
|
+
},
|
|
19
|
+
i = "function" == typeof Symbol ? Symbol : {},
|
|
20
|
+
a = i.iterator || "@@iterator",
|
|
21
|
+
c = i.asyncIterator || "@@asyncIterator",
|
|
22
|
+
u = i.toStringTag || "@@toStringTag";
|
|
23
|
+
function define(t, e, r) {
|
|
24
|
+
return Object.defineProperty(t, e, {
|
|
25
|
+
value: r,
|
|
26
|
+
enumerable: !0,
|
|
27
|
+
configurable: !0,
|
|
28
|
+
writable: !0
|
|
29
|
+
}), t[e];
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
define({}, "");
|
|
33
|
+
} catch (t) {
|
|
34
|
+
define = function (t, e, r) {
|
|
35
|
+
return t[e] = r;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function wrap(t, e, r, n) {
|
|
39
|
+
var i = e && e.prototype instanceof Generator ? e : Generator,
|
|
40
|
+
a = Object.create(i.prototype),
|
|
41
|
+
c = new Context(n || []);
|
|
42
|
+
return o(a, "_invoke", {
|
|
43
|
+
value: makeInvokeMethod(t, r, c)
|
|
44
|
+
}), a;
|
|
45
|
+
}
|
|
46
|
+
function tryCatch(t, e, r) {
|
|
47
|
+
try {
|
|
48
|
+
return {
|
|
49
|
+
type: "normal",
|
|
50
|
+
arg: t.call(e, r)
|
|
51
|
+
};
|
|
52
|
+
} catch (t) {
|
|
53
|
+
return {
|
|
54
|
+
type: "throw",
|
|
55
|
+
arg: t
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
e.wrap = wrap;
|
|
60
|
+
var h = "suspendedStart",
|
|
61
|
+
l = "suspendedYield",
|
|
62
|
+
f = "executing",
|
|
63
|
+
s = "completed",
|
|
64
|
+
y = {};
|
|
65
|
+
function Generator() {}
|
|
66
|
+
function GeneratorFunction() {}
|
|
67
|
+
function GeneratorFunctionPrototype() {}
|
|
68
|
+
var p = {};
|
|
69
|
+
define(p, a, function () {
|
|
70
|
+
return this;
|
|
71
|
+
});
|
|
72
|
+
var d = Object.getPrototypeOf,
|
|
73
|
+
v = d && d(d(values([])));
|
|
74
|
+
v && v !== r && n.call(v, a) && (p = v);
|
|
75
|
+
var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
|
|
76
|
+
function defineIteratorMethods(t) {
|
|
77
|
+
["next", "throw", "return"].forEach(function (e) {
|
|
78
|
+
define(t, e, function (t) {
|
|
79
|
+
return this._invoke(e, t);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
function AsyncIterator(t, e) {
|
|
84
|
+
function invoke(r, o, i, a) {
|
|
85
|
+
var c = tryCatch(t[r], t, o);
|
|
86
|
+
if ("throw" !== c.type) {
|
|
87
|
+
var u = c.arg,
|
|
88
|
+
h = u.value;
|
|
89
|
+
return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
|
|
90
|
+
invoke("next", t, i, a);
|
|
91
|
+
}, function (t) {
|
|
92
|
+
invoke("throw", t, i, a);
|
|
93
|
+
}) : e.resolve(h).then(function (t) {
|
|
94
|
+
u.value = t, i(u);
|
|
95
|
+
}, function (t) {
|
|
96
|
+
return invoke("throw", t, i, a);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
a(c.arg);
|
|
100
|
+
}
|
|
101
|
+
var r;
|
|
102
|
+
o(this, "_invoke", {
|
|
103
|
+
value: function (t, n) {
|
|
104
|
+
function callInvokeWithMethodAndArg() {
|
|
105
|
+
return new e(function (e, r) {
|
|
106
|
+
invoke(t, n, e, r);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
function makeInvokeMethod(e, r, n) {
|
|
114
|
+
var o = h;
|
|
115
|
+
return function (i, a) {
|
|
116
|
+
if (o === f) throw new Error("Generator is already running");
|
|
117
|
+
if (o === s) {
|
|
118
|
+
if ("throw" === i) throw a;
|
|
119
|
+
return {
|
|
120
|
+
value: t,
|
|
121
|
+
done: !0
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
for (n.method = i, n.arg = a;;) {
|
|
125
|
+
var c = n.delegate;
|
|
126
|
+
if (c) {
|
|
127
|
+
var u = maybeInvokeDelegate(c, n);
|
|
128
|
+
if (u) {
|
|
129
|
+
if (u === y) continue;
|
|
130
|
+
return u;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
|
|
134
|
+
if (o === h) throw o = s, n.arg;
|
|
135
|
+
n.dispatchException(n.arg);
|
|
136
|
+
} else "return" === n.method && n.abrupt("return", n.arg);
|
|
137
|
+
o = f;
|
|
138
|
+
var p = tryCatch(e, r, n);
|
|
139
|
+
if ("normal" === p.type) {
|
|
140
|
+
if (o = n.done ? s : l, p.arg === y) continue;
|
|
141
|
+
return {
|
|
142
|
+
value: p.arg,
|
|
143
|
+
done: n.done
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
"throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
function maybeInvokeDelegate(e, r) {
|
|
151
|
+
var n = r.method,
|
|
152
|
+
o = e.iterator[n];
|
|
153
|
+
if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
|
|
154
|
+
var i = tryCatch(o, e.iterator, r.arg);
|
|
155
|
+
if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
|
|
156
|
+
var a = i.arg;
|
|
157
|
+
return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
|
|
158
|
+
}
|
|
159
|
+
function pushTryEntry(t) {
|
|
160
|
+
var e = {
|
|
161
|
+
tryLoc: t[0]
|
|
162
|
+
};
|
|
163
|
+
1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
|
|
164
|
+
}
|
|
165
|
+
function resetTryEntry(t) {
|
|
166
|
+
var e = t.completion || {};
|
|
167
|
+
e.type = "normal", delete e.arg, t.completion = e;
|
|
168
|
+
}
|
|
169
|
+
function Context(t) {
|
|
170
|
+
this.tryEntries = [{
|
|
171
|
+
tryLoc: "root"
|
|
172
|
+
}], t.forEach(pushTryEntry, this), this.reset(!0);
|
|
173
|
+
}
|
|
174
|
+
function values(e) {
|
|
175
|
+
if (e || "" === e) {
|
|
176
|
+
var r = e[a];
|
|
177
|
+
if (r) return r.call(e);
|
|
178
|
+
if ("function" == typeof e.next) return e;
|
|
179
|
+
if (!isNaN(e.length)) {
|
|
180
|
+
var o = -1,
|
|
181
|
+
i = function next() {
|
|
182
|
+
for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
|
|
183
|
+
return next.value = t, next.done = !0, next;
|
|
184
|
+
};
|
|
185
|
+
return i.next = i;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
throw new TypeError(typeof e + " is not iterable");
|
|
189
|
+
}
|
|
190
|
+
return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
|
|
191
|
+
value: GeneratorFunctionPrototype,
|
|
192
|
+
configurable: !0
|
|
193
|
+
}), o(GeneratorFunctionPrototype, "constructor", {
|
|
194
|
+
value: GeneratorFunction,
|
|
195
|
+
configurable: !0
|
|
196
|
+
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
|
|
197
|
+
var e = "function" == typeof t && t.constructor;
|
|
198
|
+
return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
|
|
199
|
+
}, e.mark = function (t) {
|
|
200
|
+
return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
|
|
201
|
+
}, e.awrap = function (t) {
|
|
202
|
+
return {
|
|
203
|
+
__await: t
|
|
204
|
+
};
|
|
205
|
+
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
|
|
206
|
+
return this;
|
|
207
|
+
}), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
|
|
208
|
+
void 0 === i && (i = Promise);
|
|
209
|
+
var a = new AsyncIterator(wrap(t, r, n, o), i);
|
|
210
|
+
return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
|
|
211
|
+
return t.done ? t.value : a.next();
|
|
212
|
+
});
|
|
213
|
+
}, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
|
|
214
|
+
return this;
|
|
215
|
+
}), define(g, "toString", function () {
|
|
216
|
+
return "[object Generator]";
|
|
217
|
+
}), e.keys = function (t) {
|
|
218
|
+
var e = Object(t),
|
|
219
|
+
r = [];
|
|
220
|
+
for (var n in e) r.push(n);
|
|
221
|
+
return r.reverse(), function next() {
|
|
222
|
+
for (; r.length;) {
|
|
223
|
+
var t = r.pop();
|
|
224
|
+
if (t in e) return next.value = t, next.done = !1, next;
|
|
225
|
+
}
|
|
226
|
+
return next.done = !0, next;
|
|
227
|
+
};
|
|
228
|
+
}, e.values = values, Context.prototype = {
|
|
229
|
+
constructor: Context,
|
|
230
|
+
reset: function (e) {
|
|
231
|
+
if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
|
|
232
|
+
},
|
|
233
|
+
stop: function () {
|
|
234
|
+
this.done = !0;
|
|
235
|
+
var t = this.tryEntries[0].completion;
|
|
236
|
+
if ("throw" === t.type) throw t.arg;
|
|
237
|
+
return this.rval;
|
|
238
|
+
},
|
|
239
|
+
dispatchException: function (e) {
|
|
240
|
+
if (this.done) throw e;
|
|
241
|
+
var r = this;
|
|
242
|
+
function handle(n, o) {
|
|
243
|
+
return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
|
|
244
|
+
}
|
|
245
|
+
for (var o = this.tryEntries.length - 1; o >= 0; --o) {
|
|
246
|
+
var i = this.tryEntries[o],
|
|
247
|
+
a = i.completion;
|
|
248
|
+
if ("root" === i.tryLoc) return handle("end");
|
|
249
|
+
if (i.tryLoc <= this.prev) {
|
|
250
|
+
var c = n.call(i, "catchLoc"),
|
|
251
|
+
u = n.call(i, "finallyLoc");
|
|
252
|
+
if (c && u) {
|
|
253
|
+
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
254
|
+
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
255
|
+
} else if (c) {
|
|
256
|
+
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
257
|
+
} else {
|
|
258
|
+
if (!u) throw new Error("try statement without catch or finally");
|
|
259
|
+
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
abrupt: function (t, e) {
|
|
265
|
+
for (var r = this.tryEntries.length - 1; r >= 0; --r) {
|
|
266
|
+
var o = this.tryEntries[r];
|
|
267
|
+
if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
|
|
268
|
+
var i = o;
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
|
|
273
|
+
var a = i ? i.completion : {};
|
|
274
|
+
return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
|
|
275
|
+
},
|
|
276
|
+
complete: function (t, e) {
|
|
277
|
+
if ("throw" === t.type) throw t.arg;
|
|
278
|
+
return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
|
|
279
|
+
},
|
|
280
|
+
finish: function (t) {
|
|
281
|
+
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
282
|
+
var r = this.tryEntries[e];
|
|
283
|
+
if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
catch: function (t) {
|
|
287
|
+
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
288
|
+
var r = this.tryEntries[e];
|
|
289
|
+
if (r.tryLoc === t) {
|
|
290
|
+
var n = r.completion;
|
|
291
|
+
if ("throw" === n.type) {
|
|
292
|
+
var o = n.arg;
|
|
293
|
+
resetTryEntry(r);
|
|
294
|
+
}
|
|
295
|
+
return o;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
throw new Error("illegal catch attempt");
|
|
299
|
+
},
|
|
300
|
+
delegateYield: function (e, r, n) {
|
|
301
|
+
return this.delegate = {
|
|
302
|
+
iterator: values(e),
|
|
303
|
+
resultName: r,
|
|
304
|
+
nextLoc: n
|
|
305
|
+
}, "next" === this.method && (this.arg = t), y;
|
|
306
|
+
}
|
|
307
|
+
}, e;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/******************************************************************************
|
|
311
|
+
Copyright (c) Microsoft Corporation.
|
|
312
|
+
|
|
313
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
314
|
+
purpose with or without fee is hereby granted.
|
|
315
|
+
|
|
316
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
317
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
318
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
319
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
320
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
321
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
322
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
323
|
+
***************************************************************************** */
|
|
324
|
+
|
|
325
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
326
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
327
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
328
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
329
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
330
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
331
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
336
|
+
var e = new Error(message);
|
|
337
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
var cloudEventReceiverPlugin = function cloudEventReceiverPlugin(pluginOptions) {
|
|
341
|
+
return {
|
|
342
|
+
name: 'cloud-event-receiver-plugin',
|
|
343
|
+
register: function register(server, options) {
|
|
344
|
+
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
345
|
+
var _this = this;
|
|
346
|
+
var normalizedPathPrefix;
|
|
347
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
348
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
349
|
+
case 0:
|
|
350
|
+
if (!(!pluginOptions || !pluginOptions.receiver || !pluginOptions.pathPrefix)) {
|
|
351
|
+
_context2.next = 2;
|
|
352
|
+
break;
|
|
353
|
+
}
|
|
354
|
+
throw new Error('Missing required plugin options');
|
|
355
|
+
case 2:
|
|
356
|
+
normalizedPathPrefix = pluginOptions.pathPrefix.startsWith('/') ? pluginOptions.pathPrefix : '/' + pluginOptions.pathPrefix;
|
|
357
|
+
server.route({
|
|
358
|
+
method: 'POST',
|
|
359
|
+
path: "".concat(normalizedPathPrefix, "/{queueName}"),
|
|
360
|
+
handler: function handler(request, h) {
|
|
361
|
+
return __awaiter(_this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
362
|
+
var queueName;
|
|
363
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
364
|
+
while (1) switch (_context.prev = _context.next) {
|
|
365
|
+
case 0:
|
|
366
|
+
_context.prev = 0;
|
|
367
|
+
queueName = request.params.queueName;
|
|
368
|
+
_context.next = 4;
|
|
369
|
+
return pluginOptions.receiver.handle(queueName, request.headers, request.payload);
|
|
370
|
+
case 4:
|
|
371
|
+
return _context.abrupt("return", h.response().code(200));
|
|
372
|
+
case 7:
|
|
373
|
+
_context.prev = 7;
|
|
374
|
+
_context.t0 = _context["catch"](0);
|
|
375
|
+
if (!utilReceiverError.isReceiverError(_context.t0)) {
|
|
376
|
+
_context.next = 11;
|
|
377
|
+
break;
|
|
378
|
+
}
|
|
379
|
+
return _context.abrupt("return", h.response().code(_context.t0.statusCode).message(_context.t0.message));
|
|
380
|
+
case 11:
|
|
381
|
+
return _context.abrupt("return", h.response().code(500).message('Internal Server Error'));
|
|
382
|
+
case 12:
|
|
383
|
+
case "end":
|
|
384
|
+
return _context.stop();
|
|
385
|
+
}
|
|
386
|
+
}, _callee, null, [[0, 7]]);
|
|
387
|
+
}));
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
case 4:
|
|
391
|
+
case "end":
|
|
392
|
+
return _context2.stop();
|
|
393
|
+
}
|
|
394
|
+
}, _callee2);
|
|
395
|
+
}));
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
exports.cloudEventReceiverPlugin = cloudEventReceiverPlugin;
|
|
401
|
+
Object.keys(utilReceiverError).forEach(function (k) {
|
|
402
|
+
if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
|
|
403
|
+
enumerable: true,
|
|
404
|
+
get: function () { return utilReceiverError[k]; }
|
|
405
|
+
});
|
|
406
|
+
});
|
|
407
|
+
Object.keys(cloudeventReceiverCore).forEach(function (k) {
|
|
408
|
+
if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
|
|
409
|
+
enumerable: true,
|
|
410
|
+
get: function () { return cloudeventReceiverCore[k]; }
|
|
411
|
+
});
|
|
412
|
+
});
|