@vritti/api-sdk 0.2.2 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,11 +1,13 @@
1
1
  import * as _nestjs_common from '@nestjs/common';
2
- import { DynamicModule, CanActivate, ExecutionContext, InjectionToken, OnModuleInit, OnModuleDestroy, Logger, HttpException, HttpStatus, ExceptionFilter, ArgumentsHost, ModuleMetadata, Type, LoggerService as LoggerService$1, NestInterceptor, CallHandler, NestModule, MiddlewareConsumer, NestMiddleware } from '@nestjs/common';
2
+ import { DynamicModule, CanActivate, ExecutionContext, OnModuleInit, OnModuleDestroy, InjectionToken, Logger, HttpException, HttpStatus, ExceptionFilter, ArgumentsHost, ModuleMetadata, Type, LoggerService as LoggerService$1, NestInterceptor, CallHandler, NestModule, MiddlewareConsumer, NestMiddleware } from '@nestjs/common';
3
3
  import { ConfigService } from '@nestjs/config';
4
4
  import { Reflector } from '@nestjs/core';
5
5
  import { JwtService, JwtModuleOptions, JwtSignOptions } from '@nestjs/jwt';
6
6
  import { FastifyRequest, FastifyReply } from 'fastify';
7
7
  import { NodePgDatabase } from 'drizzle-orm/node-postgres';
8
- import { InferInsertModel, InferSelectModel, SQL } from 'drizzle-orm';
8
+ import * as drizzle_orm from 'drizzle-orm';
9
+ import { Column, SQL, InferInsertModel, InferSelectModel } from 'drizzle-orm';
10
+ import * as drizzle_orm_pg_core from 'drizzle-orm/pg-core';
9
11
  import { PgTable } from 'drizzle-orm/pg-core';
10
12
  import { Observable } from 'rxjs';
11
13
  import { AsyncLocalStorage } from 'node:async_hooks';
