import { ConfigService } from '@nestjs/config'; import { Observable } from 'rxjs'; import { S as SmpEnvironmentVariables, a as SmpWinstonLoggerService } from './smp-winston-logger-service.class-CltMrgeM.js'; import { S as SmpCacheInterceptorStrategy } from './smp-cache-interceptor-strategy.class-CMO0pOJC.js'; import { Timestamp, Firestore, DocumentData, Query } from 'firebase-admin/firestore'; import { App, ServiceAccount } from 'firebase-admin/app'; import { SmpBaseJwtTokenPlain } from '@tonysamperi/ts-mapi-core'; import { DynamicModule, ModuleMetadata } from '@nestjs/common'; import 'zod'; import 'url'; import '@tonysamperi/logger'; import 'winston'; import 'winston-transport'; import '@tonysamperi/ts-mapi-core/rxjs'; type SmpFirestorePlainCacheDocument = Pick; type SmpFirestoreMappedCacheDocument = Pick & { expiry: Timestamp | undefined; }; declare class SmpFirestoreCacheDocument { get createdOn(): number; get expiry(): number | undefined; get key(): string; get value(): T; protected _createdOn: number; protected _expiry?: number; protected _key: string; protected _value: T; constructor(key: string, value: T, ttl?: number); static fromFirestoreDocument(doc: SmpFirestoreMappedCacheDocument): SmpFirestoreCacheDocument; static fromPlain(plain: SmpFirestorePlainCacheDocument): SmpFirestoreCacheDocument; /** * Converts the instance to a Firestore-compatible document object */ toFirestoreDocument(): SmpFirestoreMappedCacheDocument; /** * Converts the instance to a plain object with expiry a number */ toPlain(): SmpFirestorePlainCacheDocument; } /** * This provider is meant to be used with the SmpCacheInterceptor. Don't use it directly unless you know what you're doing. * Note: we don't pass the ttl to the inner strategy, otherwise the value gets wrapped. * In firestore the expiry is part of the document, and the deletion is managed by Firebase automagically (by defining a TTL rule on the collection) */ declare class SmpCacheInterceptorFirestoreStrategy extends SmpCacheInterceptorStrategy { protected readonly _configSrv: ConfigService; protected readonly _loggerSrv: SmpWinstonLoggerService; get collectionName(): string; private _firestoreSrv; constructor(_configSrv: ConfigService, _loggerSrv: SmpWinstonLoggerService); removeByPrefix(prefix: string): Observable; write(key: string, value: T, ttl?: number): Observable; protected _flushRaw(): Observable; protected _readRaw(key: string): Observable | undefined>; protected _removeRaw(key: string): Observable; protected _writeRaw(key: string, value: any, ttl?: number): Observable; } /** * This is a base Firestore interface offered by the library. * It uses the Firestore API to read/write to Firestore * You can override the default values by defining them in your env files. * You can also pass a custom logger service to the SmpConfigModule.forRoot method. To not use this one. * * Call the _init method whenever you're ready */ declare abstract class SmpAbstractFirestoreService { protected readonly _configSrv: ConfigService; protected readonly _loggerSrv: SmpWinstonLoggerService; protected _app: App; protected _appName: string; protected _collectionName: string; protected _db: Firestore; private _googleCredentials; constructor(_configSrv: ConfigService, _loggerSrv: SmpWinstonLoggerService); protected _init(): void; protected _millisToTimestamp(millis: number): Timestamp; protected _send(query: Query): Observable; protected _validateAccess(): Observable<{ read: boolean; write: boolean; }>; private _checkReadAccess; private _checkWriteAccess; private _parseCredentials; } /** * This basically allow you to create a firestore token service with a few lines of code * * @example * ```ts * export class SmpFirestoreFooTokenService extends SmpAbstractFirestoreTokenService { * * protected override _tokenKey: string = "foo"; * * // @ts-expect-error we're sure this will work * override getToken() { * return super.getToken() * .pipe(map((item) => { * (this.constructor as typeof SmpFirestoreFooTokenService).checkJwtToken(item); * * return item; * })); * } * } * ``` * */ declare class SmpAbstractFirestoreTokenService extends SmpAbstractFirestoreService { protected _appName: string; protected _collectionName: string; protected _tokenKey: string; constructor(configSrv: ConfigService, loggerSrv: SmpWinstonLoggerService); /** * Decodes jwt token and throws if expired */ checkJwtToken(t: string): void; createJwtToken(data: T): string; /** * Retrieve the full transaction from the transaction hash * Returns an Observable that emits the transaction string or an empty string if not found. */ getToken(): Observable; putToken(token: T): Observable; } /** * This is a base GCP Storage interface offered by the library. * You can override the default values by defining them in your env files. * You can also pass a custom logger service to the SmpConfigModule.forRoot method. To not use this one. * * Call the _init method whenever you're ready */ declare abstract class SmpAbstractGcpStorageService { protected readonly _configSrv: ConfigService; protected _app: App; protected _appName: string; private _googleCredentials; constructor(_configSrv: ConfigService); getJsonObject(bucketName: string, objectPath: string): Observable; listObjectsByPrefix(bucketName: string, prefix: string): Observable<{ name: string; updatedAt: string; }[]>; putGzipJsonObject(bucketName: string, objectPath: string, payload: unknown): Observable; putJsonObject(bucketName: string, objectPath: string, payload: unknown): Observable; protected _getJsonObjectFromGcs(bucketName: string, objectPath: string): Promise; protected _init(): void; protected _parseCredentials(): ServiceAccount; protected _saveObjectInGcs(bucketName: string, objectPath: string, body: Buffer, contentType: string, contentEncoding?: string): Promise; } declare class SmpFirestoreCacheService extends SmpAbstractFirestoreService { get collectionName(): string; protected _appName: string; protected _batchMaxSize: number; constructor(configSrv: ConfigService, loggerSrv: SmpWinstonLoggerService, collectionName: string); flush(): Observable; get(key: string): Observable; remove(key: string): Observable; /** * Batch removes all cache documents where key starts with string * @param prefix */ removeByPrefix(prefix: string): Observable; set(data: SmpFirestoreCacheDocument): Observable; protected _generateDocumentId(key: string): string; } declare const smpFirestoreModuleFeatures: { SmpCacheInterceptorFirestoreStrategy: { providers: { provide: typeof SmpCacheInterceptorStrategy; useClass: typeof SmpCacheInterceptorFirestoreStrategy; }[]; exports: (typeof SmpCacheInterceptorStrategy)[]; }; }; interface SmpFirestoreModuleOpts { features?: (keyof typeof smpFirestoreModuleFeatures)[]; } declare class SmpFirestoreModule { private static _initialized; constructor(); static forRoot(config?: Partial): DynamicModule; static forRootAsync(factory: () => Promise>): Promise; protected static _getDynamicConfig(features: (keyof typeof smpFirestoreModuleFeatures)[]): ModuleMetadata; } export { SmpAbstractFirestoreService, SmpAbstractFirestoreTokenService, SmpAbstractGcpStorageService, SmpCacheInterceptorFirestoreStrategy, SmpFirestoreCacheDocument, SmpFirestoreCacheService, type SmpFirestoreMappedCacheDocument, SmpFirestoreModule };