///
import { Cloudevent } from './cloudevent';
import { JwtClaims } from './jwt-claims';
/**
* A metadata value. Can either be a string or a buffer.
*
* @public
*/
export declare type MetadataValue = string | Buffer;
/**
* A metadata entry.
*
* @public
*/
export interface MetadataEntry {
/**
* The key for this metadata entry.
*/
readonly key: string;
/**
* The entry value as bytes.
*/
readonly bytesValue: Buffer | undefined;
/**
* The entry value as a string.
*/
readonly stringValue: string | undefined;
}
/** @public */
export interface MetadataMap {
[key: string]: string | Buffer | undefined;
}
/**
* A principal associated with a request.
* @public
*/
export declare type Principal = PredefinedPrincipal | LocalServicePrincipal;
/**
* Predefined principals
* @public
*/
export declare enum PredefinedPrincipal {
Internet = 0,
Self = 1,
Backoffice = 2
}
/**
* A principal for a request from another service in the same Kalix Project
* @public
*/
export declare class LocalServicePrincipal {
/**
* The name the requesting service is deployed as
*/
readonly name: string;
constructor(name: string);
}
/**
* The principals associated with a request.
* @public
*/
export interface Principals {
/** Whether this request was from the internet. */
isInternet(): boolean;
/** Whether this is a self request. */
isSelf(): boolean;
/** Whether this request is a backoffice request. */
isBackoffice(): boolean;
/**
* Whether this request was from a service in the local project.
*
* @param name The name of the service.
*/
isLocalService(name: string): boolean;
/** Whether this request was from any service in the local project. */
isAnyLocalService(): boolean;
/** Get the service that invoked this call, if any. */
getLocalService(): string | undefined;
/** Get the principals associated with this request. */
get(): Array;
}
/**
* Kalix metadata.
*
* Metadata is treated as case insensitive on lookup, and case sensitive on set. Multiple values per key are supported,
* setting a value will add it to the current values for that key. You should delete first if you wish to replace a
* value.
*
* Values can either be strings or byte buffers. If a non string or byte buffer value is set, it will be converted to
* a string using toString.
*
* @param entries - the list of entries
*
* @public
*/
export declare class Metadata {
readonly entries: MetadataEntry[];
/**
* The metadata expressed as an object/map.
*
* @remarks
*
* The map is backed by the this Metadata object - changes to this map will be reflected in this metadata object and
* changes to this object will be reflected in the map.
*
* The map will return the first metadata entry that matches the key, case insensitive, when properties are looked up.
* When setting properties, it will replace all entries that match the key, case insensitive.
*/
readonly asMap: MetadataMap;
/**
* The Cloudevent data from this Metadata.
*
* @remarks
* This object is backed by this Metadata, changes to the Cloudevent will be reflected in the Metadata.
*/
readonly cloudevent: Cloudevent;
/**
* The JWT claims, if there was a validated bearer token with this request.
*/
readonly jwtClaims: JwtClaims;
constructor(entries?: MetadataEntry[]);
/**
* Set the HTTP status code for the response when sending a successful response using HTTP transcoding.
*
* @remarks
* This will only apply to responses that are being transcoded to plain HTTP from gRPC using the protobuf HTTP
* annotations. When gRPC is being used, calling this has no effect.
*
* @param code - The HTTP status code to set
*/
setHttpStatusCode(code: number): void;
/**
* Get the CloudEvent subject from the metadata.
*
* @returns CloudEvent subject value
*
* @deprecated Use {@link Cloudevent.subject} via {@link Metadata.cloudevent} instead.
*/
getSubject(): MetadataValue | undefined;
/**
* Create a new MetadataEntry.
*
* @param key - the key for the entry
* @param value - the value for the entry
* @returns a new MetadataEntry
*/
private createMetadataEntry;
/**
* Get the value from a metadata entry.
*
* @param entry - the metadata entry
* @returns the value for the given entry
*/
private getValue;
/**
* Get all the values for the given key.
*
* @remarks
* The key is case insensitive.
*
* @param key - the key to get
* @returns all the values, or an empty array if no values exist for the key
*/
get(key: string): MetadataValue[];
/**
* Set a given key value.
*
* @remarks
* This will append the key value to the metadata, it won't replace any existing values for existing keys.
*
* @param key - the key to set
* @param value - the value to set
* @returns this updated metadata
*/
set(key: string, value: any): Metadata;
/**
* Delete all values with the given key.
*
* @remarks
* The key is case insensitive.
*
* @param key - the key to delete
* @returns this updated metadata
*/
delete(key: string): this;
/**
* Whether there exists a metadata value for the given key.
*
* @remarks
* The key is case insensitive.
*
* @param key - the key to check
* @returns whether values exist for the given key
*/
has(key: string): boolean;
/**
* Clear the metadata.
*
* @returns this updated metadata
*/
clear(): this;
/**
* Get the Principals associated with this request.
*/
principals(): Principals;
}