{"id":21904806,"url":"https://github.com/boostercloud/rocket-webhook","last_synced_at":"2025-04-15T23:01:07.895Z","repository":{"id":46747282,"uuid":"442213106","full_name":"boostercloud/rocket-webhook","owner":"boostercloud","description":null,"archived":false,"fork":false,"pushed_at":"2025-02-27T14:06:36.000Z","size":2037,"stargazers_count":3,"open_issues_count":0,"forks_count":3,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-03-29T02:21:37.617Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/boostercloud.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-12-27T16:30:32.000Z","updated_at":"2025-02-27T14:06:39.000Z","dependencies_parsed_at":"2023-01-22T13:31:24.222Z","dependency_job_id":"46b0d00b-f758-4388-82a8-00b9697fbc58","html_url":"https://github.com/boostercloud/rocket-webhook","commit_stats":{"total_commits":70,"total_committers":8,"mean_commits":8.75,"dds":0.5857142857142856,"last_synced_commit":"0ebeab3a2f36b8e7dc1ee56a6223593efacfc15f"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boostercloud%2Frocket-webhook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boostercloud%2Frocket-webhook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boostercloud%2Frocket-webhook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boostercloud%2Frocket-webhook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/boostercloud","download_url":"https://codeload.github.com/boostercloud/rocket-webhook/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248578870,"owners_count":21127713,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-28T16:19:13.099Z","updated_at":"2025-04-15T23:01:07.860Z","avatar_url":"https://github.com/boostercloud.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Booster rocket webhook Azure\n\n## Description\nThis Rocket adds HTTP endpoints to your Booster application. When an endpoint is called, a function will be executed in your Booster application with request as a parameter. \n\n## Supported Providers\n\nThis Rocket supports the following Providers:\n\n* Azure\n* Local\n\n## Application configuration\n\nAdd your rocket to your application in the configuration file.\n\n### Generic\n\n```typescript\nimport { AllowedHttpMethod } from '@boostercloud/rocket-webhook-types'\n\nfunction buildBoosterWebhook(config: BoosterConfig): BoosterWebhook {\n  return new BoosterWebhook(config, [\n    {\n      route: 'test',\n      handlerClass: TestHandler,\n      allowedMethods: [AllowedHttpMethod.POST],\n    },\n    {\n      route: 'clients/other',\n      handlerClass: FacebookHandler,\n      allowedMethods: [AllowedHttpMethod.GET, AllowedHttpMethod.POST],\n    },\n  ])\n}\n```\n\nAnd call this method on your rocket configuration.\n\nFor Azure\n```typescript\n  config.rockets = [buildBoosterWebhook(config).rocketForAzure()]\n```\n\nFor Local\n```typescript\n  config.rockets = [buildBoosterWebhook(config).rocketForLocal()]\n```\n\n### Parameters\n\n* route: The endpoint that will be created. It is possible to define nested routes.\n* handlerClass: A class with a `handle` method to handle the request\n* multiPartConfig: multipart/form-data configuration\n  * defParamCharset: the default character set to use for values of part header parameters (e.g. filename)\n  * preservePath: If paths in filenames from file parts in a 'multipart/form-data' request shall be preserved. \n  * limits:\n    * fileSize: the max file size (in bytes)\n    * files: the max number of file fields.\n    * parts: the max number of parts (fields + files).\n\nThe `handle` method should be like this one:\n\n```typescript\nexport class TestHandler {\n\n  constructor() {\n  }\n\n  public static async handle(webhookEventInterface: WebhookEvent, register: Register): Promise\u003cWebhookHandlerReturnType\u003e {\n    if (validationFails()) {\n      throw new InvalidParameterError(\"Error message\");\n    }\n    return Promise.resolve({\n      body: { name: \"my_name\" },\n      responseType: WebhookResponseType.json,\n    });\n  }\n}\n```\n\n## Return type\n\nHandle methods return a promise of WebhookHandlerReturnType or void. This object contains the headers and body to be returned as response. You need to specify the responseType. Example:\n\n```typescript\n  public static async handle(\n    webhookEventInterface: WebhookEvent,\n    register: Register\n  ): Promise\u003cWebhookHandlerReturnType\u003e {\n    return Promise.resolve({\n      body: 'ok',\n      headers: {\n        Test: 'test header',\n      },\n      responseType: WebhookResponseType.text,\n    })\n  }\n```\n\nTo return a file, set the responseType to `WebhookResponseType.file`. Specify the name and mime type in the `file` field.\n\nExample:\n\n```typescript\n    const result: WebhookHandlerReturnType = {\n  body: file,\n  file: {\n    name: '1.txt',\n    mimeType: WebhookResponseType.text,\n  },\n  responseType: WebhookResponseType.file,\n}\n```\n\n## Authorization\n\nTo define with roles can access each point use the `authorize` configuration parameter as the `authorize` parameter in Booster.\n\nExample:\n\n```typescript\n{\n  route: 'all',\n        handlerClass: AllHandlerDispatcher,\n        authorize: 'all',\n},\n{\n  route: 'test/roles',\n        handlerClass: AdminHandlerDispatcher,\n        authorize: [Admin],\n},\n{\n  route: 'custom',\n        handlerClass: CustomHandlerDispatcher,\n        authorize: (currentUser?: UserEnvelope, request?: WebhookRequest): Promise\u003cvoid\u003e =\u003e {\n          if (currentUser?.username !== 'test@test.com') {\n            return Promise.reject('Unexpected user')\n          }\n          return Promise.resolve()\n        },\n},\n```\n\n## Usage\n\n```shell\ncurl --request POST 'http://localhost:3000/webhook/command?param1=testvalue'\n```\n\nThe webhookEventInterface object will be similar to this one: \n\n```json\n{\n  origin: 'test',\n  method: 'POST',\n  url: '/test?param1=testvalue',\n  originalUrl: '/webhook/test?param1=testvalue',\n  headers: {\n    accept: '*/*',\n    'cache-control': 'no-cache',\n    host: 'localhost:3000',\n    'accept-encoding': 'gzip, deflate, br',\n    connection: 'keep-alive',\n    'content-length': '0'\n  },\n  query: { param1: 'testvalue' },\n  params: {},\n  rawBody: undefined,\n  body: {}\n}\n```\n\n\n## Multipart/form-data requests\n\nEndpoints accepts multipart/form-data requests. The `WebhookEvent` will contain a new `multiPart` object with the files and fields in the request. Example:\n\n```json\n{\n  origin: 'test',\n  method: 'POST',\n  url: '/test?param1=testvalue',\n  originalUrl: '/webhook/test?param1=testvalue',\n  headers: {\n    accept: '*/*',\n    'cache-control': 'no-cache',\n    host: 'localhost:3000',\n    'accept-encoding': 'gzip, deflate, br',\n    connection: 'keep-alive',\n    'content-length': '0'\n  },\n  query: {\n    param1: 'testvalue'\n  },\n  params: {},\n  rawBody: undefined,\n  body: {},\n  multipart: {\n    \"files\": [\n      {\n        name: \"file1\",\n        bufferFile: Buffer(11),\n        filename: \"file1.txt\",\n        encoding: \"7bit\",\n        mimeType: \"text/plain\"\n      }\n    ],\n    \"fields\": [\n      {\n        name: \"parameterName\",\n        value: \"value\",\n        nameTruncated: false,\n        valueTruncated: false,\n        encoding: \"7bit\",\n        ...\n      }\n    ]\n  }\n}\n```\n\n## Compile\n\n\u003e npm install\n\n\u003e npm run compile\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboostercloud%2Frocket-webhook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fboostercloud%2Frocket-webhook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboostercloud%2Frocket-webhook/lists"}