@@ -43,10 +45,14 @@ declare class AuthConfigModule {
43
45
 
44
46
  declare const AccessToken: (...dataOrPipes: unknown[]) => ParameterDecorator;
45
47
 
48
+ declare const CookieDomain: (...dataOrPipes: unknown[]) => ParameterDecorator;
49
+
46
50
  declare const Onboarding: () => _nestjs_common.CustomDecorator<string>;
47
51
 
48
52
  declare const Public: () => _nestjs_common.CustomDecorator<string>;
49
53
 
54
+ declare const RefreshCookieOptions: (...dataOrPipes: unknown[]) => ParameterDecorator;
55
+
50
56
  declare const RefreshTokenCookie: (...dataOrPipes: unknown[]) => ParameterDecorator;
51
57
 
52
58
  declare const RESET_KEY = "isReset";
@@ -135,6 +141,44 @@ declare function verifyTokenHash(token: string, expectedHash: string): boolean;
135
141
  declare const SKIP_CSRF_KEY = "skipCsrf";
136
142
  declare const SkipCsrf: () => _nestjs_common.CustomDecorator<string>;
137
143
 
144
+ declare class CacheModule {
145
+ }
146
+
147
+ interface ICacheProvider {
148
+ set<T>(key: string, value: T, ttlSeconds: number): Promise<void>;
149
+ get<T>(key: string): Promise<T | null>;
150
+ del(...keys: string[]): Promise<void>;
151
+ scanKeys(pattern: string): Promise<string[]>;
152
+ getMemoryInfo(): Promise<string>;
153
+ }
154
+
155
+ declare class CacheService {
156
+ private readonly provider;
157
+ private readonly logger;
158
+ constructor(provider: ICacheProvider);
159
+ set<T>(key: string, value: T, ttlSeconds: number): Promise<void>;
160
+ get<T>(key: string): Promise<T | null>;
161
+ del(...keys: string[]): Promise<void>;
162
+ scanKeys(pattern: string): Promise<string[]>;
163
+ getMemoryInfo(): Promise<string>;
164
+ }
165
+
166
+ declare const CACHE_PROVIDER: unique symbol;
167
+
168
+ declare class RedisCacheProvider implements ICacheProvider, OnModuleInit, OnModuleDestroy {
169
+ private readonly configService;
170
+ private readonly logger;
171
+ private client;
172
+ constructor(configService: ConfigService);
173
+ onModuleInit(): void;
174
+ onModuleDestroy(): Promise<void>;
175
+ set<T>(key: string, value: T, ttlSeconds: number): Promise<void>;
176
+ get<T>(key: string): Promise<T | null>;
177
+ del(...keys: string[]): Promise<void>;
178
+ scanKeys(pattern: string): Promise<string[]>;
179
+ getMemoryInfo(): Promise<string>;
180
+ }
181
+
138
182
  interface CookieConfig {
139
183
  refreshCookieName: string;
140
184
  refreshCookieMaxAge: number;
@@ -143,6 +187,14 @@ interface CookieConfig {
143
187
  refreshCookieSameSite: 'strict' | 'lax' | 'none';
144
188
  refreshCookieDomain?: string;
145
189
  }
190
+ interface CookieSerializeOptions {
191
+ httpOnly: boolean;
192
+ secure: boolean;
193
+ sameSite: 'strict' | 'lax' | 'none';
194
+ path: string;
195
+ maxAge: number;
196
+ domain: string;
197
+ }
146
198
  interface JwtConfig {
147
199
  accessTokenExpiry: string;
148
200
  refreshTokenExpiry: string;
@@ -167,7 +219,10 @@ declare function defineConfig(config: ApiSdkConfig): ApiSdkConfig;
167
219
  declare function configureApiSdk(userConfig: ApiSdkConfig): void;
168
220
  declare function getConfig(): FullConfig;
169
221
  declare function resetConfig(): void;
170
- declare function getRefreshCookieOptions(): Record<string, unknown>;
222
+ declare function getRefreshCookieOptions(): Omit<CookieSerializeOptions, 'domain'> & {
223
+ domain?: string;
224
+ };
225
+ declare function getRefreshCookieOptionsForHost(hostname: string): CookieSerializeOptions;
171
226
  declare function getJwtExpiry(): {
172
227
  access: string;
173
228
  refresh: string;
@@ -220,9 +275,73 @@ declare class SelectOptionsQueryDto {
220
275
  excludeIds?: string;
221
276
  valueKey?: string;
222
277
  labelKey?: string;
278
+ descriptionKey?: string;
223
279
  groupIdKey?: string;
224
280
  }
225
281
 
282
+ declare class SuccessResponseDto {
283
+ success: boolean;
284
+ message: string;
285
+ }
286
+
287
+ type FilterOperator = 'equals' | 'notEquals' | 'contains' | 'notContains' | 'gt' | 'gte' | 'lt' | 'lte';
288
+ interface FilterCondition {
289
+ field: string;
290
+ operator: FilterOperator;
291
+ value: string | number;
292
+ }
293
+ interface SortCondition {
294
+ field: string;
295
+ direction: 'asc' | 'desc';
296
+ }
297
+ type DensityType = 'compact' | 'normal' | 'comfortable';
298
+ interface ColumnPinning {
299
+ left: string[];
300
+ right: string[];
301
+ }
302
+ interface SearchState {
303
+ columnId: string;
304
+ value: string;
305
+ }
306
+ interface TableViewState {
307
+ filters: FilterCondition[];
308
+ sort: SortCondition[];
309
+ columnVisibility: Record<string, boolean>;
310
+ columnOrder: string[];
311
+ columnSizing: Record<string, number>;
312
+ columnPinning: ColumnPinning;
313
+ lockedColumnSizing: boolean;
314
+ density: DensityType;
315
+ filterOrder: string[];
316
+ filterVisibility: Record<string, boolean>;
317
+ search?: SearchState | null;
318
+ pagination?: {
319
+ limit: number;
320
+ offset: number;
321
+ };
322
+ }
323
+
324
+ declare class TableResponseDto<T> {
325
+ result: T[];
326
+ count: number;
327
+ state: TableViewState;
328
+ activeViewId: string | null;
329
+ }
330
+
331
+ type FieldDefinition = {
332
+ column: Column;
333
+ type: 'string' | 'number' | 'boolean';
334
+ } | {
335
+ expression: (value: string | number) => SQL;
336
+ type: 'string' | 'number' | 'boolean';
337
+ };
338
+ type FieldMap = Record<string, FieldDefinition>;
339
+ declare class FilterProcessor {
340
+ static buildWhere(filters: FilterCondition[] | undefined, fieldMap: FieldMap): SQL | undefined;
341
+ static buildSearch(search: SearchState | null | undefined, fieldMap: FieldMap): SQL | undefined;
342
+ static buildOrderBy(sort: SortCondition[] | undefined, fieldMap: FieldMap): SQL[];
343
+ }
344
+
226
345
  declare class PrimaryDatabaseService implements OnModuleInit, OnModuleDestroy {
227
346
  private readonly options;
228
347
  private readonly logger;
@@ -233,8 +352,6 @@ declare class PrimaryDatabaseService implements OnModuleInit, OnModuleDestroy {
233
352
  constructor(options: DatabaseModuleOptions);
234
353
  onModuleInit(): Promise<void>;
235
354
  private initializeDrizzleClient;
236
- private buildPrimaryDbUrl;
237
- private maskPassword;
238
355
  getTenantInfo(tenantIdentifier: string): Promise<TenantInfo | null>;
239
356
  private cacheInfo;
240
357
  clearTenantCache(tenantIdentifier: string): void;
@@ -248,6 +365,7 @@ declare class PrimaryDatabaseService implements OnModuleInit, OnModuleDestroy {
248
365
  interface SelectQueryOption {
249
366
  value: string | number | boolean;
250
367
  label: string;
368
+ description?: string;
251
369
  groupId?: string | number;
252
370
  }
253
371
  interface SelectQueryGroup {
@@ -260,9 +378,15 @@ interface SelectQueryResult {
260
378
  hasMore: boolean;
261
379
  totalCount?: number;
262
380
  }
381
+ interface FindForSelectJoin {
382
+ table: PgTable;
383
+ on: SQL;
384
+ type?: 'left' | 'inner';
385
+ }
263
386
  interface FindForSelectConfig {
264
387
  value: string;
265
388
  label: string;
389
+ description?: string;
266
390
  groupId?: string;
267
391
  search?: string;
268
392
  limit?: number;
@@ -275,6 +399,8 @@ interface FindForSelectConfig {
275
399
  groupTable?: PgTable;
276
400
  groupLabelKey?: string;
277
401
  groupIdKey?: string;
402
+ joins?: FindForSelectJoin[];
403
+ conditions?: SQL[];
278
404
  }
279
405
 
280
406
  type RelationsWhereFilter = Record<string, unknown>;
@@ -310,6 +436,21 @@ declare abstract class PrimaryBaseRepository<TTable extends PgTable, TInsert = I
310
436
  limit?: number;
311
437
  offset?: number;
312
438
  }): Promise<TSelect[]>;
439
+ private buildSelectQuery;
440
+ findAllAndCount<TResult = TSelect>(options?: {
441
+ select?: Record<string, unknown>;
442
+ where?: SQL;
443
+ orderBy?: SQL[];
444
+ limit?: number;
445
+ offset?: number;
446
+ leftJoin?: {
447
+ table: PgTable;
448
+ on: SQL;
449
+ };
450
+ }): Promise<{
451
+ result: TResult[];
452
+ count: number;
453
+ }>;
313
454
  update(id: string, data: Partial<TInsert>): Promise<TSelect>;
314
455
  updateMany(where: SQL, data: Partial<TInsert>): Promise<{
315
456
  count: number;
@@ -508,6 +649,8 @@ declare function getHttpStatusTitle(status: number): string;
508
649
  declare class HttpExceptionFilter implements ExceptionFilter {
509
650
  private readonly logger;
510
651
  catch(exception: unknown, host: ArgumentsHost): void;
652
+ private isHttpException;
653
+ private isAxiosError;
511
654
  }
512
655
 
513
656
  type LogLevel = 'error' | 'warn' | 'log' | 'debug' | 'verbose';
@@ -630,4 +773,118 @@ declare function normalizePhoneNumber(phone: string): string;
630
773
 
631
774
  declare function parseExpiryToMs(expiry: string): number;
632
775
 
633
- export { AccessToken, type AccessTokenPayload, type ApiErrorResponse, type ApiSdkConfig, AuthConfigModule, BadGatewayException, BadRequestException, ConflictException, type CookieConfig, type CorrelationContext, CorrelationIdMiddleware, DEFAULT_CORRELATION_HEADER, DatabaseModule, type DatabaseModuleOptions, EmailModule, EmailService, type FieldError, type FindForSelectConfig, ForbiddenException, GoneException, type GuardConfig, HttpExceptionFilter, HttpLoggerInterceptor, type HttpLoggerOptions, HttpProblemException, InternalServerErrorException, JwtAuthService, type JwtConfig, LOGGER_MODULE_OPTIONS, type LogFormat, type LogLevel, type LogMetadata, LoggerModule, type LoggerModuleAsyncOptions, type LoggerModuleOptions, type LoggerOptionsFactory, LoggerService, MethodNotAllowedException, NotAcceptableException, NotFoundException, NotImplementedException, Onboarding, PayloadTooLargeException, PrimaryBaseRepository, PrimaryDatabaseService, type PrimaryDbConfig, type ProblemDetails, type ProblemOptions, Public, RESET_KEY, RefreshTokenCookie, type RefreshTokenPayload, type RegisteredSchema, RequestTimeoutException, Reset, RootModule, SKIP_CSRF_KEY, SelectOptionsQueryDto, type SelectQueryGroup, type SelectQueryOption, type SelectQueryResult, ServiceUnavailableException, SessionData, type SessionInfo, SkipCsrf, Tenant, TenantBaseRepository, TenantContextService, TenantDatabaseService, type TenantInfo, type TokenExpiry, TokenType, TooManyRequestsException, type TypedDrizzleClient, UnauthorizedException, UnprocessableEntityException, UnsupportedMediaTypeException, UserId, ValidationException, VrittiAuthGuard, addCorrelationIdToResponse, configureApiSdk, correlationStorage, defineConfig, extractCountryFromPhone, generateCorrelationId, getConfig, getCorrelationContext, getHttpStatusTitle, getJwtExpiry, getRefreshCookieOptions, getTokenExpiry, hashToken, jwtConfigFactory, normalizePhoneNumber, parseExpiryToMs, resetConfig, runWithCorrelationContext, updateCorrelationContext, verifyTokenHash };
776
+ declare const DATA_TABLE_VIEWS_TABLE: unique symbol;
777
+
778
+ interface DataTableModuleOptions {
779
+ tableViews: PgTable;
780
+ }
781
+ declare class DataTableModule {
782
+ static forRoot(options: DataTableModuleOptions): DynamicModule;
783
+ }
784
+
785
+ declare function dataTableViewsColumns(): {
786
+ id: drizzle_orm.HasDefault<drizzle_orm.IsPrimaryKey<drizzle_orm_pg_core.PgUUIDBuilder>>;
787
+ userId: drizzle_orm.NotNull<drizzle_orm_pg_core.PgUUIDBuilder>;
788
+ tableSlug: drizzle_orm.NotNull<drizzle_orm_pg_core.PgVarcharBuilder<[string, ...string[]]>>;
789
+ name: drizzle_orm.NotNull<drizzle_orm_pg_core.PgVarcharBuilder<[string, ...string[]]>>;
790
+ state: drizzle_orm.$Type<drizzle_orm.NotNull<drizzle_orm_pg_core.PgJsonbBuilder>, TableViewState>;
791
+ isShared: drizzle_orm.HasDefault<drizzle_orm.NotNull<drizzle_orm_pg_core.PgBooleanBuilder>>;
792
+ createdAt: drizzle_orm.HasDefault<drizzle_orm.NotNull<drizzle_orm_pg_core.PgTimestampBuilder>>;
793
+ updatedAt: drizzle_orm.HasDefault<drizzle_orm_pg_core.PgTimestampBuilder>;
794
+ };
795
+ declare function dataTableViewsIndexes(table: any): drizzle_orm_pg_core.IndexBuilder[];
796
+ interface DataTableViewRecord {
797
+ id: string;
798
+ userId: string;
799
+ tableSlug: string;
800
+ name: string;
801
+ state: TableViewState;
802
+ isShared: boolean;
803
+ createdAt: Date;
804
+ updatedAt: Date | null | undefined;
805
+ }
806
+ interface NewDataTableViewRecord {
807
+ userId: string;
808
+ tableSlug: string;
809
+ name: string;
810
+ state: TableViewState;
811
+ isShared?: boolean;
812
+ }
813
+
814
+ declare class DataTableViewDto {
815
+ id: string;
816
+ name: string | null;
817
+ tableSlug: string;
818
+ state: TableViewState;
819
+ isShared: boolean;
820
+ isOwn: boolean;
821
+ createdAt: Date;
822
+ updatedAt: Date | null;
823
+ static from(view: DataTableViewRecord, userId: string): DataTableViewDto;
824
+ }
825
+
826
+ declare class CreateDataTableViewDto {
827
+ name: string;
828
+ tableSlug: string;
829
+ state: TableViewState;
830
+ isShared?: boolean;
831
+ }
832
+
833
+ declare class UpdateDataTableViewDto {
834
+ state: TableViewState;
835
+ }
836
+
837
+ declare class DataTableViewsRepository extends PrimaryBaseRepository<PgTable, NewDataTableViewRecord, DataTableViewRecord> {
838
+ constructor(database: PrimaryDatabaseService, table: PgTable);
839
+ findPersonalViewsBySlug(userId: string, tableSlug: string): Promise<DataTableViewRecord[]>;
840
+ findSharedViewsBySlug(tableSlug: string): Promise<DataTableViewRecord[]>;
841
+ }
842
+
843
+ declare class DataTableViewsService {
844
+ private readonly dataTableViewsRepository;
845
+ private readonly cacheService;
846
+ private readonly configService;
847
+ private readonly logger;
848
+ constructor(dataTableViewsRepository: DataTableViewsRepository, cacheService: CacheService, configService: ConfigService);
849
+ private personalViewsKey;
850
+ private sharedViewsKey;
851
+ private get viewsTtl();
852
+ private getOrCachePersonalViews;
853
+ private getOrCacheSharedViews;
854
+ private invalidateViewsCache;
855
+ findViews(userId: string, tableSlug: string): Promise<DataTableViewDto[]>;
856
+ createView(userId: string, dto: CreateDataTableViewDto): Promise<DataTableViewDto>;
857
+ updateView(userId: string, id: string, dto: UpdateDataTableViewDto): Promise<DataTableViewDto>;
858
+ toggleShareView(userId: string, id: string, isShared: boolean): Promise<DataTableViewDto>;
859
+ renameView(userId: string, id: string, name: string): Promise<DataTableViewDto>;
860
+ deleteView(userId: string, id: string): Promise<DataTableViewDto>;
861
+ }
862
+
863
+ declare class UpsertDataTableStateDto {
864
+ tableSlug: string;
865
+ state: TableViewState;
866
+ activeViewId?: string | null;
867
+ }
868
+
869
+ declare class DataTableStateService {
870
+ private readonly cacheService;
871
+ private readonly configService;
872
+ private readonly logger;
873
+ constructor(cacheService: CacheService, configService: ConfigService);
874
+ private get stateTtl();
875
+ upsertCurrentState(userId: string, dto: UpsertDataTableStateDto): Promise<void>;
876
+ getCurrentState(userId: string, tableSlug: string): Promise<{
877
+ state: TableViewState;
878
+ activeViewId: string | null;
879
+ }>;
880
+ }
881
+
882
+ declare class RenameDataTableViewDto {
883
+ name: string;
884
+ }
885
+
886
+ declare class ToggleShareDataTableViewDto {
887
+ isShared: boolean;
888
+ }
889
+
890
+ export { AccessToken, type AccessTokenPayload, type ApiErrorResponse, type ApiSdkConfig, AuthConfigModule, BadGatewayException, BadRequestException, CACHE_PROVIDER, CacheModule, CacheService, type ColumnPinning, ConflictException, type CookieConfig, CookieDomain, type CookieSerializeOptions, type CorrelationContext, CorrelationIdMiddleware, CreateDataTableViewDto, DATA_TABLE_VIEWS_TABLE, DEFAULT_CORRELATION_HEADER, DataTableModule, type DataTableModuleOptions, DataTableStateService, DataTableViewDto, type DataTableViewRecord, DataTableViewsService, DatabaseModule, type DatabaseModuleOptions, type DensityType, EmailModule, EmailService, type FieldDefinition, type FieldError, type FieldMap, type FilterCondition, type FilterOperator, FilterProcessor, type FindForSelectConfig, type FindForSelectJoin, ForbiddenException, GoneException, type GuardConfig, HttpExceptionFilter, HttpLoggerInterceptor, type HttpLoggerOptions, HttpProblemException, type ICacheProvider, InternalServerErrorException, JwtAuthService, type JwtConfig, LOGGER_MODULE_OPTIONS, type LogFormat, type LogLevel, type LogMetadata, LoggerModule, type LoggerModuleAsyncOptions, type LoggerModuleOptions, type LoggerOptionsFactory, LoggerService, MethodNotAllowedException, type NewDataTableViewRecord, NotAcceptableException, NotFoundException, NotImplementedException, Onboarding, PayloadTooLargeException, PrimaryBaseRepository, PrimaryDatabaseService, type PrimaryDbConfig, type ProblemDetails, type ProblemOptions, Public, RESET_KEY, RedisCacheProvider, RefreshCookieOptions, RefreshTokenCookie, type RefreshTokenPayload, type RegisteredSchema, RenameDataTableViewDto, RequestTimeoutException, Reset, RootModule, SKIP_CSRF_KEY, SelectOptionsQueryDto, type SelectQueryGroup, type SelectQueryOption, type SelectQueryResult, ServiceUnavailableException, SessionData, type SessionInfo, SkipCsrf, type SortCondition, SuccessResponseDto, TableResponseDto, type TableViewState, Tenant, TenantBaseRepository, TenantContextService, TenantDatabaseService, type TenantInfo, ToggleShareDataTableViewDto, type TokenExpiry, TokenType, TooManyRequestsException, type TypedDrizzleClient, UnauthorizedException, UnprocessableEntityException, UnsupportedMediaTypeException, UpdateDataTableViewDto, UpsertDataTableStateDto, UserId, ValidationException, VrittiAuthGuard, addCorrelationIdToResponse, configureApiSdk, correlationStorage, dataTableViewsColumns, dataTableViewsIndexes, defineConfig, extractCountryFromPhone, generateCorrelationId, getConfig, getCorrelationContext, getHttpStatusTitle, getJwtExpiry, getRefreshCookieOptions, getRefreshCookieOptionsForHost, getTokenExpiry, hashToken, jwtConfigFactory, normalizePhoneNumber, parseExpiryToMs, resetConfig, runWithCorrelationContext, updateCorrelationContext, verifyTokenHash };