Skip to content

node-zendesk / Exports / clients/helpers

Module: clients/helpers

Table of contents

Functions

Functions

assembleUrl

assembleUrl(self, method, uri?): string

Constructs a URL based on the provided method, uri, and pre-defined settings within the context.

The function prioritizes query parameters from self.options.get('query') over other sources. If uri is an array, the last element can be an object representing query parameters or a query string. If the uri is a string, it's treated as the URL's endpoint path.

The function also utilizes self.sideLoad to include side-loaded resources if available. Any conflict in query parameters is resolved with query taking the highest priority, followed by sideLoad, and then the provided uri.

Parameters

NameTypeDescription
selfobjectThe context containing options and side-loading settings.
methodstringThe HTTP method. Can be "GET", "PATCH", "POST", "PUT", or "DELETE".
uri?(string | object)[]An array representing the URL segments. The last element can be an object of query parameters or a query string.

Returns

string

The assembled URL.

Throws

Will throw an error if self.options does not implement the 'get' method.

Example

ts
const context = {
  options: new Map([['endpointUri', 'http://api.example.com'], ['query', { page: { size: 100 } }]]),
  sideLoad: ['comments', 'likes']
};
assembleUrl(context, 'GET', ['users', 'list', '?foo=bar']);
// Expected: "http://api.example.com/users/list.json?foo=bar&include=comments,likes&page[size]=100"

Defined in

clients/helpers.d.ts:32


checkRequestResponse

checkRequestResponse(response, result): object

Checks the response and result from a request and returns an error or the result.

Parameters

NameTypeDescription
responseobjectThe HTTP response object.
resultobjectThe result data from the request.

Returns

object

  • The result or an error object.

Defined in

clients/helpers.d.ts:39


flatten

flatten(array): any[]

Flattens a nested array to a single-level array.

Parameters

NameTypeDescription
arrayany[]The array to be flattened.

Returns

any[]

  • A new array containing all elements from the input array, with any nested arrays recursively flattened to a single level.

Defined in

clients/helpers.d.ts:7


generateUserAgent

generateUserAgent(): string

Generates a user agent string based on the package version and node version.

Returns

string

  • The generated user agent string.

Defined in

clients/helpers.d.ts:51


processResponseBody

processResponseBody(result_, self): object

Processes the body of the response based on the result and context.

Parameters

NameTypeDescription
result_objectThe result data.
selfobjectThe context containing additional settings.

Returns

object

  • The processed body of the response.

Defined in

clients/helpers.d.ts:46

Released under the MIT License.