@eclipse-ditto/ditto-javascript-client-dom
Version:
DOM implementation of Eclipse Ditto JavaScript API to be used in browsers.
125 lines • 4.52 kB
TypeScript
/*!
* Copyright (c) 2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
import { DittoHeaders } from '../model/ditto-protocol';
export { AuthProvider, DittoHeaders, DittoURL, DittoURLParams, authenticateWithUrl, authenticateWithHeaders, authenticateWithUrlAndHeaders, ImmutableURL };
/**
* Query Parameters that can be used in a Ditto URL.
*/
declare type DittoURLParams = string[];
/**
* URL splitted into its parts.
*/
interface DittoURL {
/**
* Protocol of the URL, e.g. http, wss, ...
*/
readonly protocol: string;
/**
* Domain of the URL, e.g. ditto.eclipse.org, localhost, ...
*/
readonly domain: string;
/**
* Path for the URL, e.g. /api/2/things
*/
readonly path: string;
/**
* Params for the url, e.g. ['x-correlation-id=myCorrelationid', 'x-ditto-pre-authenticated=nginx:ditto']
*/
readonly queryParams: DittoURLParams;
/**
* Use the given protocol for the url.
* @param protocol - e.g. http, wss, ...
* @return the url object for method chaining.
*/
withProtocol(protocol: string): DittoURL;
/**
* Use the given domain for the url.
* @param domain - e.g. ditto.eclipse.org, localhost, ...
* @return the url object for method chaining.
*/
withDomain(domain: string): DittoURL;
/**
* Use the given path for the url.
* @param path - e.g. /api/2/things
* @return the url object for method chaining.
*/
withPath(path: string): DittoURL;
/**
* Use the given queryParams for the url.
* @param params - e.g. ['x-correlation-id=myCorrelationId', 'x-ditto-pre-authenticated=nginx:ditto']
* @return the url object for method chaining.
*/
withParams(params: DittoURLParams): DittoURL;
/**
* Convert to string.
* @return string representation of the url, e.g.
* https://ditto.eclipse.org/api/2/things?x-correlation-id=myCorrelationId&x-ditto-pre-authenticated=nginx:ditto
*/
toString(): string;
}
/**
* Immutable implementation of DittoURL.
*/
declare class ImmutableURL implements DittoURL {
readonly protocol: string;
readonly domain: string;
readonly path: string;
readonly queryParams: DittoURLParams;
private constructor();
static newInstance(protocol: string, domain: string, path: string, params?: DittoURLParams): DittoURL;
withProtocol(protocol: string): ImmutableURL;
withDomain(domain: string): ImmutableURL;
withPath(path: string): ImmutableURL;
withParams(params: string[]): ImmutableURL;
toString(): string;
}
/**
* Provides authentication or authorization.
*/
interface AuthProvider {
/**
* Enhance the url with authentication or authorization.
* @param originalUrl - the URL to enhance.
* @return the enchanced URL.
*/
authenticateWithUrl(originalUrl: DittoURL): DittoURL;
/**
* Enhance the headers with authentication or authorization.
* @param originalHeaders - the headers to enhance.
* @return the enhanced Headers.
*/
authenticateWithHeaders(originalHeaders: DittoHeaders): DittoHeaders;
}
/**
* Enhance the url with all auth providers.
* @param originalUrl - the url to enhance.
* @param authProviders - the auth providers to apply.
* @return the enhanced url.
*/
declare const authenticateWithUrl: (originalUrl: DittoURL, authProviders: AuthProvider[]) => DittoURL;
/**
* Enhance the headers with all auth providers.
* @param originalHeaders - the headers to enhance.
* @param authProviders - the auth providers to apply.
* @return the enhanced headers.
*/
declare const authenticateWithHeaders: (originalHeaders: DittoHeaders, authProviders: AuthProvider[]) => DittoHeaders;
/**
* Enhance the url and headers with all auth providers.
* @param originalUrl - the url to enhance.
* @param originalHeaders - the headers to enhance.
* @param authProviders - the auth providers to apply.
* @return the enhanced url and headers.
*/
declare const authenticateWithUrlAndHeaders: (originalUrl: DittoURL, originalHeaders: DittoHeaders, authProviders: AuthProvider[]) => [DittoURL, DittoHeaders];
//# sourceMappingURL=auth-provider.d.ts.map