Members
assert
The related issue: https://github.com/badges/shields/issues/11071
The code below is a modified version of the original http-deceiver library. It has been adapted to work with Node.js versions that have deprecated the original implementation.
The original library can be found at: https://github.com/spdy-http2/http-deceiver (MIT License)
This version is specifically tailored to handle the deprecation of
the http_parser module in Node.js v12 and later.
https://github.com/beenotung/http-deceiver/blob/node-v12-deprecation-fix/lib/deceiver.js (MIT License)
It maintains compatibility with older Node.js versions while providing a consistent interface for HTTP request and response parsing.
- Source:
Methods
_formatLabelForStage(stage, label) → {string}
Formats a stage label with a coloured background for console output.
Parameters:
| Name | Type | Description |
|---|---|---|
stage |
'inbound' | 'fetch' | 'validate' | 'unhandledError' | 'outbound' | Pipeline stage name. |
label |
string | Text to display inside the coloured badge. |
- Source:
Returns:
ANSI-coloured label string.
- Type
- string
createNumRequestCounter(attrs) → {object}
Parameters:
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
attrs |
object | Refer to individual attrs Properties
|
Returns:
{ inc() {} }.
- Type
- object
escapeFormat(t) → {string}
Escape a string according to the badge format encoding scheme. Underscores and dashes in the input are decoded using the rules from https://github.com/espadrine/gh-badges/issues/12#issuecomment-31518129
Single underscores become spaces, double underscores become single underscores, and double dashes become single dashes.
Parameters:
| Name | Type | Description |
|---|---|---|
t |
string | The format-encoded string to decode. |
- Source:
Returns:
The decoded string.
- Type
- string
fakeJwtToken() → {string}
Generate a fake JWT Token valid for 1 hour for use in testing.
- Source:
Returns:
Fake JWT Token valid for 1 hour.
- Type
- string
generateFakeConfig(serviceClass, fakeKey, fakeUser, fakeauthorizedOrigins, authOverride) → {object}
Generates a configuration object with a fake key based on the provided class. For use in auth tests where a config with a test key is required.
Parameters:
| Name | Type | Description |
|---|---|---|
serviceClass |
BaseService | The class to generate configuration for. |
fakeKey |
string | The fake key to be used in the configuration. |
fakeUser |
string | Optional, The fake user to be used in the configuration. |
fakeauthorizedOrigins |
Array.<string> | authorizedOrigins to add to config. |
authOverride |
object | Return result with overrid params. |
- Source:
Throws:
-
- Throws an error if the input is not a class.
- Type
- TypeError
Returns:
- The configuration object.
- Type
- object
generateInstanceId() → {string}
Generate a random 9-character alphanumeric instance identifier.
Returns:
Random identifier (e.g. a1b2c3d4e).
- Type
- string
getBadgeExampleCall(serviceClass, paramType) → {object}
Retrieves an example set of parameters for invoking a service class using OpenAPI example of that class.
Parameters:
| Name | Type | Description |
|---|---|---|
serviceClass |
BaseService | The service class containing OpenAPI specifications. |
paramType |
'path' | 'query' | The type of params to extract, may be path params or query params. |
- Source:
Throws:
-
- Throws a TypeError if the input
serviceClassis not an instance of BaseService, or if it lacks the expected structure.
- Throws a TypeError if the input
- Type
- TypeError
Returns:
An object with call params to use with a service invoke of the first OpenAPI example.
- Type
- object
Example
// Example usage:
const example = getBadgeExampleCall(StackExchangeReputation)
console.log(example)
// Output: { stackexchangesite: 'stackoverflow', query: '123' }
StackExchangeReputation.invoke(defaultContext, config, example)
getServiceClassAuthOrigin(serviceClass, authOverride, configOverride) → {Array.<string>}
Returns the first auth origin found for a provided service class.
Parameters:
| Name | Type | Description |
|---|---|---|
serviceClass |
BaseService | The service class to find the authorized origins. |
authOverride |
object | Return result with overridden params. |
configOverride |
object | Override the config. |
- Source:
Throws:
-
- Throws a TypeError if the input
serviceClassis not an instance of BaseService.
- Throws a TypeError if the input
- Type
- TypeError
Returns:
First auth origin found.
- Type
- Array.<string>
Example
// Example usage:
getServiceClassAuthOrigin(Obs)
// outputs ['https://api.opensuse.org']
getUserAgent(userAgentBaseopt) → {string}
Build the User-Agent string for outgoing HTTP requests. Incorporates the configured base name and, when available, a version from the deployment environment (Docker image version or Heroku slug commit).
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
userAgentBase |
string |
<optional> |
Base name for the user-agent. Defaults to
the configured |
- Source:
Returns:
Formatted user-agent string (e.g. shields/abc1234).
- Type
- string
legacySonarResponse(key, val) → {object}
Returns a legacy sonar api response with desired key and value
Parameters:
| Name | Type | Description |
|---|---|---|
key |
string | Key for the response value |
val |
string | number | Value to assign to response key |
Returns:
Sonar api response
- Type
- object
logTrace(stage, symbol, label, content, optionsopt) → {boolean}
Logs a trace message to the console when trace logging is enabled in config.
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
stage |
'inbound' | 'fetch' | 'validate' | 'unhandledError' | 'outbound' | Pipeline stage used to colour the label. |
||||||||||||
symbol |
string | Short symbol or emoji prefixed to the log line. |
||||||||||||
label |
string | Descriptive label shown alongside the symbol. |
||||||||||||
content |
* | Data to print; logged with |
||||||||||||
options |
object |
<optional> |
{} | Optional logging configuration. Properties
|
- Source:
Returns:
true if the message was logged, false when trace logging is disabled.
- Type
- boolean
module:services/dynamic/json-path(superclass) → {function}
Dynamic service class factory which wraps module:core/base-service/base~BaseService with support of JSONPath.
Parameters:
| Name | Type | Description |
|---|---|---|
superclass |
function | class to extend |
- Source:
Returns:
wrapped class
- Type
- function
noteGithubTokenInvalidation(attrs)
Record that a GitHub token was invalidated and removed from the pool.
Parameters:
| Name | Type | Description | ||||||
|---|---|---|---|---|---|---|---|---|
attrs |
object | Attributes Properties
|
parseJson(buffer) → {object|Array}
Parse a JSON response buffer. Throws an InvalidResponse error when the
JSON is unparseable.
Parameters:
| Name | Type | Description |
|---|---|---|
buffer |
string | Buffer | The raw response body. |
- Source:
Returns:
The parsed JSON value.
- Type
- object | Array
parseJsonl(buffer) → {Array.<object>}
Parse a JSONL (newline-delimited JSON) response buffer. Splits the buffer
by newlines, trims each line, filters empty lines, and parses each line
as JSON. Throws an InvalidResponse error when any line is unparseable.
Parameters:
| Name | Type | Description |
|---|---|---|
buffer |
string | Buffer | The raw response body. |
- Source:
Returns:
Array of parsed JSON values, one per line.
- Type
- Array.<object>
rasterRedirectUrl(options, badgeUrl) → {string}
Build a redirect URL for the raster (non-SVG) badge variant. Preserves the path and query string from the original badge request.
Parameters:
| Name | Type | Description | ||||||
|---|---|---|---|---|---|---|---|---|
options |
object | Options for the redirect. Properties
|
||||||
badgeUrl |
string | The original badge request URL. |
- Source:
Returns:
Redirect URL pointing to the raster endpoint.
- Type
- string
(async) testAuth(serviceClass, authMethod, dummyResponse, options)
Test authentication of a badge for it's first OpenAPI example using a provided dummyResponse and authentication method.
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
serviceClass |
BaseService | The service class tested. |
||||||||||||||||||||||||||||||
authMethod |
'BasicAuth' | 'ApiKeyHeader' | 'BearerAuthHeader' | 'QueryStringAuth' | 'JwtAuth' | The auth method of the tested service class. |
||||||||||||||||||||||||||||||
dummyResponse |
object | An object containing the dummy response by the server. |
||||||||||||||||||||||||||||||
options |
object | Additional options for non default keys and content-type of the dummy response. Properties
|
- Source:
Throws:
-
- Throws a TypeError if the input
serviceClassis not an instance of BaseService, or ifserviceClassis missing authorizedOrigins.
- Throws a TypeError if the input
- Type
- TypeError
Example
// Example usage:
testAuth(StackExchangeReputation, QueryStringAuth, { items: [{ reputation: 8 }] })