{"id":19732216,"url":"https://github.com/lifeomic/alpha","last_synced_at":"2025-04-06T22:12:16.031Z","repository":{"id":37932832,"uuid":"135727803","full_name":"lifeomic/alpha","owner":"lifeomic","description":"Unified client for HTTP services","archived":false,"fork":false,"pushed_at":"2025-03-08T18:31:01.000Z","size":1984,"stargazers_count":20,"open_issues_count":2,"forks_count":8,"subscribers_count":22,"default_branch":"master","last_synced_at":"2025-03-30T20:12:21.249Z","etag":null,"topics":["alpha","aws","axios","lambda-alias","lambda-functions","team-infra"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lifeomic.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"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":"2018-06-01T14:28:33.000Z","updated_at":"2024-12-16T21:08:58.000Z","dependencies_parsed_at":"2023-11-14T15:30:43.913Z","dependency_job_id":"61a8c8ae-0aab-4d35-86be-a394abba9cd4","html_url":"https://github.com/lifeomic/alpha","commit_stats":{"total_commits":193,"total_committers":23,"mean_commits":8.391304347826088,"dds":0.8186528497409327,"last_synced_commit":"822a11733175360fd5063176ce599675dc7e8dc4"},"previous_names":[],"tags_count":80,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lifeomic%2Falpha","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lifeomic%2Falpha/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lifeomic%2Falpha/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lifeomic%2Falpha/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lifeomic","download_url":"https://codeload.github.com/lifeomic/alpha/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247557770,"owners_count":20958047,"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":["alpha","aws","axios","lambda-alias","lambda-functions","team-infra"],"created_at":"2024-11-12T00:25:17.824Z","updated_at":"2025-04-06T22:12:16.014Z","avatar_url":"https://github.com/lifeomic.png","language":"TypeScript","readme":"# alpha\n\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n[![Build Status](https://travis-ci.org/lifeomic/alpha.svg?branch=master)](https://travis-ci.org/lifeomic/alpha)\n[![Coverage Status](https://coveralls.io/repos/github/lifeomic/alpha/badge.svg?branch=master)](https://coveralls.io/github/lifeomic/alpha?branch=master)\n[![Greenkeeper badge](https://badges.greenkeeper.io/lifeomic/alpha.svg)](https://greenkeeper.io/)\n[![Known Vulnerabilities](https://snyk.io/test/github/lifeomic/alpha/badge.svg?targetFile=package.json)](https://snyk.io/test/github/lifeomic/alpha?targetFile=package.json)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/lifeomic/alpha)\n\nAlpha is a module that provides a single client interface for interacting with\nHTTP micro-services regardless of whether they are implemented as Lambda\nfunctions or real HTTP servers.\n\n## API\n\n`Alpha` instances are [`axios`][axios] clients at their core. This means that they\nsupport the full `axios` API. The difference is how `Alpha` instances are\ninstantiated. Regardless of how an `Alpha` instance is instantiated, requests\nto fully qualified HTTP URLs will _always_ perform a real HTTP request. Requests\nmade to Lambda functions with a `Buffer` payload will automatically encode the\nrequest body using the base64 encoding.\n\n### `new Alpha(target)`\n\nCreates a new `Alpha` instances. All `Alpha` instances support the full\n[`axios`][axios] API.\n\n#### HTTP Targets\n\nWhen an `Alpha` instance is created with an HTTP(S) base URL target, requests to\nunqualified URLs will be relative to the base URL. For example, the following\ncode will dispatch the request to `http://example.com/some/path`.\n\n```javascript\nconst alpha = new Alpha('http://example.com');\nconst response = await alpha.get('/some/path');\n```\n\n#### Lambda Function Targets\n\nWhen an `Alpha` instance is created with a base URL using the `lambda` scheme,\nrequests to unqualified URLs will cause the specified [Lambda function][lambda]\nto be invoked with a synthetic [API Gateway][api-gateway] event using the\noptional [Lambda alias][lambda-alias]. For example, the following code will\ninvoke the `test-function` Lambda function with the `named-alias`.\n\n```javascript\nconst alpha = new Alpha('lambda://test-function:named-alias');\nconst response = await alpha.get('/some/path');\n```\n\nThe `lambda` URL scheme is interpreted according to the following pattern:\n\n```xml\n    lambda://\u003cfunction-name\u003e:\u003cnamed-alias\u003e\n```\n\n#### Lambda Handler Targets\n\nWhen an `Alpha` instance is created with a handler function target, requests to\nunqualified URLs will be transformed into synthetic [API Gateway (v1)][api-gateway]\nevents that will be passed directly to the handler function. This is primarily\nused for unit testing Lambda handlers.\n\n```javascript\nconst alpha = new Alpha(handlerFunction);\nconst response = await alpha.get('/some/path');\n```\n\n### Request Retries\n\nAn `Alpha` client can be configured to retry a failed attempt. A retryable failure\ncurrently means a request that failed from a network error or had a `5xx` status\ncode.\n\n```javascript\n// Retry failed requests using default settings\nconst alpha = new Alpha('http://example.com', { retry: true });\n```\n\n```javascript\n// Retry failed requests using custom settings\nconst alpha = new Alpha('http://example.com', { retry: {\n    attempts: 3,        // The number of attempts to make (default 3)\n    factor: 2,          // The factor to use for the exponential backoff delay (default 2)\n    maxTimeout: 10000,  // The max timeout in milliseconds to delay before the next attempt (default 10000)\n    retryCondition: function (error) { } // If function result is truthy, the error will be retried (default is retry network and 5xx errors)\n  });\n```\n\n#### Mocking Lambda\n\nTo redirect the Lambda requests to a mocked implementation, either set the\n`LAMBDA_ENDPOINT` environment variable, or use the `lambdaEndpoint` config option:\n\n```javascript\nconst alpha = new Alpha('lambda:my-lambda', { \n  lambdaEndpoint: 'http://localstack:4566'\n});\n```\n\nThe value of this option will be used when creating the AWS Lambda client.\n\n### `Alpha.dockerLambda(options, clientOptions)`\n\nCreates an `Alpha` client instance that dispatches requests to\n[`docker-lambda`][docker-lambda]. This facilitates testing Lambda services in a\nfull mock Lambda environment running in a docker container. The `options` are\npassed to the [`docker-lambda`][docker-lambda] library and the `clientOptions`\nconfigure the `Alpha` client instance that is created.\n\n[api-gateway]: https://aws.amazon.com/documentation/apigateway/ \"AWS API Gateway\"\n[axios]: https://github.com/mzabriskie/axios \"Axios\"\n[docker-lambda]: https://github.com/lambci/docker-lambda \"docker-lambda\"\n[lambda]: https://aws.amazon.com/documentation/lambda/ \"AWS Lambda\"\n[lambda-alias]: https://docs.aws.amazon.com/lambda/latest/dg/versioning-aliases.html \"AWS Lambda Versioning / Aliases\"\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flifeomic%2Falpha","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flifeomic%2Falpha","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flifeomic%2Falpha/lists"}