webpods
Version:
Append-only log service with OAuth authentication
96 lines • 2.95 kB
TypeScript
/**
* Utility functions for WebPods
*/
/**
* Validate pod ID (subdomain)
* Must be lowercase alphanumeric with hyphens, max 63 chars
*/
export declare function isValidPodId(podId: string): boolean;
/**
* Validate stream ID
* Alphanumeric, underscore, hyphen, slash for nested paths, single dots allowed (no consecutive dots)
* Max 256 chars
*/
export declare function isValidStreamId(streamId: string): boolean;
/**
* Check if stream ID is a system stream (starts with .meta/)
*/
export declare function isSystemStream(streamId: string): boolean;
/**
* Validate name - must be like a filename
* Allowed characters: a-z, A-Z, 0-9, hyphen (-), underscore (_), period (.)
* Cannot start or end with a period (to avoid . and .. confusion)
* Cannot contain slashes or other special characters
*/
export declare function isValidName(name: string): boolean;
/**
* Parse index query parameter (e.g., "0", "-1", "10:20")
*/
export declare function parseIndexQuery(query: string): {
type: "single" | "range";
start: number;
end?: number;
} | null;
/**
* Calculate SHA-256 hash for record
*/
export declare function calculateRecordHash(previousHash: string | null, timestamp: string, content: any): string;
/**
* Check if a hostname is the main domain
*/
export declare function isMainDomain(hostname: string, configuredDomain: string): boolean;
/**
* Check if a hostname is a subdomain of the main domain
*/
export declare function isSubdomainOf(hostname: string, mainDomain: string): boolean;
/**
* Extract pod ID from hostname
*/
export declare function extractPodId(hostname: string, mainDomain?: string): string | null;
/**
* Parse permission string
*/
export declare function parsePermission(permission: string): {
type: "public" | "private" | "allow" | "deny";
streams: string[];
};
/**
* Detect content type from headers
*/
export declare function detectContentType(headers: Record<string, string | string[] | undefined>): string;
/**
* Check if a string is a valid index (numeric)
*/
export declare function isNumericIndex(str: string): boolean;
/**
* Get IP address from request
*/
export declare function getIpAddress(req: any): string;
/**
* Supported content types for direct serving
*/
export declare const SERVABLE_CONTENT_TYPES: string[];
/**
* Binary content types that need base64 encoding
*/
export declare const BINARY_CONTENT_TYPES: string[];
/**
* Check if content type is servable
*/
export declare function isServableContentType(contentType: string): boolean;
/**
* Check if content type is binary
*/
export declare function isBinaryContentType(contentType: string): boolean;
/**
* Validate base64 string
*/
export declare function isValidBase64(str: string): boolean;
/**
* Extract base64 data and content type from data URL
*/
export declare function parseDataUrl(dataUrl: string): {
contentType: string;
data: string;
} | null;
//# sourceMappingURL=utils.d.ts.map