@stackone/olap 1.15.0 → 1.17.0

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.mts CHANGED
@@ -1,6 +1,12 @@
1
- import { t as __name } from "./chunk-Cfxk5zVN.mjs";
1
+ import { r as __name } from "./chunk-Co8tzA6w.mjs";
2
+ import { z } from "@stackone/utils";
2
3
  import { S3Client } from "@aws-sdk/client-s3";
4
+ import https from "node:https";
3
5
  import { Kafka } from "kafkajs";
6
+ import http from "node:http";
7
+ import * as redis from "redis";
8
+ import { AxiosInstance } from "axios";
9
+ import { Readable } from "node:stream";
4
10
 
5
11
  //#region ../logger/src/types.d.ts
6
12
  interface ILogger {
@@ -84,10 +90,487 @@ type DefenderOptions = {
84
90
  enabled?: boolean;
85
91
  };
86
92
  //#endregion
93
+ //#region ../transport/src/cacheClient/types.d.ts
94
+ interface ICacheClient<ClientType = unknown> {
95
+ getData<T>(key: string): Promise<T | null>;
96
+ listData<T>({
97
+ partialKey,
98
+ limit,
99
+ cursor
100
+ }: {
101
+ partialKey: string;
102
+ limit?: number;
103
+ cursor?: string;
104
+ }): Promise<{
105
+ items: T[] | null;
106
+ cursor?: string;
107
+ }>;
108
+ setData<T>({
109
+ key,
110
+ value,
111
+ cacheTTL,
112
+ groupKey
113
+ }: {
114
+ key: string;
115
+ value: T;
116
+ cacheTTL: number;
117
+ groupKey?: string;
118
+ }): Promise<boolean>;
119
+ executeScript?<T>({
120
+ sha1,
121
+ keys,
122
+ args
123
+ }: {
124
+ sha1: string;
125
+ keys: string[];
126
+ args: string[];
127
+ }): Promise<T | null>;
128
+ loadScript?(script: string): Promise<string | null>;
129
+ scriptExists?(shas: string[]): Promise<boolean[]>;
130
+ increment?(key: string, cacheTTL: number): Promise<number | null>;
131
+ decrement?(key: string, cacheTTL: number): Promise<number | null>;
132
+ subscribe?<T extends boolean = false>(pattern: string, listener: PubSubListener<T>): Promise<boolean>;
133
+ unsubscribe?(pattern: string): Promise<boolean>;
134
+ publish?(channel: string, message: string): Promise<number | null>;
135
+ getClient?(): ClientType | null;
136
+ deleteData?(key: string): Promise<boolean>;
137
+ close?(): Promise<void> | void;
138
+ }
139
+ type PubSubListener<ReturnsBuffer extends boolean = false> = <T extends (ReturnsBuffer extends true ? Buffer : string)>(message: T, channel: T) => unknown;
140
+ //#endregion
141
+ //#region ../transport/src/redisClient/types.d.ts
142
+ type RedisClientType = redis.RedisClientType;
143
+ interface RedisClientConfig {
144
+ getRedisClient?: typeof redis.createClient;
145
+ host?: string;
146
+ port?: number;
147
+ tls?: boolean;
148
+ reconnect?: boolean;
149
+ database?: number;
150
+ }
151
+ type RedisClientBuilder = (config: RedisClientConfig, logger?: ILogger, invoker?: string) => Promise<ICacheClient<RedisClientType> | undefined>;
152
+ //#endregion
153
+ //#region ../transport/src/concurrencyManager/types.d.ts
154
+ type ConcurrencySubPoolConfig = {
155
+ subPoolKey: string;
156
+ urlPattern: RegExp | string;
157
+ maxConcurrency: number;
158
+ };
159
+ type ConcurrencyConfig = {
160
+ mainMaxConcurrency: number;
161
+ subPools?: ConcurrencySubPoolConfig[];
162
+ };
163
+ //#endregion
164
+ //#region ../transport/src/rateLimitManager/types.d.ts
165
+ type RateLimitSubPoolConfig = {
166
+ subPoolKey: string;
167
+ urlPattern: RegExp | string;
168
+ rateLimit: number;
169
+ };
170
+ type RetryUnit = 'seconds' | 'milliseconds' | 'date';
171
+ type MappedRateLimitErrorConfig = {
172
+ errorStatus: number;
173
+ errorMessage: string | RegExp;
174
+ errorMessagePath?: string;
175
+ retryAfterPath?: string;
176
+ retryAfterUnit?: RetryUnit;
177
+ retryAfterValue?: number;
178
+ };
179
+ type RateLimitConfig = {
180
+ mainRatelimit: number;
181
+ subPools?: RateLimitSubPoolConfig[];
182
+ mappedRateLimitErrors?: MappedRateLimitErrorConfig[];
183
+ };
184
+ //#endregion
185
+ //#region ../transport/src/interceptors/types.d.ts
186
+ type RequestConfig = {
187
+ rateLimits?: RateLimitConfig;
188
+ concurrency?: ConcurrencyConfig;
189
+ };
190
+ //#endregion
191
+ //#region ../transport/src/parsers/types.d.ts
192
+ declare const QueryArrayFormats: readonly ["repeat", "brackets", "comma"];
193
+ type QueryArrayFormat = (typeof QueryArrayFormats)[number];
194
+ //#endregion
195
+ //#region ../transport/src/httpClient/types.d.ts
196
+ type HttpHeader = string | string[];
197
+ type HttpHeaders = {
198
+ [key: string]: HttpHeader;
199
+ };
200
+ type HttpQueryParamValue = {
201
+ value: string | string[];
202
+ arrayFormat?: QueryArrayFormat;
203
+ };
204
+ type HttpQueryParams = {
205
+ [key: string]: string | string[] | HttpQueryParamValue;
206
+ };
207
+ declare const HttpMethods: readonly ["get", "post", "put", "delete", "patch"];
208
+ type HttpMethod = (typeof HttpMethods)[number];
209
+ type HttpResponse<T = any, P = any> = {
210
+ data: T;
211
+ status: number;
212
+ headers: HttpHeaders;
213
+ requestUrl: string;
214
+ responseType?: string;
215
+ responseTime?: Date;
216
+ message?: string;
217
+ body?: P;
218
+ };
219
+ type StreamHttpResponse = {
220
+ status: number;
221
+ headers: HttpHeaders;
222
+ stream: Readable;
223
+ requestUrl: string;
224
+ };
225
+ interface IHttpClient {
226
+ request<P, T>({
227
+ headers,
228
+ url,
229
+ method,
230
+ queryParams,
231
+ maxRedirects,
232
+ responseType,
233
+ cacheTTL,
234
+ context,
235
+ payload,
236
+ httpsAgent,
237
+ httpAgent,
238
+ requestConfig,
239
+ httpsAgentConfig
240
+ }: {
241
+ headers?: HttpHeaders;
242
+ url: string;
243
+ method?: HttpMethod;
244
+ queryParams?: HttpQueryParams;
245
+ maxRedirects?: number;
246
+ responseType?: 'arraybuffer' | 'blob' | 'document' | 'json' | 'text';
247
+ cacheTTL?: number;
248
+ context?: RequestContext;
249
+ payload?: P;
250
+ httpsAgent?: https.Agent;
251
+ httpAgent?: http.Agent;
252
+ requestConfig?: RequestConfig;
253
+ httpsAgentConfig?: https.AgentOptions;
254
+ }): Promise<HttpResponse<T>>;
255
+ get<T>({
256
+ headers,
257
+ url,
258
+ queryParams,
259
+ maxRedirects,
260
+ cacheTTL,
261
+ context,
262
+ requestConfig
263
+ }: {
264
+ headers?: HttpHeaders;
265
+ url: string;
266
+ queryParams?: HttpQueryParams;
267
+ maxRedirects?: number;
268
+ cacheTTL?: number;
269
+ context?: RequestContext;
270
+ requestConfig?: RequestConfig;
271
+ }): Promise<HttpResponse<T>>;
272
+ post<P, T>({
273
+ headers,
274
+ url,
275
+ maxRedirects,
276
+ cacheTTL,
277
+ context,
278
+ payload,
279
+ requestConfig
280
+ }: {
281
+ headers?: HttpHeaders;
282
+ url: string;
283
+ maxRedirects?: number;
284
+ cacheTTL?: number;
285
+ context?: RequestContext;
286
+ payload?: P;
287
+ requestConfig?: RequestConfig;
288
+ }): Promise<HttpResponse<T>>;
289
+ requestStream({
290
+ headers,
291
+ url,
292
+ method,
293
+ queryParams,
294
+ maxRedirects,
295
+ context,
296
+ traceId,
297
+ payload,
298
+ httpsAgent,
299
+ httpAgent,
300
+ requestConfig,
301
+ httpsAgentConfig
302
+ }: {
303
+ headers?: HttpHeaders;
304
+ url: string;
305
+ method?: HttpMethod;
306
+ queryParams?: HttpQueryParams;
307
+ maxRedirects?: number;
308
+ context?: RequestContext;
309
+ traceId?: string;
310
+ payload?: unknown;
311
+ httpsAgent?: https.Agent;
312
+ httpAgent?: http.Agent;
313
+ requestConfig?: RequestConfig;
314
+ httpsAgentConfig?: https.AgentOptions;
315
+ }): Promise<StreamHttpResponse>;
316
+ }
317
+ interface OperationSetting {
318
+ url?: string;
319
+ query?: Record<string, string>;
320
+ config?: Partial<APIConfig>;
321
+ custom_settings?: Record<string, unknown>;
322
+ }
323
+ type OperationSettings = Record<string, OperationSetting>;
324
+ type AccountSettings = Record<string, string | number | boolean | object>;
325
+ type HttpClientBehaviour = 'CONCURRENCY' | 'RETRY';
326
+ type APIConfig = Record<string, unknown>;
327
+ type RequestContext = {
328
+ accountSecureId?: string;
329
+ projectSecureId?: string;
330
+ organizationId?: number | string;
331
+ environment?: string;
332
+ authConfigKey?: string;
333
+ provider?: string;
334
+ service?: string;
335
+ resource?: string;
336
+ subResource?: string;
337
+ childResource?: string;
338
+ operation?: string;
339
+ action?: string;
340
+ mode?: string;
341
+ testerUniqueToken?: string;
342
+ externalKey?: string;
343
+ dataKey?: string;
344
+ isDataSync?: boolean;
345
+ operationSettings?: OperationSettings;
346
+ accountSettings?: AccountSettings;
347
+ behaviours?: HttpClientBehaviour[];
348
+ };
349
+ type ErrorMappingFn<TError extends Error = Error> = (error: Error) => TError | undefined;
350
+ type TransportFactory = ({
351
+ logger,
352
+ redisClientConfig,
353
+ context,
354
+ requestConfig,
355
+ httpsAgentConfig
356
+ }: {
357
+ logger?: ILogger;
358
+ redisClientConfig?: RedisClientConfig;
359
+ context?: RequestContext;
360
+ requestConfig?: RequestConfig;
361
+ httpsAgentConfig?: https.AgentOptions;
362
+ }) => Promise<AxiosInstance>;
363
+ //#endregion
364
+ //#region ../transport/src/httpClient/httpClient.d.ts
365
+ declare class HttpClient<TError extends Error = Error> implements IHttpClient {
366
+ #private;
367
+ name: string;
368
+ constructor({
369
+ transportFactory,
370
+ getRedisClient,
371
+ logger,
372
+ redisClientConfig,
373
+ errorMappingFn
374
+ }?: {
375
+ transportFactory?: TransportFactory;
376
+ getRedisClient?: RedisClientBuilder;
377
+ logger?: ILogger;
378
+ redisClientConfig?: RedisClientConfig;
379
+ errorMappingFn?: ErrorMappingFn<TError>;
380
+ });
381
+ request<P, T>({
382
+ headers,
383
+ url,
384
+ method,
385
+ queryParams,
386
+ maxRedirects,
387
+ responseType,
388
+ cacheTTL,
389
+ context,
390
+ traceId,
391
+ payload,
392
+ httpsAgent,
393
+ httpAgent,
394
+ requestConfig,
395
+ httpsAgentConfig
396
+ }: {
397
+ headers?: HttpHeaders;
398
+ url: string;
399
+ method?: HttpMethod;
400
+ queryParams?: HttpQueryParams;
401
+ maxRedirects?: number;
402
+ responseType?: 'arraybuffer' | 'blob' | 'document' | 'json' | 'text';
403
+ cacheTTL?: number;
404
+ context?: RequestContext;
405
+ traceId?: string;
406
+ payload?: P;
407
+ httpsAgent?: https.Agent;
408
+ httpAgent?: http.Agent;
409
+ requestConfig?: RequestConfig;
410
+ httpsAgentConfig?: https.AgentOptions;
411
+ }): Promise<HttpResponse<T>>;
412
+ get<T>({
413
+ headers,
414
+ url,
415
+ queryParams,
416
+ maxRedirects,
417
+ cacheTTL,
418
+ context,
419
+ traceId,
420
+ requestConfig
421
+ }: {
422
+ headers?: HttpHeaders;
423
+ url: string;
424
+ queryParams?: HttpQueryParams;
425
+ maxRedirects?: number;
426
+ cacheTTL?: number;
427
+ context?: RequestContext;
428
+ traceId?: string;
429
+ requestConfig?: RequestConfig;
430
+ }): Promise<HttpResponse<T>>;
431
+ post<P, T>({
432
+ headers,
433
+ url,
434
+ maxRedirects,
435
+ cacheTTL,
436
+ context,
437
+ traceId,
438
+ payload,
439
+ requestConfig
440
+ }: {
441
+ headers?: HttpHeaders;
442
+ url: string;
443
+ maxRedirects?: number;
444
+ cacheTTL?: number;
445
+ context?: RequestContext;
446
+ traceId?: string;
447
+ payload?: P;
448
+ requestConfig?: RequestConfig;
449
+ }): Promise<HttpResponse<T>>;
450
+ requestStream({
451
+ headers,
452
+ url,
453
+ method,
454
+ queryParams,
455
+ maxRedirects,
456
+ context,
457
+ traceId,
458
+ payload,
459
+ httpsAgent,
460
+ httpAgent,
461
+ requestConfig,
462
+ httpsAgentConfig
463
+ }: {
464
+ headers?: HttpHeaders;
465
+ url: string;
466
+ method?: HttpMethod;
467
+ queryParams?: HttpQueryParams;
468
+ maxRedirects?: number;
469
+ context?: RequestContext;
470
+ traceId?: string;
471
+ payload?: unknown;
472
+ httpsAgent?: https.Agent;
473
+ httpAgent?: http.Agent;
474
+ requestConfig?: RequestConfig;
475
+ httpsAgentConfig?: https.AgentOptions;
476
+ }): Promise<StreamHttpResponse>;
477
+ }
478
+ //#endregion
479
+ //#region src/logs/types.d.ts
480
+ type ActionsQuery = {
481
+ organizationId?: string | string[];
482
+ projectSecureId?: string | string[];
483
+ actionRunId?: string | string[];
484
+ accountSecureId?: string | string[];
485
+ actionId?: string | string[];
486
+ connectorKey?: string | string[];
487
+ mode?: string | string[];
488
+ category?: string | string[];
489
+ success?: boolean;
490
+ startTime?: Date;
491
+ endTime?: Date;
492
+ pageNumber?: number;
493
+ pageSize?: number;
494
+ };
495
+ type ActionsQueryResult = {
496
+ actionLogs: ActionLog[];
497
+ total: number;
498
+ pageNumber: number;
499
+ pageSize: number;
500
+ };
501
+ type StepsQuery = {
502
+ organizationId?: string | string[];
503
+ projectSecureId?: string | string[];
504
+ accountSecureId?: string | string[];
505
+ actionRunId?: string | string[];
506
+ stepId?: string | string[];
507
+ success?: boolean;
508
+ startTime?: Date;
509
+ endTime?: Date;
510
+ pageNumber?: number;
511
+ pageSize?: number;
512
+ };
513
+ type StepsQueryResult = {
514
+ stepLogs: StepLog[];
515
+ total: number;
516
+ pageNumber: number;
517
+ pageSize: number;
518
+ };
519
+ type HttpClientBuilder = (logger?: ILogger) => HttpClient | undefined;
520
+ interface KafkaClientConfig {
521
+ brokers: string[];
522
+ }
523
+ type KafkaClientBuilder = (config?: KafkaClientConfig, logger?: ILogger) => Kafka | undefined;
524
+ type ActionLog = {
525
+ actionRunId: string;
526
+ actionId: string;
527
+ connectorKey: string;
528
+ connectorVersion: string;
529
+ organizationId: string;
530
+ projectSecureId: string;
531
+ accountSecureId: string;
532
+ mode?: string;
533
+ category?: string;
534
+ originOwnerId?: string;
535
+ originOwnerName?: string;
536
+ httpMethod?: string;
537
+ url?: string;
538
+ sourceType?: string;
539
+ sourceId?: string;
540
+ sourceValue?: string;
541
+ success?: boolean;
542
+ statusCode?: number;
543
+ startTime?: Date;
544
+ endTime?: Date;
545
+ durationMs?: number;
546
+ eventTime?: Date;
547
+ riskLevel?: string;
548
+ tier2Score?: number;
549
+ };
550
+ type StepLog = {
551
+ actionRunId: string;
552
+ stepIndex: number;
553
+ stepId: string;
554
+ organizationId: string;
555
+ projectSecureId: string;
556
+ accountSecureId: string;
557
+ skipped?: boolean;
558
+ success?: boolean;
559
+ message?: string;
560
+ startTime?: Date;
561
+ endTime?: Date;
562
+ durationMs?: number;
563
+ eventTime?: Date;
564
+ };
565
+ //#endregion
87
566
  //#region src/types.d.ts
88
567
  interface IOlapClient {
89
568
  recordAction(actionInput: ActionInput, actionResult: ActionResult, options?: OlapOptions): void;
90
569
  recordStep(stepInput: StepInput, stepResult: StepResult, options?: OlapOptions): void;
570
+ getActions(organizationId: string, projectSecureId: string, query: ActionsQuery): Promise<ActionsQueryResult>;
571
+ getAction(organizationId: string, projectSecureId: string, actionRunId: string): Promise<ActionLog | undefined>;
572
+ getAdvanced(organizationId: string, projectSecureId: string, actionRunId: string): Promise<string | undefined>;
573
+ getDefender(organizationId: string, projectSecureId: string, actionRunId: string): Promise<string | undefined>;
91
574
  }
92
575
  type DefenderContext = {
93
576
  riskLevel: string;
@@ -160,11 +643,30 @@ interface S3ClientConfig {
160
643
  }
161
644
  type S3ClientBuilder = (config?: S3ClientConfig, logger?: ILogger) => S3Client | undefined;
162
645
  //#endregion
163
- //#region src/logs/types.d.ts
164
- interface KafkaClientConfig {
165
- brokers: string[];
646
+ //#region src/logs/tinybirdClient.d.ts
647
+ interface TinybirdConfig {
648
+ baseUrl: string;
649
+ token: string;
650
+ allowHttp?: boolean;
651
+ }
652
+ interface TinybirdResponse<T> {
653
+ meta: Array<{
654
+ name: string;
655
+ type: string;
656
+ }>;
657
+ data: T;
658
+ rows: number;
659
+ rows_before_limit_at_least?: number;
660
+ statistics?: {
661
+ elapsed: number;
662
+ rows_read: number;
663
+ bytes_read: number;
664
+ };
665
+ }
666
+ interface TinybirdQueryOptions<TParams = Record<string, unknown>> {
667
+ endpoint: string;
668
+ params?: TParams;
166
669
  }
167
- type KafkaClientBuilder = (config?: KafkaClientConfig, logger?: ILogger) => Kafka | undefined;
168
670
  //#endregion
169
671
  //#region src/olap/olapClient.d.ts
170
672
  declare class OlapClient implements IOlapClient {
@@ -172,54 +674,70 @@ declare class OlapClient implements IOlapClient {
172
674
  name: string;
173
675
  constructor({
174
676
  getKafkaClient,
677
+ getHttpClient,
175
678
  getS3Client,
176
679
  kafkaClientConfig,
177
680
  s3ClientConfig,
681
+ tinybirdConfig,
178
682
  logger
179
683
  }?: {
180
684
  getKafkaClient?: KafkaClientBuilder;
685
+ getHttpClient?: HttpClientBuilder;
181
686
  getS3Client?: S3ClientBuilder;
182
687
  kafkaClientConfig?: KafkaClientConfig;
183
688
  s3ClientConfig?: S3ClientConfig;
689
+ tinybirdConfig?: TinybirdConfig;
184
690
  logger?: ILogger;
185
691
  });
186
692
  initialize(): Promise<void>;
187
693
  recordAction(actionInput: ActionInput, actionResult: ActionResult, options?: OlapOptions): Promise<void>;
188
694
  recordStep(stepInput: StepInput, stepResult: StepResult, options?: OlapOptions): Promise<void>;
695
+ getActions(organizationId: string, projectSecureId: string, query: ActionsQuery): Promise<ActionsQueryResult>;
696
+ getAction(organizationId: string, projectSecureId: string, actionRunId: string): Promise<ActionLog | undefined>;
697
+ getAdvanced(organizationId: string, projectSecureId: string, actionRunId: string): Promise<string | undefined>;
698
+ getDefender(organizationId: string, projectSecureId: string, actionRunId: string): Promise<string | undefined>;
189
699
  }
190
700
  //#endregion
191
701
  //#region src/olap/olapClientManager.d.ts
192
702
  declare const buildOlapClientInstance: ({
193
703
  getKafkaClient,
704
+ getHttpClient,
194
705
  getS3Client,
195
706
  kafkaClientConfig,
196
707
  s3ClientConfig,
708
+ tinybirdConfig,
197
709
  logger
198
710
  }?: {
199
711
  getKafkaClient?: KafkaClientBuilder;
712
+ getHttpClient?: HttpClientBuilder;
200
713
  getS3Client?: S3ClientBuilder;
201
714
  kafkaClientConfig?: KafkaClientConfig;
202
715
  s3ClientConfig?: S3ClientConfig;
716
+ tinybirdConfig?: TinybirdConfig;
203
717
  logger?: ILogger;
204
718
  }) => Promise<IOlapClient>;
205
719
  declare class OlapClientManager {
206
720
  private static olapClientPromise;
207
721
  static getInstance({
208
722
  getKafkaClient,
723
+ getHttpClient,
209
724
  getS3Client,
210
725
  kafkaClientConfig,
211
726
  s3ClientConfig,
727
+ tinybirdConfig,
212
728
  logger,
213
729
  getOlapClient
214
730
  }?: {
215
731
  getKafkaClient?: KafkaClientBuilder;
732
+ getHttpClient?: HttpClientBuilder;
216
733
  getS3Client?: S3ClientBuilder;
217
734
  kafkaClientConfig?: KafkaClientConfig;
218
735
  s3ClientConfig?: S3ClientConfig;
736
+ tinybirdConfig?: TinybirdConfig;
219
737
  logger?: ILogger;
220
738
  getOlapClient?: typeof buildOlapClientInstance;
221
739
  }): Promise<IOlapClient>;
222
740
  static resetInstance(): void;
223
741
  }
224
742
  //#endregion
225
- export { type ActionInput, type ActionResult, type AdvancedOptions, type DefenderContext, type DefenderOptions, type IOlapClient, type LogsOptions, OlapClient, OlapClientManager, type OlapOptions, type StepInput, type StepResult };
743
+ export { type ActionInput, type ActionLog, type ActionResult, type ActionsQuery, type ActionsQueryResult, type AdvancedOptions, type DefenderContext, type DefenderOptions, type IOlapClient, type LogsOptions, OlapClient, OlapClientManager, type OlapOptions, type StepInput, type StepLog, type StepResult, type StepsQuery, type StepsQueryResult, type TinybirdConfig, type TinybirdQueryOptions, type TinybirdResponse };