@yourrentals/cloudevent-receiver-hapi 0.4.2 → 0.5.0
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 +36 -3
- package/index.cjs.js +21 -10
- package/index.esm.js +70 -5
- package/package.json +3 -3
- package/src/index.d.ts +0 -1
package/README.md
CHANGED
|
@@ -11,8 +11,11 @@ yarn add @yourrentals/cloudevent-receiver-hapi
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
13
|
```ts
|
|
14
|
-
import {
|
|
15
|
-
|
|
14
|
+
import {
|
|
15
|
+
cloudEventReceiverPlugin,
|
|
16
|
+
CloudEventReceiver,
|
|
17
|
+
WebhookSignatureV1HmacPlugin
|
|
18
|
+
} from '@yourrentals/message-bus-receiver-nestjs';
|
|
16
19
|
import * as Hapi from '@hapi/hapi';
|
|
17
20
|
|
|
18
21
|
const server = new Hapi.Server({
|
|
@@ -28,8 +31,15 @@ const receiver = new CloudEventReceiver({
|
|
|
28
31
|
// ...
|
|
29
32
|
},
|
|
30
33
|
},
|
|
34
|
+
{
|
|
35
|
+
name: 'my-sqs-queue',
|
|
36
|
+
handler: async (event: SQSMessage) => {
|
|
37
|
+
// ...
|
|
38
|
+
},
|
|
39
|
+
isCloudEvent: false,
|
|
40
|
+
},
|
|
31
41
|
],
|
|
32
|
-
|
|
42
|
+
verifierPlugins: [new WebhookSignatureV1HmacPlugin('secret')],
|
|
33
43
|
});
|
|
34
44
|
|
|
35
45
|
server.register({
|
|
@@ -64,6 +74,29 @@ const main = async () => {
|
|
|
64
74
|
};
|
|
65
75
|
```
|
|
66
76
|
|
|
77
|
+
## Raw Mode
|
|
78
|
+
|
|
79
|
+
The library can receive messages from any sources so long that it implements the Webhook Signature.
|
|
80
|
+
To disable parsing as cloudevent, set the `isCloudEvent` option to `false`.
|
|
81
|
+
|
|
82
|
+
By default, the event type is assumed to be a SQS Message
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
const receiver = new CloudEventReceiver({
|
|
86
|
+
queues: [
|
|
87
|
+
{
|
|
88
|
+
name: 'my-queue',
|
|
89
|
+
handler: async (event: SqsMessage) => {
|
|
90
|
+
// ...
|
|
91
|
+
},
|
|
92
|
+
// Disable parsing as cloudevent
|
|
93
|
+
isCloudEvent: false
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
verifierPlugins: [new WebhookSignatureV1HmacPlugin('secret')],
|
|
97
|
+
});
|
|
98
|
+
```
|
|
99
|
+
|
|
67
100
|
## Errors
|
|
68
101
|
|
|
69
102
|
The library defines the following errors:
|
package/index.cjs.js
CHANGED
|
@@ -343,7 +343,7 @@ var cloudEventReceiverPlugin = function cloudEventReceiverPlugin(pluginOptions)
|
|
|
343
343
|
register: function register(server, options) {
|
|
344
344
|
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
345
345
|
var _this = this;
|
|
346
|
-
var normalizedPathPrefix;
|
|
346
|
+
var normalizedPathPrefix, majorVersion;
|
|
347
347
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
348
348
|
while (1) switch (_context2.prev = _context2.next) {
|
|
349
349
|
case 0:
|
|
@@ -354,7 +354,8 @@ var cloudEventReceiverPlugin = function cloudEventReceiverPlugin(pluginOptions)
|
|
|
354
354
|
throw new Error('Missing required plugin options');
|
|
355
355
|
case 2:
|
|
356
356
|
normalizedPathPrefix = pluginOptions.pathPrefix.startsWith('/') ? pluginOptions.pathPrefix : '/' + pluginOptions.pathPrefix;
|
|
357
|
-
server.
|
|
357
|
+
majorVersion = parseInt(server.version.split('.')[0]);
|
|
358
|
+
server.route(Object.assign({
|
|
358
359
|
method: 'POST',
|
|
359
360
|
path: "".concat(normalizedPathPrefix, "/{queueName}"),
|
|
360
361
|
handler: function handler(request, h) {
|
|
@@ -386,8 +387,24 @@ var cloudEventReceiverPlugin = function cloudEventReceiverPlugin(pluginOptions)
|
|
|
386
387
|
}, _callee, null, [[0, 7]]);
|
|
387
388
|
}));
|
|
388
389
|
}
|
|
389
|
-
}
|
|
390
|
-
|
|
390
|
+
}, majorVersion >= 17 ? {
|
|
391
|
+
options: {
|
|
392
|
+
auth: false,
|
|
393
|
+
payload: {
|
|
394
|
+
output: 'data',
|
|
395
|
+
parse: false
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
} : {
|
|
399
|
+
config: {
|
|
400
|
+
auth: false,
|
|
401
|
+
payload: {
|
|
402
|
+
output: 'data',
|
|
403
|
+
parse: false
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}));
|
|
407
|
+
case 5:
|
|
391
408
|
case "end":
|
|
392
409
|
return _context2.stop();
|
|
393
410
|
}
|
|
@@ -398,12 +415,6 @@ var cloudEventReceiverPlugin = function cloudEventReceiverPlugin(pluginOptions)
|
|
|
398
415
|
};
|
|
399
416
|
|
|
400
417
|
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
418
|
Object.keys(cloudeventReceiverCore).forEach(function (k) {
|
|
408
419
|
if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
|
|
409
420
|
enumerable: true,
|
package/index.esm.js
CHANGED
|
@@ -1,7 +1,27 @@
|
|
|
1
1
|
import { isReceiverError } from '@yourrentals/util-receiver-error';
|
|
2
|
-
export * from '@yourrentals/util-receiver-error';
|
|
3
2
|
export * from '@yourrentals/cloudevent-receiver-core';
|
|
4
3
|
|
|
4
|
+
function ownKeys(e, r) {
|
|
5
|
+
var t = Object.keys(e);
|
|
6
|
+
if (Object.getOwnPropertySymbols) {
|
|
7
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
8
|
+
r && (o = o.filter(function (r) {
|
|
9
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
10
|
+
})), t.push.apply(t, o);
|
|
11
|
+
}
|
|
12
|
+
return t;
|
|
13
|
+
}
|
|
14
|
+
function _objectSpread2(e) {
|
|
15
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
16
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
17
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
|
|
18
|
+
_defineProperty(e, r, t[r]);
|
|
19
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
20
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return e;
|
|
24
|
+
}
|
|
5
25
|
function _regeneratorRuntime() {
|
|
6
26
|
_regeneratorRuntime = function () {
|
|
7
27
|
return e;
|
|
@@ -333,13 +353,41 @@ function _asyncToGenerator(fn) {
|
|
|
333
353
|
});
|
|
334
354
|
};
|
|
335
355
|
}
|
|
356
|
+
function _defineProperty(obj, key, value) {
|
|
357
|
+
key = _toPropertyKey(key);
|
|
358
|
+
if (key in obj) {
|
|
359
|
+
Object.defineProperty(obj, key, {
|
|
360
|
+
value: value,
|
|
361
|
+
enumerable: true,
|
|
362
|
+
configurable: true,
|
|
363
|
+
writable: true
|
|
364
|
+
});
|
|
365
|
+
} else {
|
|
366
|
+
obj[key] = value;
|
|
367
|
+
}
|
|
368
|
+
return obj;
|
|
369
|
+
}
|
|
370
|
+
function _toPrimitive(input, hint) {
|
|
371
|
+
if (typeof input !== "object" || input === null) return input;
|
|
372
|
+
var prim = input[Symbol.toPrimitive];
|
|
373
|
+
if (prim !== undefined) {
|
|
374
|
+
var res = prim.call(input, hint || "default");
|
|
375
|
+
if (typeof res !== "object") return res;
|
|
376
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
377
|
+
}
|
|
378
|
+
return (hint === "string" ? String : Number)(input);
|
|
379
|
+
}
|
|
380
|
+
function _toPropertyKey(arg) {
|
|
381
|
+
var key = _toPrimitive(arg, "string");
|
|
382
|
+
return typeof key === "symbol" ? key : String(key);
|
|
383
|
+
}
|
|
336
384
|
|
|
337
385
|
var cloudEventReceiverPlugin = function cloudEventReceiverPlugin(pluginOptions) {
|
|
338
386
|
return {
|
|
339
387
|
name: 'cloud-event-receiver-plugin',
|
|
340
388
|
register: function () {
|
|
341
389
|
var _register = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(server, options) {
|
|
342
|
-
var normalizedPathPrefix;
|
|
390
|
+
var normalizedPathPrefix, majorVersion;
|
|
343
391
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
344
392
|
while (1) switch (_context2.prev = _context2.next) {
|
|
345
393
|
case 0:
|
|
@@ -350,7 +398,8 @@ var cloudEventReceiverPlugin = function cloudEventReceiverPlugin(pluginOptions)
|
|
|
350
398
|
throw new Error('Missing required plugin options');
|
|
351
399
|
case 2:
|
|
352
400
|
normalizedPathPrefix = pluginOptions.pathPrefix.startsWith('/') ? pluginOptions.pathPrefix : '/' + pluginOptions.pathPrefix;
|
|
353
|
-
server.
|
|
401
|
+
majorVersion = parseInt(server.version.split('.')[0]);
|
|
402
|
+
server.route(_objectSpread2({
|
|
354
403
|
method: 'POST',
|
|
355
404
|
path: "".concat(normalizedPathPrefix, "/{queueName}"),
|
|
356
405
|
handler: function () {
|
|
@@ -386,8 +435,24 @@ var cloudEventReceiverPlugin = function cloudEventReceiverPlugin(pluginOptions)
|
|
|
386
435
|
}
|
|
387
436
|
return handler;
|
|
388
437
|
}()
|
|
389
|
-
}
|
|
390
|
-
|
|
438
|
+
}, majorVersion >= 17 ? {
|
|
439
|
+
options: {
|
|
440
|
+
auth: false,
|
|
441
|
+
payload: {
|
|
442
|
+
output: 'data',
|
|
443
|
+
parse: false
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
} : {
|
|
447
|
+
config: {
|
|
448
|
+
auth: false,
|
|
449
|
+
payload: {
|
|
450
|
+
output: 'data',
|
|
451
|
+
parse: false
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
}));
|
|
455
|
+
case 5:
|
|
391
456
|
case "end":
|
|
392
457
|
return _context2.stop();
|
|
393
458
|
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yourrentals/cloudevent-receiver-hapi",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@yourrentals/cloudevent-receiver-core": "0.
|
|
6
|
-
"@yourrentals/util-receiver-error": "0.
|
|
5
|
+
"@yourrentals/cloudevent-receiver-core": "0.5.0",
|
|
6
|
+
"@yourrentals/util-receiver-error": "0.5.0"
|
|
7
7
|
},
|
|
8
8
|
"peerDependencies": {
|
|
9
9
|
"@hapi/hapi": "^17.0.0 || ^18.0.0 || ^19.0.0 || ^20.0.0 || ^21.0.0"
|
package/src/index.d.ts
CHANGED