UNPKG

@itwin/access-control-client

Version:

Access control client for the iTwin platform

100 lines 4.58 kB
/** @packageDocumentation * @module AccessControlClient */ import type { AccessToken } from "@itwin/core-bentley"; import type { BentleyAPIResponse, Method, ODataQueryParams, RequestConfig } from "../types/CommonApiTypes"; import { ParameterMapping } from "../types/typeUtils"; /** * Base client class providing common functionality for Access Control API requests. * Handles authentication, request configuration, and query string building, and error validation. */ export declare class BaseClient { protected _baseUrl: string; /** * Creates a new BaseClient instance for Access Control API operations * @param url - Optional custom base URL, defaults to production iTwins API URL * * @example * ```typescript * // Use default production URL * const client = new BaseClient(); * * // Use custom URL for development/testing * const client = new ITwinsAccessClient("https://api.bentley.com/accesscontrol/itwins"); * ``` */ constructor(url?: string); /** * Maps the some properties of {@link ODataQueryParams} to their corresponding query parameter names. * * @remarks * This mapping is used to translate internal property names to the expected parameter names * when constructing requests. Properties mapped to empty strings are excluded from * the query string as they should be sent as headers instead. * * The mapping includes OData query parameters (prefixed with $) for pagination. * * @readonly */ protected static readonly paginationParamMapping: ParameterMapping<Pick<ODataQueryParams, "top" | "skip">>; /** * Sends a basic API request to the specified URL with the given method and data. * @param accessToken The client access token * @param method The HTTP method of the request (GET, POST, DELETE, etc) * @param url The URL of the request * @param data Optional request body data * @param property Optional property name to extract from response data * @param additionalHeaders Optional additional headers to include in the request * @returns Promise resolving to a BentleyAPIResponse containing the response data or error */ protected sendGenericAPIRequest<TResponse = unknown, TData = unknown>(accessToken: AccessToken, method: Method, url: string, data?: TData, property?: string, additionalHeaders?: Record<string, string>): Promise<BentleyAPIResponse<TResponse>>; /** * Build the request configuration including method, headers, and body * @param accessTokenString The client access token * @param method The HTTP method of the request * @param url The URL of the request * @param data Optional request body data * @param additionalHeaders Optional additional headers to include in the request * @returns RequestConfig object with method, url, body, and headers */ protected getRequestOptions<TData>(accessTokenString: AccessToken, method: Method, url: string, data?: TData, additionalHeaders?: Record<string, string>): RequestConfig; /** * Builds a query string to be appended to a URL from query arguments * @param parameterMapping - Parameter mapping configuration that maps object properties to query parameter names * @param queryArg - Object containing queryable properties for filtering * @returns Query string with parameters applied, ready to append to a URL * * @example * ```typescript * const queryString = this.getQueryString( * BaseClient.paginationParamMapping, * { * top: 10, * skip: 5, * } * ); * // Returns: "$top=10&$skip=5" * ``` */ protected getQueryString<T>(parameterMapping: ParameterMapping<NonNullable<T>>, queryArg?: T): string; /** * Helper method to build query parameter array from mapping. * Uses exhaustive parameter mapping to ensure type safety and prevent missing parameters. * Automatically handles URL encoding and filters out excluded parameters. * * @param queryArg - Object containing queryable properties * @param mapping - Parameter mapping configuration that maps object properties to query parameter names * @returns Array of formatted query parameter strings ready for URL construction * * @example * ```typescript * const params = this.buildQueryParams( * { top: 10, skip: 5 }, * { top: "$top", skip: "$skip" } * ); * // Returns: ["$top=10", "$skip=5"] * ``` */ private buildQueryParams; } //# sourceMappingURL=BaseClient.d.ts.map