@yourrentals/cloudevent-receiver-hapi 0.4.3 → 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 CHANGED
@@ -11,7 +11,11 @@ yarn add @yourrentals/cloudevent-receiver-hapi
11
11
  ## Usage
12
12
 
13
13
  ```ts
14
- import { cloudEventReceiverPlugin, CloudEventReceiver, CloudEventRsaVerifier } from '@yourrentals/message-bus-receiver-nestjs';
14
+ import {
15
+ cloudEventReceiverPlugin,
16
+ CloudEventReceiver,
17
+ WebhookSignatureV1HmacPlugin
18
+ } from '@yourrentals/message-bus-receiver-nestjs';
15
19
  import * as Hapi from '@hapi/hapi';
16
20
 
17
21
  const server = new Hapi.Server({
@@ -27,8 +31,15 @@ const receiver = new CloudEventReceiver({
27
31
  // ...
28
32
  },
29
33
  },
34
+ {
35
+ name: 'my-sqs-queue',
36
+ handler: async (event: SQSMessage) => {
37
+ // ...
38
+ },
39
+ isCloudEvent: false,
40
+ },
30
41
  ],
31
- verifiers: [new CloudEventRsaVerifier('signature', 'publicKey')],
42
+ verifierPlugins: [new WebhookSignatureV1HmacPlugin('secret')],
32
43
  });
33
44
 
34
45
  server.register({
@@ -63,6 +74,29 @@ const main = async () => {
63
74
  };
64
75
  ```
65
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
+
66
100
  ## Errors
67
101
 
68
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.route({
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
- case 4:
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
  }
package/index.esm.js CHANGED
@@ -1,6 +1,27 @@
1
1
  import { isReceiverError } from '@yourrentals/util-receiver-error';
2
2
  export * from '@yourrentals/cloudevent-receiver-core';
3
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
+ }
4
25
  function _regeneratorRuntime() {
5
26
  _regeneratorRuntime = function () {
6
27
  return e;
@@ -332,13 +353,41 @@ function _asyncToGenerator(fn) {
332
353
  });
333
354
  };
334
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
+ }
335
384
 
336
385
  var cloudEventReceiverPlugin = function cloudEventReceiverPlugin(pluginOptions) {
337
386
  return {
338
387
  name: 'cloud-event-receiver-plugin',
339
388
  register: function () {
340
389
  var _register = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(server, options) {
341
- var normalizedPathPrefix;
390
+ var normalizedPathPrefix, majorVersion;
342
391
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
343
392
  while (1) switch (_context2.prev = _context2.next) {
344
393
  case 0:
@@ -349,7 +398,8 @@ var cloudEventReceiverPlugin = function cloudEventReceiverPlugin(pluginOptions)
349
398
  throw new Error('Missing required plugin options');
350
399
  case 2:
351
400
  normalizedPathPrefix = pluginOptions.pathPrefix.startsWith('/') ? pluginOptions.pathPrefix : '/' + pluginOptions.pathPrefix;
352
- server.route({
401
+ majorVersion = parseInt(server.version.split('.')[0]);
402
+ server.route(_objectSpread2({
353
403
  method: 'POST',
354
404
  path: "".concat(normalizedPathPrefix, "/{queueName}"),
355
405
  handler: function () {
@@ -385,8 +435,24 @@ var cloudEventReceiverPlugin = function cloudEventReceiverPlugin(pluginOptions)
385
435
  }
386
436
  return handler;
387
437
  }()
388
- });
389
- case 4:
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:
390
456
  case "end":
391
457
  return _context2.stop();
392
458
  }
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@yourrentals/cloudevent-receiver-hapi",
3
- "version": "0.4.3",
3
+ "version": "0.5.0",
4
4
  "dependencies": {
5
- "@yourrentals/cloudevent-receiver-core": "0.4.3",
6
- "@yourrentals/util-receiver-error": "0.4.3"
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"