@boltic/sdk 0.1.3 → 0.1.5

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.
@@ -1,3 +1,25 @@
1
+ import { CreateFolderData } from '../../../storage/src/types/storage';
2
+ import { CreateFolderParams } from '../../../storage/src/types/storage';
3
+ import { CreateServerlessParams } from '../../../serverless/src/types/serverless';
4
+ import { DeleteFileParams } from '../../../storage/src/types/storage';
5
+ import { DownloadFileData } from '../../../storage/src/types/storage';
6
+ import { DownloadFileParams } from '../../../storage/src/types/storage';
7
+ import { GetBuildLogsData } from '../../../serverless/src/types/serverless';
8
+ import { GetBuildLogsParams } from '../../../serverless/src/types/serverless';
9
+ import { GetBuildsData } from '../../../serverless/src/types/serverless';
10
+ import { GetBuildsParams } from '../../../serverless/src/types/serverless';
11
+ import { GetLogsData } from '../../../serverless/src/types/serverless';
12
+ import { GetLogsParams } from '../../../serverless/src/types/serverless';
13
+ import { ListServerlessData } from '../../../serverless/src/types/serverless';
14
+ import { ListServerlessParams } from '../../../serverless/src/types/serverless';
15
+ import { ListStorageData } from '../../../storage/src/types/storage';
16
+ import { ListStorageParams } from '../../../storage/src/types/storage';
17
+ import { ObjectAccessSummary } from '../../../storage/src/types/storage';
18
+ import { ServerlessData } from '../../../serverless/src/types/serverless';
19
+ import { UpdateServerlessParams } from '../../../serverless/src/types/serverless';
20
+ import { UploadData } from '../../../storage/src/types/storage';
21
+ import { UploadParams } from '../../../storage/src/types/storage';
22
+
1
23
  /** Properties describing the activity to execute (dynamic, varies by integration) */
2
24
  declare type ActivityProperties = Record<string, unknown>;
3
25
 
@@ -163,6 +185,8 @@ export declare class BolticClient {
163
185
  private indexResource;
164
186
  private databaseResource;
165
187
  private workflowResource;
188
+ private serverlessResource;
189
+ private storageResource;
166
190
  private currentDatabase;
167
191
  private clientOptions;
168
192
  constructor(apiKey: string, options?: ClientOptions);
@@ -302,6 +326,59 @@ export declare class BolticClient {
302
326
  getIntegrationResource: (params: GetIntegrationResourceParams) => Promise<BolticErrorResponse | BolticSuccessResponse<IntegrationResourceData>>;
303
327
  getIntegrationForm: (params: GetIntegrationFormParams) => Promise<BolticErrorResponse | BolticSuccessResponse<Record<string, unknown> | IntegrationFormJsonSchema>>;
304
328
  };
329
+ /**
330
+ * Serverless function operations.
331
+ *
332
+ * @example
333
+ * ```typescript
334
+ * // List all serverless functions
335
+ * const list = await client.serverless.list();
336
+ *
337
+ * // Create a new serverless function
338
+ * const fn = await client.serverless.create({
339
+ * Name: 'my-api',
340
+ * Runtime: 'code',
341
+ * CodeOpts: { Language: 'nodejs/20', Code: '...' },
342
+ * Resources: { CPU: 0.1, MemoryMB: 128, MemoryMaxMB: 128 },
343
+ * Scaling: { AutoStop: false, Min: 1, Max: 1, MaxIdleTime: 0 },
344
+ * });
345
+ *
346
+ * // Get a serverless function by ID
347
+ * const details = await client.serverless.get('serverless-id');
348
+ *
349
+ * // Get builds
350
+ * const builds = await client.serverless.getBuilds({ appId: 'id' });
351
+ *
352
+ * // Get runtime logs
353
+ * const logs = await client.serverless.getLogs({ appId: 'id' });
354
+ * ```
355
+ */
356
+ get serverless(): {
357
+ list: (params?: ListServerlessParams) => Promise<BolticErrorResponse | BolticSuccessResponse<ListServerlessData>>;
358
+ get: (appId: string) => Promise<BolticErrorResponse | BolticSuccessResponse<ServerlessData>>;
359
+ create: (params: CreateServerlessParams) => Promise<BolticErrorResponse | BolticSuccessResponse<ServerlessData>>;
360
+ createAndWait: (params: CreateServerlessParams) => Promise<BolticErrorResponse | BolticSuccessResponse<ServerlessData>>;
361
+ update: (params: UpdateServerlessParams) => Promise<BolticErrorResponse | BolticSuccessResponse<ServerlessData>>;
362
+ updateAndWait: (params: UpdateServerlessParams) => Promise<BolticErrorResponse | BolticSuccessResponse<ServerlessData>>;
363
+ getBuilds: (params: GetBuildsParams) => Promise<BolticErrorResponse | BolticSuccessResponse<GetBuildsData>>;
364
+ getLogs: (params: GetLogsParams) => Promise<BolticErrorResponse | BolticSuccessResponse<GetLogsData>>;
365
+ getBuildLogs: (params: GetBuildLogsParams) => Promise<BolticErrorResponse | BolticSuccessResponse<GetBuildLogsData>>;
366
+ pollStatus: (appId: string, options?: {
367
+ intervalMs?: number;
368
+ maxAttempts?: number;
369
+ }) => Promise<BolticErrorResponse | BolticSuccessResponse<ServerlessData>>;
370
+ };
371
+ get storage(): {
372
+ list: (params?: ListStorageParams) => Promise<BolticErrorResponse | ListStorageData>;
373
+ upload: (params: UploadParams) => Promise<BolticErrorResponse | UploadData>;
374
+ createFolder: (params: CreateFolderParams) => Promise<BolticErrorResponse | CreateFolderData>;
375
+ deleteFile: (params: DeleteFileParams) => Promise<BolticErrorResponse | {
376
+ message: unknown;
377
+ }>;
378
+ makePublic: (filePath: string) => Promise<BolticErrorResponse | ObjectAccessSummary>;
379
+ makePrivate: (filePath: string) => Promise<BolticErrorResponse | ObjectAccessSummary>;
380
+ downloadFile: (params: DownloadFileParams) => Promise<BolticErrorResponse | DownloadFileData>;
381
+ };
305
382
  getSqlResource(): SqlResource;
306
383
  updateApiKey(newApiKey: string): void;
307
384
  updateConfig(updates: Partial<ClientConfig>): void;
@@ -1183,6 +1260,11 @@ export declare interface HttpRequestConfig {
1183
1260
  data?: unknown;
1184
1261
  timeout?: number;
1185
1262
  signal?: AbortSignal;
1263
+ /**
1264
+ * Opt-in only. When unset (default), JSON/text parsing is unchanged for all services.
1265
+ * Storage `downloadFile` sets `arraybuffer` for binary bodies.
1266
+ */
1267
+ responseType?: 'arraybuffer';
1186
1268
  }
1187
1269
 
1188
1270
  export declare interface HttpResponse<T = unknown> {
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./test-client-BgkvBtst.js");class i{constructor(e){this.queryOptions={},this.updateData={},this.tableName=e.tableName,this.columnResource=e.columnResource}where(e){return this.queryOptions.where={...this.queryOptions.where,...e},this}orderBy(e,i="asc"){return this.queryOptions.sort||(this.queryOptions.sort=[]),this.queryOptions.sort.push({field:e,order:i}),this}limit(e){return this.queryOptions.limit=e,this}offset(e){return this.queryOptions.offset=e,this}select(e){return this.queryOptions.fields=e,this}set(e){return this.updateData={...this.updateData,...e},this}async findAll(){return this.columnResource.findAll(this.tableName,this.queryOptions)}async get(){return this.queryOptions.where?.name?this.columnResource.get(this.tableName,this.queryOptions.where.name):{error:{code:"MISSING_COLUMN_NAME",message:"Column name is required for get operation"}}}async update(){return this.queryOptions.where?.name?this.columnResource.update(this.tableName,this.queryOptions.where.name,this.updateData):{error:{code:"MISSING_COLUMN_NAME",message:"Column name is required for update operation"}}}async delete(){return this.queryOptions.where?.name?this.columnResource.delete(this.tableName,this.queryOptions.where.name):{error:{code:"MISSING_COLUMN_NAME",message:"Column name is required for delete operation"}}}getQueryOptions(){return{...this.queryOptions}}getUpdateData(){return{...this.updateData}}}exports.ALLOWED_FIELD_TYPE_CONVERSIONS=e.ALLOWED_FIELD_TYPE_CONVERSIONS,exports.ApiError=e.ApiError,exports.BolticClient=e.BolticClient,exports.DateFormatEnum=e.DateFormatEnum,exports.ENV_CONFIGS=e.ENV_CONFIGS,exports.FIELD_SPECIFIC_KEYS_MAP=e.FIELD_SPECIFIC_KEYS_MAP,exports.FILTER_OPERATORS=e.FILTER_OPERATORS,exports.FieldTypeEnum=e.FieldTypeEnum,exports.FilterBuilder=e.FilterBuilder,exports.REGION_BASE_HOSTS=e.REGION_BASE_HOSTS,exports.REGION_CONFIGS=e.REGION_CONFIGS,exports.SqlResource=e.SqlResource,exports.TimeFormatEnum=e.TimeFormatEnum,exports.ValidationError=e.ValidationError,exports.buildApiFilters=e.buildApiFilters,exports.createErrorResponse=e.createErrorResponse,exports.createErrorWithContext=e.createErrorWithContext,exports.createFilter=e.createFilter,exports.createMockResponse=e.createMockResponse,exports.createRecordBuilder=e.createRecordBuilder,exports.createTableBuilder=e.createTableBuilder,exports.createTestClient=e.createTestClient,exports.formatError=e.formatError,exports.getHttpStatusCode=e.getHttpStatusCode,exports.isErrorResponse=e.isErrorResponse,exports.isListResponse=e.isListResponse,exports.isNetworkError=e.isNetworkError,exports.mapFiltersToWhere=e.mapFiltersToWhere,exports.mapWhereToFilters=e.mapWhereToFilters,exports.normalizeFilters=e.normalizeFilters,exports.resolveServiceURL=e.resolveServiceURL,exports.ColumnHelpers=class{static fieldToUpdateRequest(e){return{name:e.name,type:e.type,description:e.description,is_nullable:e.is_nullable,is_unique:e.is_unique,is_indexed:e.is_indexed,is_visible:e.is_visible,is_primary_key:e.is_primary_key,is_readonly:e.is_readonly,field_order:e.field_order,default_value:e.default_value,alignment:e.alignment,decimals:e.decimals,currency_format:e.currency_format,selectable_items:e.selectable_items,multiple_selections:e.multiple_selections,phone_format:e.phone_format,date_format:e.date_format,time_format:e.time_format,timezone:e.timezone,vector_dimension:e.vector_dimension,show_decrypted:e.show_decrypted,is_deterministic:e.is_deterministic}}static applyDefaultValues(e){if(!e.name||!e.type)throw new Error("Column name and type are required");return{name:e.name,type:e.type,is_nullable:!0,is_unique:!1,is_indexed:!1,is_primary_key:!1,is_visible:!0,is_readonly:!1,field_order:1,alignment:"left",multiple_selections:!1,...e}}static createColumnDefinition(e,i,r={}){return this.applyDefaultValues({name:e,type:i,...r})}static getColumnTypeDisplayName(e){return{text:"Text","long-text":"Long Text",number:"Number",currency:"Currency",checkbox:"Checkbox",dropdown:"Dropdown",email:"Email","phone-number":"Phone Number",link:"Link",json:"JSON","date-time":"Date & Time",vector:"Vector",halfvec:"Half Vector",sparsevec:"Sparse Vector",encrypted:"Encrypted"}[e]||e}},exports.SchemaHelpers=class{static textField(e,i={}){return{name:e,type:"text",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,...i}}static numberField(e,i={}){return{name:e,type:"number",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,decimals:"0.00",...i}}static currencyField(e,i="USD",r={}){return{name:e,type:"currency",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,decimals:"0.00",currency_format:i,...r}}static dropdownField(e,i,r={}){return{name:e,type:"dropdown",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,selection_source:"provide-static-list",selectable_items:i,multiple_selections:!1,...r}}static vectorField(e,i,r={}){return{name:e,type:"vector",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,vector_dimension:i,...r}}static jsonField(e,i={}){return{name:e,type:"json",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,...i}}static dateTimeField(e,i={}){return{name:e,type:"date-time",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,date_format:"YYYY-MM-DD",time_format:"HH:mm:ss",...i}}static emailField(e,i={}){return{name:e,type:"email",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,...i}}static longTextField(e,i={}){return{name:e,type:"long-text",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,...i}}static linkField(e,i={}){return{name:e,type:"link",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,...i}}static phoneNumberField(e,i="international",r={}){return{name:e,type:"phone-number",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,phone_format:i,...r}}static checkboxField(e,i={}){return{name:e,type:"checkbox",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,default_value:!1,...i}}static halfVectorField(e,i,r={}){return{name:e,type:"halfvec",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,vector_dimension:i,...r}}static sparseVectorField(e,i,r={}){return{name:e,type:"sparsevec",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,vector_dimension:i,...r}}static createBasicSchema(e){return e.map((e,i)=>({name:e.name,type:e.type,is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:i+1}))}},exports.VERSION="1.0.0",exports.createClient=function(i,r={}){return new e.BolticClient(i,r)},exports.createColumnBuilder=function(e){return new i(e)};
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./test-client-DzMli6cH.js");class i{constructor(e){this.queryOptions={},this.updateData={},this.tableName=e.tableName,this.columnResource=e.columnResource}where(e){return this.queryOptions.where={...this.queryOptions.where,...e},this}orderBy(e,i="asc"){return this.queryOptions.sort||(this.queryOptions.sort=[]),this.queryOptions.sort.push({field:e,order:i}),this}limit(e){return this.queryOptions.limit=e,this}offset(e){return this.queryOptions.offset=e,this}select(e){return this.queryOptions.fields=e,this}set(e){return this.updateData={...this.updateData,...e},this}async findAll(){return this.columnResource.findAll(this.tableName,this.queryOptions)}async get(){return this.queryOptions.where?.name?this.columnResource.get(this.tableName,this.queryOptions.where.name):{error:{code:"MISSING_COLUMN_NAME",message:"Column name is required for get operation"}}}async update(){return this.queryOptions.where?.name?this.columnResource.update(this.tableName,this.queryOptions.where.name,this.updateData):{error:{code:"MISSING_COLUMN_NAME",message:"Column name is required for update operation"}}}async delete(){return this.queryOptions.where?.name?this.columnResource.delete(this.tableName,this.queryOptions.where.name):{error:{code:"MISSING_COLUMN_NAME",message:"Column name is required for delete operation"}}}getQueryOptions(){return{...this.queryOptions}}getUpdateData(){return{...this.updateData}}}exports.ALLOWED_FIELD_TYPE_CONVERSIONS=e.ALLOWED_FIELD_TYPE_CONVERSIONS,exports.ApiError=e.ApiError,exports.BolticClient=e.BolticClient,exports.DateFormatEnum=e.DateFormatEnum,exports.ENV_CONFIGS=e.ENV_CONFIGS,exports.FIELD_SPECIFIC_KEYS_MAP=e.FIELD_SPECIFIC_KEYS_MAP,exports.FILTER_OPERATORS=e.FILTER_OPERATORS,exports.FieldTypeEnum=e.FieldTypeEnum,exports.FilterBuilder=e.FilterBuilder,exports.REGION_BASE_HOSTS=e.REGION_BASE_HOSTS,exports.REGION_CONFIGS=e.REGION_CONFIGS,exports.SqlResource=e.SqlResource,exports.TimeFormatEnum=e.TimeFormatEnum,exports.ValidationError=e.ValidationError,exports.buildApiFilters=e.buildApiFilters,exports.createErrorResponse=e.createErrorResponse,exports.createErrorWithContext=e.createErrorWithContext,exports.createFilter=e.createFilter,exports.createMockResponse=e.createMockResponse,exports.createRecordBuilder=e.createRecordBuilder,exports.createTableBuilder=e.createTableBuilder,exports.createTestClient=e.createTestClient,exports.formatError=e.formatError,exports.getHttpStatusCode=e.getHttpStatusCode,exports.isErrorResponse=e.isErrorResponse,exports.isListResponse=e.isListResponse,exports.isNetworkError=e.isNetworkError,exports.mapFiltersToWhere=e.mapFiltersToWhere,exports.mapWhereToFilters=e.mapWhereToFilters,exports.normalizeFilters=e.normalizeFilters,exports.resolveServiceURL=e.resolveServiceURL,exports.ColumnHelpers=class{static fieldToUpdateRequest(e){return{name:e.name,type:e.type,description:e.description,is_nullable:e.is_nullable,is_unique:e.is_unique,is_indexed:e.is_indexed,is_visible:e.is_visible,is_primary_key:e.is_primary_key,is_readonly:e.is_readonly,field_order:e.field_order,default_value:e.default_value,alignment:e.alignment,decimals:e.decimals,currency_format:e.currency_format,selectable_items:e.selectable_items,multiple_selections:e.multiple_selections,phone_format:e.phone_format,date_format:e.date_format,time_format:e.time_format,timezone:e.timezone,vector_dimension:e.vector_dimension,show_decrypted:e.show_decrypted,is_deterministic:e.is_deterministic}}static applyDefaultValues(e){if(!e.name||!e.type)throw new Error("Column name and type are required");return{name:e.name,type:e.type,is_nullable:!0,is_unique:!1,is_indexed:!1,is_primary_key:!1,is_visible:!0,is_readonly:!1,field_order:1,alignment:"left",multiple_selections:!1,...e}}static createColumnDefinition(e,i,r={}){return this.applyDefaultValues({name:e,type:i,...r})}static getColumnTypeDisplayName(e){return{text:"Text","long-text":"Long Text",number:"Number",currency:"Currency",checkbox:"Checkbox",dropdown:"Dropdown",email:"Email","phone-number":"Phone Number",link:"Link",json:"JSON","date-time":"Date & Time",vector:"Vector",halfvec:"Half Vector",sparsevec:"Sparse Vector",encrypted:"Encrypted"}[e]||e}},exports.SchemaHelpers=class{static textField(e,i={}){return{name:e,type:"text",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,...i}}static numberField(e,i={}){return{name:e,type:"number",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,decimals:"0.00",...i}}static currencyField(e,i="USD",r={}){return{name:e,type:"currency",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,decimals:"0.00",currency_format:i,...r}}static dropdownField(e,i,r={}){return{name:e,type:"dropdown",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,selection_source:"provide-static-list",selectable_items:i,multiple_selections:!1,...r}}static vectorField(e,i,r={}){return{name:e,type:"vector",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,vector_dimension:i,...r}}static jsonField(e,i={}){return{name:e,type:"json",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,...i}}static dateTimeField(e,i={}){return{name:e,type:"date-time",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,date_format:"YYYY-MM-DD",time_format:"HH:mm:ss",...i}}static emailField(e,i={}){return{name:e,type:"email",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,...i}}static longTextField(e,i={}){return{name:e,type:"long-text",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,...i}}static linkField(e,i={}){return{name:e,type:"link",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,...i}}static phoneNumberField(e,i="international",r={}){return{name:e,type:"phone-number",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,phone_format:i,...r}}static checkboxField(e,i={}){return{name:e,type:"checkbox",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,default_value:!1,...i}}static halfVectorField(e,i,r={}){return{name:e,type:"halfvec",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,vector_dimension:i,...r}}static sparseVectorField(e,i,r={}){return{name:e,type:"sparsevec",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,vector_dimension:i,...r}}static createBasicSchema(e){return e.map((e,i)=>({name:e.name,type:e.type,is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:i+1}))}},exports.VERSION="1.0.0",exports.createClient=function(i,r={}){return new e.BolticClient(i,r)},exports.createColumnBuilder=function(e){return new i(e)};
2
2
  //# sourceMappingURL=index.js.map
@@ -1,2 +1,2 @@
1
- import{B as e}from"./test-client-BEAX5vfC.mjs";import{u as i,A as r,D as s,E as t,v as a,F as n,t as l,b as o,r as _,R as u,S as d,T as m,V as c,c as p,o as y,h,d as b,p as f,f as q,g as v,q as x,j as O,k as E,i as F,a as k,l as N,m as S,e as w,n as R,s as C}from"./test-client-BEAX5vfC.mjs";function D(i,r={}){return new e(i,r)}class g{static fieldToUpdateRequest(e){return{name:e.name,type:e.type,description:e.description,is_nullable:e.is_nullable,is_unique:e.is_unique,is_indexed:e.is_indexed,is_visible:e.is_visible,is_primary_key:e.is_primary_key,is_readonly:e.is_readonly,field_order:e.field_order,default_value:e.default_value,alignment:e.alignment,decimals:e.decimals,currency_format:e.currency_format,selectable_items:e.selectable_items,multiple_selections:e.multiple_selections,phone_format:e.phone_format,date_format:e.date_format,time_format:e.time_format,timezone:e.timezone,vector_dimension:e.vector_dimension,show_decrypted:e.show_decrypted,is_deterministic:e.is_deterministic}}static applyDefaultValues(e){if(!e.name||!e.type)throw new Error("Column name and type are required");return{name:e.name,type:e.type,is_nullable:!0,is_unique:!1,is_indexed:!1,is_primary_key:!1,is_visible:!0,is_readonly:!1,field_order:1,alignment:"left",multiple_selections:!1,...e}}static createColumnDefinition(e,i,r={}){return this.applyDefaultValues({name:e,type:i,...r})}static getColumnTypeDisplayName(e){return{text:"Text","long-text":"Long Text",number:"Number",currency:"Currency",checkbox:"Checkbox",dropdown:"Dropdown",email:"Email","phone-number":"Phone Number",link:"Link",json:"JSON","date-time":"Date & Time",vector:"Vector",halfvec:"Half Vector",sparsevec:"Sparse Vector",encrypted:"Encrypted"}[e]||e}}class T{static textField(e,i={}){return{name:e,type:"text",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,...i}}static numberField(e,i={}){return{name:e,type:"number",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,decimals:"0.00",...i}}static currencyField(e,i="USD",r={}){return{name:e,type:"currency",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,decimals:"0.00",currency_format:i,...r}}static dropdownField(e,i,r={}){return{name:e,type:"dropdown",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,selection_source:"provide-static-list",selectable_items:i,multiple_selections:!1,...r}}static vectorField(e,i,r={}){return{name:e,type:"vector",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,vector_dimension:i,...r}}static jsonField(e,i={}){return{name:e,type:"json",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,...i}}static dateTimeField(e,i={}){return{name:e,type:"date-time",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,date_format:"YYYY-MM-DD",time_format:"HH:mm:ss",...i}}static emailField(e,i={}){return{name:e,type:"email",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,...i}}static longTextField(e,i={}){return{name:e,type:"long-text",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,...i}}static linkField(e,i={}){return{name:e,type:"link",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,...i}}static phoneNumberField(e,i="international",r={}){return{name:e,type:"phone-number",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,phone_format:i,...r}}static checkboxField(e,i={}){return{name:e,type:"checkbox",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,default_value:!1,...i}}static halfVectorField(e,i,r={}){return{name:e,type:"halfvec",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,vector_dimension:i,...r}}static sparseVectorField(e,i,r={}){return{name:e,type:"sparsevec",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,vector_dimension:i,...r}}static createBasicSchema(e){return e.map((e,i)=>({name:e.name,type:e.type,is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:i+1}))}}class I{constructor(e){this.queryOptions={},this.updateData={},this.tableName=e.tableName,this.columnResource=e.columnResource}where(e){return this.queryOptions.where={...this.queryOptions.where,...e},this}orderBy(e,i="asc"){return this.queryOptions.sort||(this.queryOptions.sort=[]),this.queryOptions.sort.push({field:e,order:i}),this}limit(e){return this.queryOptions.limit=e,this}offset(e){return this.queryOptions.offset=e,this}select(e){return this.queryOptions.fields=e,this}set(e){return this.updateData={...this.updateData,...e},this}async findAll(){return this.columnResource.findAll(this.tableName,this.queryOptions)}async get(){return this.queryOptions.where?.name?this.columnResource.get(this.tableName,this.queryOptions.where.name):{error:{code:"MISSING_COLUMN_NAME",message:"Column name is required for get operation"}}}async update(){return this.queryOptions.where?.name?this.columnResource.update(this.tableName,this.queryOptions.where.name,this.updateData):{error:{code:"MISSING_COLUMN_NAME",message:"Column name is required for update operation"}}}async delete(){return this.queryOptions.where?.name?this.columnResource.delete(this.tableName,this.queryOptions.where.name):{error:{code:"MISSING_COLUMN_NAME",message:"Column name is required for delete operation"}}}getQueryOptions(){return{...this.queryOptions}}getUpdateData(){return{...this.updateData}}}function M(e){return new I(e)}const L="1.0.0";export{i as ALLOWED_FIELD_TYPE_CONVERSIONS,r as ApiError,e as BolticClient,g as ColumnHelpers,s as DateFormatEnum,t as ENV_CONFIGS,a as FIELD_SPECIFIC_KEYS_MAP,n as FILTER_OPERATORS,l as FieldTypeEnum,o as FilterBuilder,_ as REGION_BASE_HOSTS,u as REGION_CONFIGS,T as SchemaHelpers,d as SqlResource,m as TimeFormatEnum,L as VERSION,c as ValidationError,p as buildApiFilters,D as createClient,M as createColumnBuilder,y as createErrorResponse,h as createErrorWithContext,b as createFilter,f as createMockResponse,q as createRecordBuilder,v as createTableBuilder,x as createTestClient,O as formatError,E as getHttpStatusCode,F as isErrorResponse,k as isListResponse,N as isNetworkError,S as mapFiltersToWhere,w as mapWhereToFilters,R as normalizeFilters,C as resolveServiceURL};
1
+ import{B as e}from"./test-client-rR_4EBUe.mjs";import{u as i,A as r,D as s,E as t,v as a,F as n,t as l,b as o,r as _,R as u,S as d,T as m,V as c,c as p,o as y,h,d as b,p as f,f as q,g as v,q as x,j as O,k as E,i as F,a as k,l as N,m as S,e as w,n as R,s as C}from"./test-client-rR_4EBUe.mjs";function D(i,r={}){return new e(i,r)}class g{static fieldToUpdateRequest(e){return{name:e.name,type:e.type,description:e.description,is_nullable:e.is_nullable,is_unique:e.is_unique,is_indexed:e.is_indexed,is_visible:e.is_visible,is_primary_key:e.is_primary_key,is_readonly:e.is_readonly,field_order:e.field_order,default_value:e.default_value,alignment:e.alignment,decimals:e.decimals,currency_format:e.currency_format,selectable_items:e.selectable_items,multiple_selections:e.multiple_selections,phone_format:e.phone_format,date_format:e.date_format,time_format:e.time_format,timezone:e.timezone,vector_dimension:e.vector_dimension,show_decrypted:e.show_decrypted,is_deterministic:e.is_deterministic}}static applyDefaultValues(e){if(!e.name||!e.type)throw new Error("Column name and type are required");return{name:e.name,type:e.type,is_nullable:!0,is_unique:!1,is_indexed:!1,is_primary_key:!1,is_visible:!0,is_readonly:!1,field_order:1,alignment:"left",multiple_selections:!1,...e}}static createColumnDefinition(e,i,r={}){return this.applyDefaultValues({name:e,type:i,...r})}static getColumnTypeDisplayName(e){return{text:"Text","long-text":"Long Text",number:"Number",currency:"Currency",checkbox:"Checkbox",dropdown:"Dropdown",email:"Email","phone-number":"Phone Number",link:"Link",json:"JSON","date-time":"Date & Time",vector:"Vector",halfvec:"Half Vector",sparsevec:"Sparse Vector",encrypted:"Encrypted"}[e]||e}}class T{static textField(e,i={}){return{name:e,type:"text",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,...i}}static numberField(e,i={}){return{name:e,type:"number",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,decimals:"0.00",...i}}static currencyField(e,i="USD",r={}){return{name:e,type:"currency",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,decimals:"0.00",currency_format:i,...r}}static dropdownField(e,i,r={}){return{name:e,type:"dropdown",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,selection_source:"provide-static-list",selectable_items:i,multiple_selections:!1,...r}}static vectorField(e,i,r={}){return{name:e,type:"vector",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,vector_dimension:i,...r}}static jsonField(e,i={}){return{name:e,type:"json",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,...i}}static dateTimeField(e,i={}){return{name:e,type:"date-time",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,date_format:"YYYY-MM-DD",time_format:"HH:mm:ss",...i}}static emailField(e,i={}){return{name:e,type:"email",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,...i}}static longTextField(e,i={}){return{name:e,type:"long-text",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,...i}}static linkField(e,i={}){return{name:e,type:"link",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,...i}}static phoneNumberField(e,i="international",r={}){return{name:e,type:"phone-number",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,phone_format:i,...r}}static checkboxField(e,i={}){return{name:e,type:"checkbox",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,default_value:!1,...i}}static halfVectorField(e,i,r={}){return{name:e,type:"halfvec",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,vector_dimension:i,...r}}static sparseVectorField(e,i,r={}){return{name:e,type:"sparsevec",is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:1,vector_dimension:i,...r}}static createBasicSchema(e){return e.map((e,i)=>({name:e.name,type:e.type,is_nullable:!0,is_primary_key:!1,is_unique:!1,is_visible:!0,is_readonly:!1,is_indexed:!1,field_order:i+1}))}}class I{constructor(e){this.queryOptions={},this.updateData={},this.tableName=e.tableName,this.columnResource=e.columnResource}where(e){return this.queryOptions.where={...this.queryOptions.where,...e},this}orderBy(e,i="asc"){return this.queryOptions.sort||(this.queryOptions.sort=[]),this.queryOptions.sort.push({field:e,order:i}),this}limit(e){return this.queryOptions.limit=e,this}offset(e){return this.queryOptions.offset=e,this}select(e){return this.queryOptions.fields=e,this}set(e){return this.updateData={...this.updateData,...e},this}async findAll(){return this.columnResource.findAll(this.tableName,this.queryOptions)}async get(){return this.queryOptions.where?.name?this.columnResource.get(this.tableName,this.queryOptions.where.name):{error:{code:"MISSING_COLUMN_NAME",message:"Column name is required for get operation"}}}async update(){return this.queryOptions.where?.name?this.columnResource.update(this.tableName,this.queryOptions.where.name,this.updateData):{error:{code:"MISSING_COLUMN_NAME",message:"Column name is required for update operation"}}}async delete(){return this.queryOptions.where?.name?this.columnResource.delete(this.tableName,this.queryOptions.where.name):{error:{code:"MISSING_COLUMN_NAME",message:"Column name is required for delete operation"}}}getQueryOptions(){return{...this.queryOptions}}getUpdateData(){return{...this.updateData}}}function M(e){return new I(e)}const L="1.0.0";export{i as ALLOWED_FIELD_TYPE_CONVERSIONS,r as ApiError,e as BolticClient,g as ColumnHelpers,s as DateFormatEnum,t as ENV_CONFIGS,a as FIELD_SPECIFIC_KEYS_MAP,n as FILTER_OPERATORS,l as FieldTypeEnum,o as FilterBuilder,_ as REGION_BASE_HOSTS,u as REGION_CONFIGS,T as SchemaHelpers,d as SqlResource,m as TimeFormatEnum,L as VERSION,c as ValidationError,p as buildApiFilters,D as createClient,M as createColumnBuilder,y as createErrorResponse,h as createErrorWithContext,b as createFilter,f as createMockResponse,q as createRecordBuilder,v as createTableBuilder,x as createTestClient,O as formatError,E as getHttpStatusCode,F as isErrorResponse,k as isListResponse,N as isNetworkError,S as mapFiltersToWhere,w as mapWhereToFilters,R as normalizeFilters,C as resolveServiceURL};
2
2
  //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,2 @@
1
+ "use strict";const e={"asia-south1":{local:{baseURL:"http://localhost:8000",timeout:3e4,debug:!0},sit:{baseURL:"https://asia-south1.api.fcz0.de/service/sdk/boltic-tables",timeout:15e3},uat:{baseURL:"https://asia-south1.api.uat.fcz0.de/service/sdk/boltic-tables",timeout:15e3},prod:{baseURL:"https://asia-south1.api.boltic.io/service/sdk/boltic-tables",timeout:1e4}},"us-central1":{local:{baseURL:"http://localhost:8000",timeout:3e4,debug:!0},sit:{baseURL:"https://us-central1.api.fcz0.de/service/sdk/boltic-tables",timeout:15e3},uat:{baseURL:"https://us-central1.api.uat.fcz0.de/service/sdk/boltic-tables",timeout:15e3},prod:{baseURL:"https://us-central1.api.boltic.io/service/sdk/boltic-tables",timeout:1e4}}},t=e["asia-south1"],r={"asia-south1":{local:{host:"http://localhost:8000",timeout:3e4,debug:!0},sit:{host:"https://asia-south1.api.fcz0.de",timeout:15e3},uat:{host:"https://asia-south1.api.uat.fcz0.de",timeout:15e3},prod:{host:"https://asia-south1.api.boltic.io",timeout:1e4}},"us-central1":{local:{host:"http://localhost:8000",timeout:3e4,debug:!0},sit:{host:"https://us-central1.api.fcz0.de",timeout:15e3},uat:{host:"https://us-central1.api.uat.fcz0.de",timeout:15e3},prod:{host:"https://us-central1.api.boltic.io",timeout:1e4}}};function s(e,t,s){const i=r[e];if(!i)throw new Error(`Unsupported region: ${e}`);const a=i[t];if(!a)throw new Error(`Unsupported environment: ${t} for region: ${e}`);return`${a.host}${s}`}function i(e){return"error"in e&&void 0!==e.error}function a(e){return"pagination"in e}class n extends Error{constructor(e,t=[]){super(e),this.name="ValidationError",this.failures=t}}class o extends Error{constructor(e,t,r){super(e),this.name="ApiError",this.statusCode=t,this.response=r}}function d(e,t){const r=new Error(e);return t&&(r.context=t),r}function l(e){if(e&&"object"==typeof e){if("response"in e&&e.response&&"object"==typeof e.response){const t=e.response;if("status"in t&&"number"==typeof t.status)return t.status}if("status"in e&&"number"==typeof e.status)return e.status}return null}function u(e){if(e instanceof Error){const t=e.context,r=l(e);let s=`${e.name}: ${e.message}`;return r&&(s+=` (HTTP ${r})`),t&&(s+=`\nContext: ${JSON.stringify(t,null,2)}`),s}return String(e)}function c(e){const t=(new TextDecoder).decode(e);try{return JSON.parse(t)}catch{return t}}class h{constructor(){try{this.axios=require("axios")}catch(e){throw d("Axios is required for Node.js < 18. Please install axios: npm install axios",{error:e})}}async request(e){try{const t="undefined"!=typeof FormData&&e.data instanceof FormData;let r=e.headers;t&&r&&(r={...r},delete r["Content-Type"],delete r["content-type"]);const s={url:e.url,method:e.method.toLowerCase(),headers:r,params:e.params,data:e.data,timeout:e.timeout,signal:e.signal,validateStatus:()=>!0};"arraybuffer"===e.responseType&&(s.responseType="arraybuffer");const i=await this.axios(s),a=function(e,t,r){return"arraybuffer"!==e.responseType||!(r instanceof ArrayBuffer)||t<400?r:c(r)}(e,i.status,i.data);if(i.status<200||i.status>=300){if("string"==typeof a&&a.trim().startsWith("<!DOCTYPE")||"string"==typeof a&&a.includes("<html")){const t=a.match(/<pre>(.*?)<\/pre>/s);throw d(t?t[1].trim():`HTTP ${i.status}: ${i.statusText}`,{url:e.url,method:e.method,status:i.status,statusText:i.statusText,isHtmlError:!0})}if(a&&"object"==typeof a&&"error"in a)return{data:a,status:i.status,statusText:i.statusText,headers:i.headers||{}};throw d(`HTTP ${i.status}: ${i.statusText}`,{url:e.url,method:e.method,status:i.status,statusText:i.statusText,responseData:a})}return{data:a,status:i.status,statusText:i.statusText,headers:i.headers||{}}}catch(t){const r=t;if("ECONNABORTED"===r.code||r.message?.includes("timeout"))throw d("Request timeout",{url:e.url,method:e.method,timeout:e.timeout});if("ERR_NETWORK"===r.code||"ENOTFOUND"===r.code||"ECONNREFUSED"===r.code||"EHOSTUNREACH"===r.code||"ETIMEDOUT"===r.code||"ERR_INTERNET_DISCONNECTED"===r.code||r.message?.includes("network")||r.message?.includes("internet")||r.message?.includes("connection")||r.message?.includes("resolve"))throw d("Network connection failed. Please check your internet connection or VPN settings.",{url:e.url,method:e.method,networkError:!0,errorCode:r.code,originalMessage:r.message});if("AbortError"===r.name||"ERR_CANCELED"===r.code)throw d("Request was aborted",{url:e.url,method:e.method});throw d(`HTTP request failed: ${r.message||"Unknown error"}`,{url:e.url,method:e.method,originalError:t})}}}async function p(e,t){return"arraybuffer"===t.responseType?async function(e){const t=await e.arrayBuffer();return e.status>=400?c(t):t}(e):async function(e){const t=e.headers.get("content-type");return t?.includes("application/json")?e.json():e.text()}(e)}class m{async request(e){const t=new URL(e.url);e.params&&Object.entries(e.params).forEach(([e,r])=>{null!=r&&t.searchParams.append(e,String(r))});const r="undefined"!=typeof FormData&&e.data instanceof FormData,s={...e.headers||{}};r?(delete s["Content-Type"],delete s["content-type"]):s["Content-Type"]=s["Content-Type"]??s["content-type"]??"application/json";const i={method:e.method,headers:s,signal:e.signal};e.data&&["POST","PUT","PATCH","DELETE"].includes(e.method)&&(i.body=r?e.data:JSON.stringify(e.data));try{const r=new AbortController;let s;e.timeout&&(s=setTimeout(()=>r.abort(),e.timeout),i.signal=e.signal?(()=>{const t=new AbortController;return e.signal.addEventListener("abort",()=>t.abort()),r.signal.addEventListener("abort",()=>t.abort()),t.signal})():r.signal);const a=await fetch(t.toString(),i);s&&clearTimeout(s);const n=await p(a,e),o={};if(a.headers.forEach((e,t)=>{o[t]=e}),a.status<200||a.status>=300){if("string"==typeof n&&(n.trim().startsWith("<!DOCTYPE")||n.includes("<html"))){const t=n.match(/<pre>(.*?)<\/pre>/s);throw d(t?t[1].trim():`HTTP ${a.status}: ${a.statusText}`,{url:e.url,method:e.method,status:a.status,statusText:a.statusText,isHtmlError:!0})}if(n&&"object"==typeof n&&"error"in n)return{data:n,status:a.status,statusText:a.statusText,headers:o};throw d(`HTTP ${a.status}: ${a.statusText}`,{url:e.url,method:e.method,status:a.status,statusText:a.statusText,responseData:n})}return{data:n,status:a.status,statusText:a.statusText,headers:o}}catch(a){if(a instanceof Error&&"AbortError"===a.name)throw d("Request was aborted",{type:"AbortError",url:e.url,method:e.method});if(a instanceof Error){const t=a.message.toLowerCase();if("TypeError"===a.name&&(t.includes("network")||t.includes("fetch")||t.includes("failed to fetch")||t.includes("internet")||t.includes("connection")||t.includes("resolve")||t.includes("unreachable")))throw d("Network connection failed. Please check your internet connection or VPN settings.",{url:e.url,method:e.method,networkError:!0,originalMessage:a.message})}throw d(`HTTP request failed: ${a instanceof Error?a.message:"Unknown error"}`,{url:e.url,method:e.method,originalError:a})}}}function f(){if("undefined"!=typeof fetch)return new m;try{return new h}catch(e){throw d("No suitable HTTP adapter found. Please use Node.js >= 18 or install axios: npm install axios",{error:e})}}class g{constructor(e){this.tokenInfo=null,this.config={maxRetries:3,...e},this.validateApiKey(e.apiKey)}validateApiKey(e){if(!e||"string"!=typeof e||0===e.trim().length)throw d("API key is required and must be a non-empty string",{name:"AuthenticationError",code:"INVALID_API_KEY"});if(e.length<10)throw d("API key appears to be invalid (too short)",{name:"AuthenticationError",code:"INVALID_API_KEY_FORMAT"})}getAuthHeaders(){return{"x-boltic-token":this.config.apiKey}}updateApiKey(e){this.validateApiKey(e),this.config.apiKey=e,this.tokenInfo=null}isAuthenticated(){return!!this.config.apiKey}async validateApiKeyAsync(){try{return this.validateApiKey(this.config.apiKey),!0}catch{return!1}}getTokenInfo(){return this.tokenInfo?{...this.tokenInfo}:null}getMaxRetries(){return this.config.maxRetries||3}toString(){return`AuthManager { authenticated: ${this.isAuthenticated()}, maxRetries: ${this.getMaxRetries()} }`}toJSON(){return{authenticated:this.isAuthenticated(),maxRetries:this.getMaxRetries()}}[Symbol.for("nodejs.util.inspect.custom")](){return this.toString()}}const _="/service/sdk/boltic-tables/v1",b="/service/panel/temporal/v1.0",y="/service/panel/integration/v1",w="/service/panel/serverless/v1.0",E="/service/panel/storage/v1.0";class R{constructor(e,t={},r=_){this.config={apiKey:e,...t},this.httpAdapter=f(),this.environment=t.environment||"prod",this.region=t.region||"asia-south1",this.baseURL=s(this.region,this.environment,r)}resolveAdditionalServiceURL(e){return s(this.region,this.environment,e)}buildHeaders(){return{"Content-Type":"application/json",Accept:"application/json","x-boltic-token":this.config.apiKey,...this.config.headers}}formatErrorResponse(e,t="API"){if(this.config.debug&&console.error(`[${this.constructor.name}] ${t} Error:`,e),e&&"object"==typeof e&&"response"in e){const r=e;return r.response?.data?.error?r.response.data:{error:{code:`${t}_ERROR`,message:e instanceof Error?e.message:`Unknown ${t} error`,meta:[`Status: ${r.response?.status||"unknown"}`]}}}return e instanceof Error?{error:{code:`${t}_CLIENT_ERROR`,message:e.message,meta:[]}}:{error:{code:`${t}_UNKNOWN_ERROR`,message:`An unexpected ${t} error occurred`,meta:[]}}}toString(){return`${this.constructor.name} { environment: "${this.config.environment||"prod"}", debug: ${this.config.debug||!1} }`}toJSON(){const e={...this.config};return delete e.apiKey,{client:this.constructor.name,config:e}}[Symbol.for("nodejs.util.inspect.custom")](){return this.toString()}}class T{constructor(){this.requestInterceptors=new Map,this.responseInterceptors=new Map,this.nextId=0,this.request={use:e=>{const t=this.nextId++;return this.requestInterceptors.set(t,e),t},eject:e=>{this.requestInterceptors.delete(e)}},this.response={use:(e,t)=>{const r=this.nextId++;return this.responseInterceptors.set(r,{fulfilled:e,rejected:t}),r},eject:e=>{this.responseInterceptors.delete(e)}}}async executeRequestInterceptors(e){let t=e;for(const r of Array.from(this.requestInterceptors.values()))t=await r(t);return t}async executeResponseInterceptors(e){let t=e;for(const{fulfilled:r}of Array.from(this.responseInterceptors.values()))r&&(t=await r(t));return t}async executeErrorInterceptors(e){let t=e;for(const{rejected:r}of Array.from(this.responseInterceptors.values()))r&&(t=await r(t));return t}}class v{constructor(e,t){this.config=e,this.authManager=t,this.httpAdapter=f(),this.interceptors=new T,this.setupDefaultInterceptors()}setupDefaultInterceptors(){this.interceptors.request.use(e=>{const t=this.authManager.getAuthHeaders();return e.headers={...e.headers,...t,...this.config.headers},e}),this.interceptors.response.use(e=>(this.config.debug&&console.log("HTTP Response:",e),e),e=>this.handleError(e))}handleError(e){if(this.config.debug&&console.error("HTTP Error:",e),e instanceof Error&&e.context)throw e;const t=l(e);if(!t)throw d("Network request failed",{name:"NetworkError",originalError:e});const r=e.response?.data||e.data;throw d(r?.message||r?.error||`HTTP ${t} error`,{name:"ApiError",statusCode:t,response:r,isClientError:t>=400&&t<500,isServerError:t>=500,isAuthError:401===t||403===t,isNotFoundError:404===t,isRateLimitError:429===t})}async request(e){let t;const r=this.config.maxRetries;for(let i=0;i<=r;i++)try{e.url.startsWith("http")||(e.url=`${this.config.baseURL}${e.url}`),e.timeout||(e.timeout=this.config.timeout);const t=await this.interceptors.executeRequestInterceptors(e),r=await this.httpAdapter.request(t);if(r.status>=400){const e=d(`HTTP ${r.status} error`,{name:"ApiError",statusCode:r.status,response:r.data,statusText:r.statusText});throw await this.interceptors.executeErrorInterceptors(e)}return await this.interceptors.executeResponseInterceptors(r)}catch(s){if(t=s,i===r)break;const e=l(s);if(e&&e>=400&&e<500)break;if(i<r){const e=this.config.retryDelay*Math.pow(2,i);await new Promise(t=>setTimeout(t,e))}}throw await this.interceptors.executeErrorInterceptors(t)}get(e,t){return this.request({...t,method:"GET",url:e})}post(e,t,r){return this.request({...r,method:"POST",url:e,data:t})}put(e,t,r){return this.request({...r,method:"PUT",url:e,data:t})}patch(e,t,r){return this.request({...r,method:"PATCH",url:e,data:t})}delete(e,t){return this.request({...t,method:"DELETE",url:e})}getInterceptors(){return this.interceptors}updateConfig(e){this.config={...this.config,...e}}getConfig(){return{...this.config}}}class A{constructor(e,t){this.client=e,this.basePath=t}getBasePath(){return this.basePath}async makeRequest(e,t,r,s){const i=`${this.basePath}${t}`;try{let t;switch(e){case"GET":t=await this.client.get(i,{params:s?.params});break;case"POST":t=await this.client.post(i,r,{params:s?.params});break;case"PUT":t=await this.client.put(i,r,{params:s?.params});break;case"PATCH":t=await this.client.patch(i,r,{params:s?.params});break;case"DELETE":t=await this.client.delete(i,{params:s?.params})}return t.data}catch(a){return{error:{code:"CLIENT_ERROR",message:u(a),meta:["Request failed"]}}}}buildQueryParams(e={}){const t={};return e.fields?.length&&(t.fields=e.fields.join(",")),e.sort?.length&&(t.sort=e.sort.map(e=>`${e.field}:${e.order}`).join(",")),void 0!==e.limit&&(t.limit=e.limit),void 0!==e.offset&&(t.offset=e.offset),e.where&&Object.entries(e.where).forEach(([e,r])=>{null!=r&&(t[`where[${e}]`]="object"==typeof r?JSON.stringify(r):r)}),t}handleResponse(e){return"error"in e&&this.client.getConfig().debug&&console.error("API Error:",e.error),e}}class C{constructor(t,r="prod",s="asia-south1",i){const a=e[s][r];this.config={apiKey:t,environment:r,region:s,retryAttempts:3,retryDelay:1e3,maxRetries:3,debug:!1,headers:{},...a,...i}}getConfig(){return{...this.config}}updateConfig(e){this.config={...this.config,...e}}toString(){return`ConfigManager { environment: "${this.config.environment}", region: "${this.config.region}", debug: ${this.config.debug} }`}toJSON(){const e={...this.config};return delete e.apiKey,e}[Symbol.for("nodejs.util.inspect.custom")](){return this.toString()}}function I(e,t){if(!t||0===t.length)return e;const r={};for(const s of t)s in e&&(r[s]=e[s]);return r}function S(e,t){return t&&0!==t.length?e.map(e=>I(e,t)):e}function x(e,t){if(!t||""===t)return e;const r=e.includes("?")?"&":"?";return`${e}${r}db_id=${encodeURIComponent(t)}`}const O={path:"/tables/{table_id}/fields/list",method:"POST",authenticated:!0,rateLimit:{requests:200,window:6e4}},N={path:"/tables/{table_id}/fields",method:"POST",authenticated:!0},$={path:"/tables/{table_id}/fields/{field_id}",method:"GET",authenticated:!0,rateLimit:{requests:300,window:6e4}},L={path:"/tables/{table_id}/fields/{field_id}",method:"PATCH",authenticated:!0},q={path:"/tables/{table_id}/fields/{field_id}",method:"DELETE",authenticated:!0},U=(e,t={})=>{let r=e.path;Object.entries(t).forEach(([e,t])=>{r=r.replace(`{${e}}`,encodeURIComponent(t))});const s=r.match(/\{([^}]+)\}/g);if(s)throw new Error(`Missing path parameters: ${s.join(", ")}`);return r},D=Object.freeze({MMDDYY:"%m/%d/%y",MMDDYYYY:"%m/%d/%Y",MM_DD_YYYY:"%m-%d-%Y",DD_MM_YYYY:"%d-%m-%Y",DDMMYYYY:"%d/%m/%Y",DDMMYY:"%d/%m/%y",YYYY_MM_DD:"%Y-%m-%d",MMMM__DD__YYYY:"%B %d %Y",MMM__DD__YYYY:"%b %d %Y",ddd__MMM__DD__YYYY:"%a %b %d %Y"}),k=Object.freeze({HH_mm_ss:"%H:%M:%S",HH_mm_ssZ:"%H:%M:%SZ",HH_mm_ss_SSS:"%H:%M:%S.%f",HH_mm_ss__Z:"%H:%M:%S %Z",HH_mm__AMPM:"%I:%M %p",HH_mm_ss__AMPM:"%I:%M:%S %p"});var P=(e=>(e.TEXT="text",e.EMAIL="email",e.LONG_TEXT="long-text",e.DATE_TIME="date-time",e.NUMBER="number",e.CURRENCY="currency",e.CHECKBOX="checkbox",e.DROPDOWN="dropdown",e.PHONE_NUMBER="phone-number",e.LINK="link",e.JSON="json",e.VECTOR="vector",e.SPARSEVECTOR="sparsevec",e.HALFVECTOR="halfvec",e.ENCRYPTED="encrypted",e))(P||{});const M={text:["email","long-text","date-time","number","currency","checkbox","phone-number","link","json","vector","sparsevec","halfvec","encrypted"],email:["text","long-text","date-time","number","currency","checkbox","phone-number","link","json","vector","sparsevec","halfvec"],"long-text":["text","email","date-time","number","currency","checkbox","phone-number","link","json","vector","sparsevec","halfvec"],"date-time":["text","email","long-text","phone-number","link"],number:["text","email","long-text","currency","phone-number","link"],currency:["text","email","long-text","number","phone-number","link"],checkbox:["text","email","long-text","phone-number","link"],dropdown:[],"phone-number":["text","email","long-text","date-time","number","currency","checkbox","link","json","vector","sparsevec","halfvec"],link:["text","email","long-text","number","currency","checkbox","phone-number","json","vector","sparsevec","halfvec"],json:["text","email","long-text","phone-number","link"],vector:["text","email","long-text","phone-number","link","halfvec","sparsevec","vector"],sparsevec:["text","email","long-text","phone-number","link","vector","halfvec","sparsevec"],halfvec:["text","email","long-text","phone-number","link","vector","sparsevec","halfvec"],encrypted:[]},H={text:[],email:[],"long-text":[],number:["decimals"],currency:["decimals","currency_format"],checkbox:[],dropdown:["selection_source","selectable_items","multiple_selections"],"date-time":["timezone","date_format","time_format"],"phone-number":["phone_format"],link:[],json:[],vector:["vector_dimension"],sparsevec:["vector_dimension"],halfvec:["vector_dimension"],encrypted:["show_decrypted","is_deterministic"]};function B(e){if(!e||"object"!=typeof e)throw new Error("Invalid request: single column data is required");if(!e.name||!e.type)throw new Error("Column name and type are required");return{name:(t=e).name,type:t.type,is_nullable:t.is_nullable??!0,is_primary_key:t.is_primary_key??!1,is_unique:t.is_unique??!1,is_visible:t.is_visible??!0,is_readonly:t.is_readonly??!1,is_indexed:t.is_indexed??!1,field_order:t.field_order??1,alignment:t.alignment??"left",timezone:t.timezone??void 0,date_format:t.date_format?F(t.date_format):void 0,time_format:t.time_format?j(t.time_format):void 0,decimals:t.decimals??void 0,currency_format:t.currency_format??void 0,selection_source:"dropdown"!==t.type||t.selection_source?t.selection_source??void 0:"provide-static-list",selectable_items:t.selectable_items??void 0,multiple_selections:t.multiple_selections??void 0,phone_format:t.phone_format??void 0,vector_dimension:t.vector_dimension??void 0,description:t.description??void 0,default_value:t.default_value??void 0,show_decrypted:t.show_decrypted??void 0,is_deterministic:t.is_deterministic??void 0};var t}function F(e){return D[e]||e}function j(e){return k[e]||e}class Y extends R{constructor(e,t={}){super(e,t)}async createColumn(e,t){try{const r=N,s=`${this.baseURL}${U(r,{table_id:e})}`,i=B(t),a=await this.httpAdapter.request({url:s,method:r.method,headers:this.buildHeaders(),data:i,timeout:this.config.timeout});return this.config.debug&&console.log("Column API Response:",JSON.stringify(a.data,null,2)),a.data}catch(r){return this.formatErrorResponse(r)}}async createColumns(e,t){try{const r=t.columns,s=[];for(const t of r){const r=await this.createColumn(e,t);if(i(r))return r;s.push(r.data)}if(t.fields&&s.length>0){const e=S(s,t.fields);s.splice(0,s.length,...e)}return{data:s,message:"Columns created successfully"}}catch(r){return this.formatErrorResponse(r)}}async listColumns(e,t={}){try{const r=O;let s=`${this.baseURL}${U(r,{table_id:e})}?no_cache=true`;s=x(s,t.db_id);const i=(await this.httpAdapter.request({url:s,method:r.method,headers:this.buildHeaders(),data:t,timeout:this.config.timeout})).data;return t.fields&&i.data&&(i.data=S(i.data,t.fields)),i}catch(r){return this.formatErrorResponse(r)}}async getColumn(e,t,r={}){try{const s=$,i=`${this.baseURL}${U(s,{table_id:e,field_id:t})}`,a=await this.httpAdapter.request({url:i,method:s.method,headers:this.buildHeaders(),timeout:this.config.timeout});this.config.debug&&console.log("Column API Response:",JSON.stringify(a.data,null,2));const n=a.data;return r.fields&&n.data&&(n.data=I(n.data,r.fields)),n}catch(s){return this.formatErrorResponse(s)}}async updateColumn(e,t,r){try{const s=L,i=`${this.baseURL}${U(s,{table_id:e,field_id:t})}`,a=function(e){const t={};return void 0!==e.name&&(t.name=e.name),void 0!==e.type&&(t.type=e.type),void 0!==e.description&&(t.description=e.description),void 0!==e.is_nullable&&(t.is_nullable=e.is_nullable),void 0!==e.is_unique&&(t.is_unique=e.is_unique),void 0!==e.is_primary_key&&(t.is_primary_key=e.is_primary_key),void 0!==e.is_indexed&&(t.is_indexed=e.is_indexed),void 0!==e.is_visible&&(t.is_visible=e.is_visible),void 0!==e.is_readonly&&(t.is_readonly=e.is_readonly),void 0!==e.default_value&&(t.default_value=e.default_value),void 0!==e.field_order&&(t.field_order=e.field_order),void 0!==e.show_decrypted&&(t.show_decrypted=e.show_decrypted),void 0!==e.is_deterministic&&(t.is_deterministic=e.is_deterministic),void 0!==e.alignment&&(t.alignment=e.alignment),void 0!==e.decimals&&(t.decimals=e.decimals),void 0!==e.currency_format&&(t.currency_format=e.currency_format),"dropdown"===e.type||void 0!==e.selectable_items?t.selection_source="provide-static-list":void 0!==e.selection_source&&(t.selection_source=e.selection_source),void 0!==e.selectable_items&&(t.selectable_items=e.selectable_items),void 0!==e.multiple_selections&&(t.multiple_selections=e.multiple_selections),void 0!==e.phone_format&&(t.phone_format=e.phone_format),void 0!==e.timezone&&(t.timezone=e.timezone),void 0!==e.vector_dimension&&(t.vector_dimension=e.vector_dimension),void 0!==e.date_format&&(t.date_format=F(e.date_format)),void 0!==e.time_format&&(t.time_format=j(e.time_format)),t}(r),n=(await this.httpAdapter.request({url:i,method:s.method,headers:this.buildHeaders(),data:a,timeout:this.config.timeout})).data;return r.fields&&n.data&&(n.data=I(n.data,r.fields)),n}catch(s){return this.formatErrorResponse(s)}}async deleteColumn(e,t){try{const r=q,s=`${this.baseURL}${U(r,{table_id:e,field_id:t})}`;return(await this.httpAdapter.request({url:s,method:r.method,headers:this.buildHeaders(),timeout:this.config.timeout})).data}catch(r){return this.formatErrorResponse(r)}}async findColumnByName(e,t){try{const r={page:{page_no:1,page_size:1},filters:[{field:"name",operator:"=",values:[t]}],sort:[]},s=await this.listColumns(e,r);if(i(s))return s;const a=s.data[0]||null;return{data:a,message:a?"Column found":"Column not found"}}catch(r){return this.formatErrorResponse(r)}}convertColumnDetailsToUpdateRequest(e){return{name:e.name,type:e.type,description:e.description,is_nullable:e.is_nullable,is_unique:e.is_unique,is_indexed:e.is_indexed,is_visible:e.is_visible,is_primary_key:e.is_primary_key,is_readonly:e.is_readonly,default_value:e.default_value,field_order:e.field_order,alignment:e.alignment,decimals:e.decimals,currency_format:e.currency_format,selection_source:e.selection_source,selectable_items:e.selectable_items,multiple_selections:e.multiple_selections,phone_format:e.phone_format,date_format:e.date_format,time_format:e.time_format,timezone:e.timezone,vector_dimension:e.vector_dimension}}async updateColumnByName(e,t,r){try{const s=await this.findColumnByName(e,t);if(i(s))return s;if(!s.data)return{error:{code:"COLUMN_NOT_FOUND",message:`Column '${t}' not found in table`,meta:["404"]}};const a={...this.convertColumnDetailsToUpdateRequest(s.data),...r};return await this.updateColumn(e,s.data.id,a)}catch(s){return this.formatErrorResponse(s)}}async deleteColumnByName(e,t){try{const r=await this.findColumnByName(e,t);return i(r)?r:r.data?await this.deleteColumn(e,r.data.id):{error:{code:"COLUMN_NOT_FOUND",message:`Column '${t}' not found in table`,meta:["Column not found"]}}}catch(r){return this.formatErrorResponse(r)}}}const z={path:"/tables/list",method:"POST",authenticated:!0,rateLimit:{requests:200,window:6e4}},K={path:"/tables",method:"POST",authenticated:!0},W={path:"/tables/{table_id}",method:"GET",authenticated:!0,rateLimit:{requests:300,window:6e4}},Q={path:"/tables/{table_id}",method:"PATCH",authenticated:!0},G={path:"/tables/{table_id}",method:"DELETE",authenticated:!0},V=(e,t={})=>{let r=e.path;Object.entries(t).forEach(([e,t])=>{r=r.replace(`{${e}}`,encodeURIComponent(t))});const s=r.match(/\{([^}]+)\}/g);if(s)throw new Error(`Missing path parameters: ${s.join(", ")}`);return r},J={EQUALS:"=",NOT_EQUALS:"!=",GREATER_THAN:">",GREATER_THAN_EQUAL:">=",LESS_THAN:"<",LESS_THAN_EQUAL:"<=",LIKE:"LIKE",ILIKE:"ILIKE",STARTS_WITH:"STARTS WITH",IN:"IN",NOT_IN:"NOT IN",IS_EMPTY:"IS EMPTY",IS_NULL:"IS NULL",IS_NOT_NULL:"IS NOT NULL",BETWEEN:"BETWEEN",ARRAY_CONTAINS:"@>",ARRAY_NOT_CONTAINS:"NOT @>",ANY:"ANY",IS_ONE_OF_ARRAY:"IS ONE OF",DROPDOWN_ITEM_STARTS_WITH:"DROPDOWN ITEM STARTS WITH",WITHIN:"WITHIN"},X={$eq:J.EQUALS,$ne:J.NOT_EQUALS,$gt:J.GREATER_THAN,$gte:J.GREATER_THAN_EQUAL,$lt:J.LESS_THAN,$lte:J.LESS_THAN_EQUAL,$like:J.LIKE,$ilike:J.ILIKE,$startsWith:J.STARTS_WITH,$in:J.IN,$notIn:J.NOT_IN,$between:J.BETWEEN,$isEmpty:J.IS_EMPTY,$isNull:J.IS_NULL,$isNotNull:J.IS_NOT_NULL,$arrayContains:J.ARRAY_CONTAINS,$arrayNotContains:J.ARRAY_NOT_CONTAINS,$any:J.ANY,$isOneOfArray:J.IS_ONE_OF_ARRAY,$dropdownItemStartsWith:J.DROPDOWN_ITEM_STARTS_WITH,$within:J.WITHIN};function Z(e){return Array.isArray(e)?e.length>0&&"object"==typeof e[0]&&"field"in e[0]&&"operator"in e[0]&&"values"in e[0]?e:(console.warn("Legacy Record<string, unknown>[] filter format detected. Please migrate to the new filter format."),[]):ee(e)}function ee(e){const t=[];return Object.entries(e).forEach(([e,r])=>{"object"!=typeof r||Array.isArray(r)||null===r?t.push({field:e,operator:J.EQUALS,values:[r]}):Object.entries(r).forEach(([r,s])=>{const i=X[r];if(!i)throw new Error(`Unsupported operator: ${r}`);let a;a=i===J.BETWEEN&&Array.isArray(s)&&2===s.length?s:i!==J.IN&&i!==J.NOT_IN&&i!==J.IS_ONE_OF_ARRAY||!Array.isArray(s)?i===J.IS_NULL||i===J.IS_NOT_NULL||i===J.IS_EMPTY?[]:[s]:s,t.push({field:e,operator:i,values:a})})}),t}class te{constructor(){this.filters=[]}equals(e,t){return this.filters.push({field:e,operator:J.EQUALS,values:[t]}),this}notEquals(e,t){return this.filters.push({field:e,operator:J.NOT_EQUALS,values:[t]}),this}greaterThan(e,t){return this.filters.push({field:e,operator:J.GREATER_THAN,values:[t]}),this}lessThan(e,t){return this.filters.push({field:e,operator:J.LESS_THAN,values:[t]}),this}between(e,t,r){return this.filters.push({field:e,operator:J.BETWEEN,values:[t,r]}),this}in(e,t){return this.filters.push({field:e,operator:J.IN,values:t}),this}like(e,t){return this.filters.push({field:e,operator:J.LIKE,values:[t]}),this}startsWith(e,t){return this.filters.push({field:e,operator:J.STARTS_WITH,values:[t]}),this}isEmpty(e){return this.filters.push({field:e,operator:J.IS_EMPTY,values:[]}),this}isNull(e){return this.filters.push({field:e,operator:J.IS_NULL,values:[]}),this}arrayContains(e,t){return this.filters.push({field:e,operator:J.ARRAY_CONTAINS,values:[t]}),this}build(){return[...this.filters]}clear(){return this.filters=[],this}}function re(e){return{name:e.name,type:e.type,is_nullable:e.is_nullable??!0,is_primary_key:e.is_primary_key??!1,is_unique:e.is_unique??!1,is_indexed:e.is_indexed??!1,is_visible:e.is_visible??!0,is_readonly:e.is_readonly??!1,field_order:e.field_order??1,alignment:e.alignment??"left",timezone:e.timezone??void 0,date_format:e.date_format??void 0,time_format:e.time_format??void 0,decimals:e.decimals??void 0,currency_format:e.currency_format??void 0,selection_source:"dropdown"!==e.type||e.selection_source?e.selection_source??void 0:"provide-static-list",selectable_items:e.selectable_items??void 0,multiple_selections:e.multiple_selections??!1,phone_format:e.phone_format??void 0,vector_dimension:e.vector_dimension??void 0,description:e.description,default_value:e.default_value}}class se extends R{constructor(e,t={}){super(e,t)}async createTable(e,t={}){try{const r=K;let s=`${this.baseURL}${r.path}`;s=x(s,t.db_id);const i=function(e,t={}){return{name:e.name,description:e.description,fields:e.fields.map(re),is_ai_generated_schema:t.is_ai_generated_schema||!1,is_template:t.is_template||!1}}(e,t);return(await this.httpAdapter.request({url:s,method:r.method,headers:this.buildHeaders(),data:i,timeout:this.config.timeout})).data}catch(r){return this.formatErrorResponse(r)}}async listTables(e={}){try{const t=z;let r=`${this.baseURL}${t.path}`;r=x(r,e.db_id);const s=(await this.httpAdapter.request({url:r,method:t.method,headers:this.buildHeaders(),data:e,timeout:this.config.timeout})).data;return e.fields&&s.data&&(s.data=S(s.data,e.fields)),s}catch(t){return this.formatErrorResponse(t)}}async getTable(e,t={}){try{const r=W;let s=`${this.baseURL}${V(r,{table_id:e})}`;s=x(s,t.db_id);const i=(await this.httpAdapter.request({url:s,method:r.method,headers:this.buildHeaders(),timeout:this.config.timeout})).data;return t.fields&&i.data&&(i.data=I(i.data,t.fields)),i}catch(r){return this.formatErrorResponse(r)}}async updateTable(e,t){try{const{fields:r,db_id:s,...i}=t,a=Q;let n=`${this.baseURL}${V(a,{table_id:e})}`;n=x(n,s);const o=(await this.httpAdapter.request({url:n,method:a.method,headers:this.buildHeaders(),data:i,timeout:this.config.timeout})).data;return r&&o.data&&(o.data=I(o.data,r)),o}catch(r){return this.formatErrorResponse(r)}}async deleteTable(e,t={}){try{const r=G;let s=`${this.baseURL}${V(r,{table_id:e})}`;s=x(s,t.db_id);return(await this.httpAdapter.request({url:s,method:r.method,headers:this.buildHeaders(),timeout:this.config.timeout})).data}catch(r){return this.formatErrorResponse(r)}}}class ie extends A{constructor(e){super(e,"/v1/tables");const t=e.getConfig();this.tablesApiClient=new se(t.apiKey,{environment:t.environment,region:t.region,timeout:t.timeout,debug:t.debug,retryAttempts:t.retryAttempts,retryDelay:t.retryDelay,headers:t.headers})}async create(e,t){try{const r={...e};e.fields&&e.fields.length>0&&(r.fields=await this.processFieldsDefaults(e.fields));const s=await this.tablesApiClient.createTable(r,t?{db_id:t}:{});if(i(s))throw new o(s.error.message||"Create table failed",400,s.error);return s}catch(r){throw r instanceof o?r:new o(this.formatError(r),500)}}async processFieldsDefaults(e){const t=[];for(let r=0;r<e.length;r++){const s={...e[r]};if(void 0===s.is_primary_key&&(s.is_primary_key=!1),void 0===s.is_unique&&(s.is_unique=!1),void 0===s.is_nullable&&(s.is_nullable=!0),void 0===s.is_indexed&&(s.is_indexed=!1),"encrypted"===s.type&&(void 0===s.show_decrypted&&(s.show_decrypted=!1),void 0===s.is_deterministic&&(s.is_deterministic=!1),void 0!==s.default_value&&null!==s.default_value))throw new Error("Encrypted columns do not accept a default value");if(void 0===s.field_order&&(s.field_order=r+1),s.field_order<=0||s.field_order>=2147483647)throw new Error("Field order must be a number greater than 0 and less than 2147483647");t.push(s)}return t}transformTableQueryToApiRequest(e){const t={page:{page_no:1,page_size:e.limit||100},filters:[],sort:[]};if(e.offset&&e.limit){const r=Math.floor(e.offset/e.limit)+1;t.page.page_no=r}return e.where&&Object.entries(e.where).forEach(([e,r])=>{null!=r&&t.filters.push({field:e,operator:"=",values:[r]})}),e.sort&&(t.sort=e.sort.map(e=>({field:e.field,direction:e.order}))),t}async findAll(e={},t){try{const r=this.transformTableQueryToApiRequest(e),s=[...r.filters];t&&s.push({field:"db_id",operator:"=",values:[t]});const a=e.where?.resource_id||"boltic";s.push({field:"resource_id",operator:"=",values:[a]});const n={page:r.page,filters:s,sort:r.sort,...e.fields&&{fields:e.fields}},d=await this.tablesApiClient.listTables(n);if(i(d))throw new o(d.error.message||"List tables failed",400,d.error);return d}catch(r){throw r instanceof o?r:new o(this.formatError(r),500)}}async findOne(e,t){try{if(!e.where?.id&&!e.where?.name)throw new n("Either id or name must be provided in where clause");if(e.where?.id){const r=await this.tablesApiClient.getTable(e.where.id,t?{db_id:t}:{});if(i(r)){if("TABLE_NOT_FOUND"===r.error.code)return{data:null,message:"Table not found"};throw new o(r.error.message||"Get table failed",400,r.error)}return r}{const r=[{field:"name",operator:"=",values:[e.where.name]}];t&&r.push({field:"db_id",operator:"=",values:[t]});const s=e.where?.resource_id||"boltic";r.push({field:"resource_id",operator:"=",values:[s]});const n={page:{page_no:1,page_size:1},filters:r,sort:[]},d=await this.tablesApiClient.listTables(n);if(i(d))throw new o(d.error.message||"Find table by name failed",400,d.error);const l=a(d)?d.data[0]:null;return{data:l||null,message:l?"Table found":"Table not found"}}}catch(r){throw r instanceof o||r instanceof n?r:new o(this.formatError(r),500)}}async findByName(e,t){return this.findOne({where:{name:e}},t)}async findById(e,t){return this.findOne({where:{id:e}},t)}async update(e,t,r){try{const s=await this.findByName(e,r);if(!s.data)throw new o(`Table '${e}' not found`,404);if(s.data.snapshot_url)throw new o(`Cannot update snapshot table '${e}'. Snapshots are read-only and cannot be modified.`,400);const a=await this.tablesApiClient.updateTable(s.data.id,r?{...t,db_id:r}:t);if(i(a))throw new o(a.error.message||"Update table failed",400,a.error);return a}catch(s){throw s instanceof o?s:new o(this.formatError(s),500)}}async delete(e,t){try{const r=await this.findByName(e,t);if(!r.data)throw new o(`Table '${e}' not found`,404);if(r.data.snapshot_url)throw new o(`Cannot delete snapshot table '${e}'. Snapshots are read-only and cannot be deleted.`,400);const s=await this.tablesApiClient.deleteTable(r.data.id,t?{db_id:t}:{});if(i(s))throw new o(s.error.message||"Delete table failed",400,s.error);return s}catch(r){throw r instanceof o?r:new o(this.formatError(r),500)}}async rename(e,t,r){try{return await this.update(e,{name:t},r)}catch(s){throw s instanceof o?s:new o(this.formatError(s),500)}}formatError(e){return e instanceof Error?e.message:"string"==typeof e?e:"An unexpected error occurred"}}class ae extends A{constructor(e){super(e,"/v1/tables");const t=e.getConfig();this.columnsApiClient=new Y(t.apiKey,{environment:t.environment,region:t.region,timeout:t.timeout,debug:t.debug,retryAttempts:t.retryAttempts,retryDelay:t.retryDelay,headers:t.headers}),this.tablesApiClient=new se(t.apiKey,{environment:t.environment,region:t.region,timeout:t.timeout,debug:t.debug,retryAttempts:t.retryAttempts,retryDelay:t.retryDelay,headers:t.headers})}async create(e,t){try{const r=await this.getTableInfo(e);if(!r)return{error:{code:"TABLE_NOT_FOUND",message:`Table '${e}' not found`}};const s=await this.processColumnDefaults(r.id,t),a=await this.columnsApiClient.createColumn(r.id,s);return i(a),a}catch(r){return{error:{code:"CREATE_COLUMN_ERROR",message:r instanceof Error?r.message:"Unknown error occurred"}}}}async processColumnDefaults(e,t){const r={...t};if(void 0===r.is_primary_key&&(r.is_primary_key=!1),void 0===r.is_unique&&(r.is_unique=!1),void 0===r.is_nullable&&(r.is_nullable=!0),void 0===r.is_indexed&&(r.is_indexed=!1),"encrypted"===r.type&&(void 0===r.show_decrypted&&(r.show_decrypted=!1),void 0===r.is_deterministic&&(r.is_deterministic=!1),void 0!==r.default_value&&null!==r.default_value))throw new Error("Encrypted columns do not accept a default value");if(void 0===r.field_order&&(r.field_order=await this.generateFieldOrder(e)),r.field_order<=0||r.field_order>=2147483647)throw new Error("Field order must be a number greater than 0 and less than 2147483647");return r}async generateFieldOrder(e){try{const t=await this.columnsApiClient.listColumns(e);let r=0;if(!i(t)&&t.data&&Array.isArray(t.data))for(const e of t.data)e.field_order&&e.field_order>r&&(r=e.field_order);return r+1}catch(t){return Math.floor(Date.now()/1e3)%2147483647}}transformColumnQueryToApiRequest(e){const t={page:{page_no:1,page_size:e.limit||100},filters:[],sort:[]};if(e.offset&&e.limit){const r=Math.floor(e.offset/e.limit)+1;t.page.page_no=r}return e.where&&Object.entries(e.where).forEach(([e,r])=>{null!=r&&t.filters.push({field:e,operator:"=",values:[r]})}),e.sort&&(t.sort=e.sort.map(e=>({field:e.field,direction:e.order}))),t}async createMany(e,t){try{const r=await this.getTableInfo(e);if(!r)return{error:{code:"TABLE_NOT_FOUND",message:`Table '${e}' not found`}};const s=[];for(const e of t){const t=await this.processColumnDefaults(r.id,e);s.push(t)}const a=await this.columnsApiClient.createColumns(r.id,{columns:s});return i(a),a}catch(r){return{error:{code:"CREATE_COLUMNS_ERROR",message:r instanceof Error?r.message:"Unknown error occurred"}}}}async findAll(e,t={}){try{const r=await this.getTableInfo(e);if(!r)return{error:{code:"TABLE_NOT_FOUND",message:`Table '${e}' not found`}};const s=this.transformColumnQueryToApiRequest(t),a=await this.columnsApiClient.listColumns(r.id,s);return i(a),a}catch(r){return{error:{code:"LIST_COLUMNS_ERROR",message:r instanceof Error?r.message:"Unknown error occurred"}}}}async get(e,t){try{const r=await this.getTableInfo(e);if(!r)return{error:{code:"TABLE_NOT_FOUND",message:`Table '${e}' not found`}};const s=await this.columnsApiClient.findColumnByName(r.id,t);return i(s)?s:s.data?{data:s.data,message:"Column found successfully"}:{error:{code:"COLUMN_NOT_FOUND",message:`Column '${t}' not found in table '${e}'`}}}catch(r){return{error:{code:"GET_COLUMN_ERROR",message:r instanceof Error?r.message:"Unknown error occurred"}}}}async findById(e,t){try{const r=await this.getTableInfo(e);if(!r)return{error:{code:"TABLE_NOT_FOUND",message:`Table '${e}' not found`}};const s=await this.columnsApiClient.getColumn(r.id,t);return i(s),s}catch(r){return{error:{code:"FIND_COLUMN_BY_ID_ERROR",message:r instanceof Error?r.message:"Unknown error occurred"}}}}async update(e,t,r){try{const s=await this.getTableInfo(e);if(!s)return{error:{code:"TABLE_NOT_FOUND",message:`Table '${e}' not found`}};const a=await this.columnsApiClient.updateColumnByName(s.id,t,r);return i(a),a}catch(s){return{error:{code:"UPDATE_COLUMN_ERROR",message:s instanceof Error?s.message:"Unknown error occurred"}}}}async delete(e,t){try{const r=await this.getTableInfo(e);if(!r)return{error:{code:"TABLE_NOT_FOUND",message:`Table '${e}' not found`}};const s=await this.columnsApiClient.deleteColumnByName(r.id,t);return i(s)?s:{data:{success:!0,message:"Column deleted successfully"}}}catch(r){return{error:{code:"DELETE_COLUMN_ERROR",message:r instanceof Error?r.message:"Unknown error occurred"}}}}async getTableInfo(e){try{const t=new ie(this.client),r=await t.findByName(e);return r.data?{id:r.data.id,snapshot_url:r.data.snapshot_url}:null}catch(t){return console.error("Error getting table info:",t),null}}async getTableId(e){const t=await this.getTableInfo(e);return t?.id||null}}const ne={path:"/tables/databases",method:"POST",authenticated:!0},oe={path:"/tables/databases/list",method:"POST",authenticated:!0},de={path:"/tables/databases/{db_id}",method:"PATCH",authenticated:!0},le={path:"/tables/databases/{db_id}",method:"DELETE",authenticated:!0},ue={path:"/tables/databases/jobs/list",method:"POST",authenticated:!0},ce={path:"/tables/databases/delete-status/{job_id}",method:"GET",authenticated:!0},he=(e,t={})=>{let r=e.path;return Object.entries(t).forEach(([e,t])=>{r=r.replace(`{${e}}`,t)}),r};class pe extends R{constructor(e,t={}){super(e,t)}async createDatabase(e){try{const t=ne,r=`${this.baseURL}${t.path}`;return(await this.httpAdapter.request({url:r,method:t.method,headers:this.buildHeaders(),data:e,timeout:this.config.timeout})).data}catch(t){return this.formatErrorResponse(t)}}async listDatabases(e={},t,r){try{const s=oe;let i=`${this.baseURL}${s.path}`;const a=new URLSearchParams;t?.connector_id&&a.append("connector_id",t.connector_id),t?.add_default_if_missing&&a.append("add_default_if_missing",t.add_default_if_missing),a.toString()&&(i+=`?${a.toString()}`);const n=(await this.httpAdapter.request({url:i,method:s.method,headers:this.buildHeaders(),data:e,timeout:this.config.timeout})).data;return r?.fields&&!("error"in n)?{...n,data:S(n.data,r.fields)}:n}catch(s){return this.formatErrorResponse(s)}}async updateDatabase(e,t){try{const r=de,s=he(r,{db_id:e}),i=`${this.baseURL}${s}`;return(await this.httpAdapter.request({url:i,method:r.method,headers:this.buildHeaders(),data:t,timeout:this.config.timeout})).data}catch(r){return this.formatErrorResponse(r)}}async deleteDatabase(e){try{const t=le,r=he(t,{db_id:e}),s=`${this.baseURL}${r}`;return(await this.httpAdapter.request({url:s,method:t.method,headers:this.buildHeaders(),timeout:this.config.timeout})).data}catch(t){return this.formatErrorResponse(t)}}async listDatabaseJobs(e={},t){try{const r=ue,s=`${this.baseURL}${r.path}`,i=(await this.httpAdapter.request({url:s,method:r.method,headers:this.buildHeaders(),data:e,timeout:this.config.timeout})).data;return t?.fields&&!("error"in i)?{...i,data:S(i.data,t.fields)}:i}catch(r){return this.formatErrorResponse(r)}}async pollDeleteStatus(e){try{const t=ce,r=he(t,{job_id:e}),s=`${this.baseURL}${r}`;return(await this.httpAdapter.request({url:s,method:t.method,headers:this.buildHeaders(),timeout:this.config.timeout})).data}catch(t){return this.formatErrorResponse(t)}}}class me extends A{constructor(e){super(e,"/v1/tables/databases"),this.apiClient=new pe(e.getConfig().apiKey,{environment:e.getConfig().environment,region:e.getConfig().region,timeout:e.getConfig().timeout,debug:e.getConfig().debug})}async create(e){const t=await this.apiClient.createDatabase(e);return i(t)?{error:{code:"number"==typeof t.error.code?String(t.error.code):t.error.code,message:t.error.message,meta:t.error.meta}}:t}async findAll(e){const t={};if(e?.page&&(t.page=e.page),e?.sort&&(t.sort=e.sort),e?.filters){const r=e.filters.filter(e=>"status"!==e.field);t.filters=[...r,{field:"status",operator:"=",values:["ACTIVE"]}]}else t.filters=[{field:"status",operator:"=",values:["ACTIVE"]}];const r={};e?.connector_id&&(r.connector_id=e.connector_id),void 0!==e?.add_default_if_missing&&(r.add_default_if_missing=e.add_default_if_missing?"true":"false");const s=await this.apiClient.listDatabases(t,r,e);if(i(s))return{error:{code:"number"==typeof s.error.code?String(s.error.code):s.error.code,message:s.error.message,meta:s.error.meta}};if("pagination"in s&&s.pagination){const e=s.pagination;return{...s,pagination:{total_count:e.total_count,total_pages:e.total_pages??Math.ceil(e.total_count/e.per_page),current_page:e.current_page,per_page:e.per_page,type:"page"}}}return s}async findOne(e,t){const r=await this.findAll({filters:[{field:"db_internal_name",operator:"=",values:[e]}],fields:t?.fields,page:{page_no:1,page_size:1}});return i(r)?r:0===r.data.length?{error:{code:"NOT_FOUND",message:`Database with internal name '${e}' not found`,meta:[]}}:{data:r.data[0],message:"Database found"}}async getDefault(){const e=await this.findAll({filters:[{field:"is_default",operator:"=",values:[!0]}],page:{page_no:1,page_size:1}});return i(e)?e:0===e.data.length?{error:{code:"NOT_FOUND",message:"Default database not found",meta:[]}}:{data:e.data[0],message:"Default database found"}}async update(e,t){const r=await this.findOne(e);if(i(r))return{error:{code:"DATABASE_NOT_FOUND",message:`Database with internal name '${e}' not found`,meta:[]}};const s=r.data.id,a={db_name:t.db_name},n=await this.apiClient.updateDatabase(s,a);return i(n)?{error:{code:"number"==typeof n.error.code?String(n.error.code):n.error.code,message:n.error.message,meta:n.error.meta}}:n}async delete(e){const t=await this.findOne(e);if(i(t))return{error:{code:"DATABASE_NOT_FOUND",message:`Database with internal name '${e}' not found`,meta:[]}};if(t.data.is_default)return{error:{code:"CANNOT_DELETE_DEFAULT",message:"Cannot delete the default database",meta:[]}};const r=t.data.id,s=await this.apiClient.deleteDatabase(r);return i(s)?{error:{code:"number"==typeof s.error.code?String(s.error.code):s.error.code,message:s.error.message,meta:s.error.meta}}:s}async listJobs(e){const t={};void 0!==e?.deleted_by_me&&(t.deleted_by_me=e.deleted_by_me),e?.page&&(t.page=e.page),e?.sort&&(t.sort=e.sort),e?.filters&&(t.filters=e.filters);const r=await this.apiClient.listDatabaseJobs(t,e);if(i(r))return{error:{code:"number"==typeof r.error.code?String(r.error.code):r.error.code,message:r.error.message,meta:r.error.meta}};if("pagination"in r&&r.pagination){const e=r.pagination;return{...r,pagination:{total_count:e.total_count,total_pages:e.total_pages??Math.ceil(e.total_count/e.per_page),current_page:e.current_page,per_page:e.per_page,type:"page"}}}return{...r,data:r.data||[]}}async pollDeleteStatus(e){const t=await this.apiClient.pollDeleteStatus(e);return i(t)?{error:{code:"number"==typeof t.error.code?String(t.error.code):t.error.code,message:t.error.message,meta:t.error.meta}}:t}}const fe={path:"/tables/indexes/{table_id}",method:"POST",authenticated:!0},ge={path:"/tables/indexes/{table_id}/list",method:"POST",authenticated:!0},_e={path:"/tables/indexes/{table_id}",method:"DELETE",authenticated:!0},be=(e,t={})=>{let r=e.path;Object.entries(t).forEach(([e,t])=>{r=r.replace(`{${e}}`,encodeURIComponent(t))});const s=r.match(/\{([^}]+)\}/g);if(s)throw new Error(`Missing path parameters: ${s.join(", ")}`);return r};class ye extends R{constructor(e,t={}){super(e,t)}async addIndex(e,t,r){try{const s=fe;let i=`${this.baseURL}${be(s,{table_id:e})}`;i=x(i,r);return(await this.httpAdapter.request({url:i,method:s.method,headers:this.buildHeaders(),data:t,timeout:this.config.timeout})).data}catch(s){return this.formatErrorResponse(s)}}async listIndexes(e,t,r){try{const s=ge;let i=`${this.baseURL}${be(s,{table_id:e})}`;i=x(i,r);return(await this.httpAdapter.request({url:i,method:s.method,headers:this.buildHeaders(),data:t,timeout:this.config.timeout})).data}catch(s){return this.formatErrorResponse(s)}}async deleteIndex(e,t,r){try{const s=_e;let i=`${this.baseURL}${be(s,{table_id:e})}`;i=x(i,r);return(await this.httpAdapter.request({url:i,method:s.method,headers:this.buildHeaders(),data:t,timeout:this.config.timeout})).data}catch(s){return this.formatErrorResponse(s)}}}class we{constructor(e){this.client=e;const t=e.getConfig();this.apiClient=new ye(t.apiKey,{environment:t.environment,region:t.region,timeout:t.timeout,debug:t.debug,retryAttempts:t.retryAttempts,retryDelay:t.retryDelay,headers:t.headers}),this.tableResource=new ie(e)}async resolveTableId(e,t){const r=await this.tableResource.findByName(e,t);if(!r.data)throw new Error(`Table not found: ${e}`);return r.data.id}async addIndex(e,t,r){try{const s=await this.resolveTableId(e,r);return await this.apiClient.addIndex(s,t,r)}catch(s){return{error:{code:"CLIENT_ERROR",message:s?.message||"Failed to add index",meta:["IndexResource.addIndex"]}}}}async listIndexes(e,t,r){try{const s=await this.resolveTableId(e,r);return await this.apiClient.listIndexes(s,t,r)}catch(s){return{error:{code:"CLIENT_ERROR",message:s?.message||"Failed to list indexes",meta:["IndexResource.listIndexes"]}}}}async deleteIndex(e,t,r){try{const s=await this.resolveTableId(e,r),i={index_name:t};return await this.apiClient.deleteIndex(s,i,r)}catch(s){return{error:{code:"CLIENT_ERROR",message:s?.message||"Failed to delete index",meta:["IndexResource.deleteIndex"]}}}}}const Ee={path:"/tables/{table_id}/records",method:"POST",authenticated:!0},Re={path:"/tables/{table_id}/records/bulk-insert",method:"POST",authenticated:!0},Te={path:"/tables/{table_id}/records/list",method:"POST",authenticated:!0,rateLimit:{requests:200,window:6e4}},ve={path:"/tables/{table_id}/records/{record_id}",method:"GET",authenticated:!0,rateLimit:{requests:200,window:6e4}},Ae={path:"/tables/{table_id}/records/bulk-update",method:"PUT",authenticated:!0},Ce={path:"/tables/{table_id}/records/{record_id}",method:"PATCH",authenticated:!0},Ie={path:"/tables/{table_id}/records/list",method:"DELETE",authenticated:!0},Se=(e,t={})=>{let r=e.path;Object.entries(t).forEach(([e,t])=>{r=r.replace(`{${e}}`,encodeURIComponent(t))});const s=r.match(/\{([^}]+)\}/g);if(s)throw new Error(`Missing path parameters: ${s.join(", ")}`);return r};class xe extends R{constructor(e,t={}){super(e,t)}async insertRecord(e,t){try{const{table_id:r,fields:s,...i}=e;if(!r)return this.formatErrorResponse(new Error("table_id is required for insert operation"));const a=Ee;let n=`${this.baseURL}${Se(a,{table_id:r})}`;n=x(n,t);const o=(await this.httpAdapter.request({url:n,method:a.method,headers:this.buildHeaders(),data:i,timeout:this.config.timeout})).data;return s&&o.data&&(o.data=I(o.data,s)),o}catch(r){return this.formatErrorResponse(r)}}async insertManyRecords(e,t,r={validation:!0},s){try{if(!t)return this.formatErrorResponse(new Error("table_id is required for bulk insert operation"));if(!e||!Array.isArray(e)||0===e.length)return this.formatErrorResponse(new Error("records array is required and cannot be empty"));const i=Re;let a=`${this.baseURL}${Se(i,{table_id:t})}`;const n=new URLSearchParams;void 0!==r.validation&&n.append("validation",r.validation.toString()),n.toString()&&(a+=`?${n.toString()}`),a=x(a,s);return(await this.httpAdapter.request({url:a,method:i.method,headers:this.buildHeaders(),data:e,timeout:this.config.timeout})).data}catch(i){return this.formatErrorResponse(i)}}async getRecord(e,t,r={},s){try{if(!t)return this.formatErrorResponse(new Error("table_id is required for get operation"));const i=ve;let a=`${this.baseURL}${Se(i,{table_id:t,record_id:e})}`;const n=new URLSearchParams;r.show_decrypted&&n.append("show_decrypted","true"),n.toString()&&(a+=`?${n.toString()}`),a=x(a,s);const o=(await this.httpAdapter.request({url:a,method:i.method,headers:this.buildHeaders(),timeout:this.config.timeout})).data;return r.fields&&o.data&&(o.data=I(o.data,r.fields)),o}catch(i){return this.formatErrorResponse(i)}}async listRecords(e={},t){try{const{table_id:r,...s}=e;if(!r)return this.formatErrorResponse(new Error("table_id is required for list operation"));const i=Te;let a=`${this.baseURL}${Se(i,{table_id:r})}`;a=x(a,t);const n=(await this.httpAdapter.request({url:a,method:i.method,headers:this.buildHeaders(),data:s,timeout:this.config.timeout})).data;return s.fields&&n.data&&(n.data=S(n.data,s.fields)),n}catch(r){return this.formatErrorResponse(r)}}async updateRecords(e,t){try{const{table_id:r,set:s,filters:i,fields:a,show_decrypted:n,...o}=e;if(!r)return this.formatErrorResponse(new Error("table_id is required for update operation"));const d={updates:s,filters:i,...o};a&&(d.fields=a);const l=Ae;let u=`${this.baseURL}${Se(l,{table_id:r})}`;const c=new URLSearchParams;n&&c.append("show_decrypted","true"),c.toString()&&(u+=`?${c.toString()}`),u=x(u,t);const h=(await this.httpAdapter.request({url:u,method:l.method,headers:this.buildHeaders(),data:d,timeout:this.config.timeout})).data;return a&&h.data&&(h.data=S(h.data,a)),h}catch(r){return this.formatErrorResponse(r)}}async updateRecordById(e,t,r){try{const{table_id:s,show_decrypted:i,...a}=t;if(!s)return this.formatErrorResponse(new Error("table_id is required for updateById operation"));const n=Ce;let o=`${this.baseURL}${Se(n,{record_id:e,table_id:s})}`;const d=new URLSearchParams;i&&d.append("show_decrypted","true"),d.toString()&&(o+=`?${d.toString()}`),o=x(o,r);const l=(await this.httpAdapter.request({url:o,method:n.method,headers:this.buildHeaders(),data:a.set,timeout:this.config.timeout})).data;return a.fields&&l.data&&(l.data=I(l.data,a.fields)),l}catch(s){return this.formatErrorResponse(s)}}async deleteRecords(e,t){try{const{table_id:r}=e;if(!r)return this.formatErrorResponse(new Error("table_id is required for delete operation"));const s=function(e){const t={};return e.record_ids&&e.record_ids.length>0&&(t.record_ids=e.record_ids),e.filters&&(Array.isArray(e.filters)?(e.filters.length>0&&"object"==typeof e.filters[0]&&"field"in e.filters[0]&&"operator"in e.filters[0]&&"values"in e.filters[0]||console.warn("Legacy Record<string, unknown>[] filter format detected. Please migrate to the new filter format."),t.filters=e.filters):t.filters=ee(e.filters)),t}(e),i=Ie;let a=`${this.baseURL}${Se(i,{table_id:r})}`;a=x(a,t);return(await this.httpAdapter.request({url:a,method:i.method,headers:this.buildHeaders(),data:s,timeout:this.config.timeout})).data}catch(r){return this.formatErrorResponse(r)}}async deleteRecordById(e,t,r){return this.deleteRecords({record_ids:[e],table_id:t.table_id},r)}}class Oe{constructor(e){this.client=e,this.apiClient=new xe(e.getConfig().apiKey,{environment:e.getConfig().environment,region:e.getConfig().region,timeout:e.getConfig().timeout,debug:e.getConfig().debug}),this.tablesApiClient=new se(e.getConfig().apiKey,{environment:e.getConfig().environment,region:e.getConfig().region,timeout:e.getConfig().timeout,debug:e.getConfig().debug})}async insert(e,t,r){try{const s=await this.getTableInfo(e,r);if(!s)return{error:{code:"TABLE_NOT_FOUND",message:`Table '${e}' not found`}};const a=await this.ensureCompleteRecordData(e,t);if("error"in a&&a.error)return a;const n={...a,table_id:s.id},o=await this.apiClient.insertRecord(n,r);return i(o),o}catch(s){return{error:{code:"INSERT_ERROR",message:s instanceof Error?s.message:"Unknown error occurred"}}}}async insertMany(e,t,r={validation:!0},s){try{if(!t||!Array.isArray(t)||0===t.length)return{error:{code:"INVALID_INPUT",message:"Records array is required and cannot be empty"}};const a=await this.getTableInfo(e,s);if(!a)return{error:{code:"TABLE_NOT_FOUND",message:`Table '${e}' not found`}};const n=await this.apiClient.insertManyRecords(t,a.id,r,s);return i(n),n}catch(a){return{error:{code:"INSERT_MANY_ERROR",message:a instanceof Error?a.message:"Unknown error occurred"}}}}async get(e,t,r,s){try{let a=!1,n=s;"string"==typeof r?n=r:"object"==typeof r&&(a=r.show_decrypted||!1,n=r.dbId||s);const o=await this.getTableInfo(e,n);if(!o)return{error:{code:"TABLE_NOT_FOUND",message:`Table '${e}' not found`}};const d=await this.apiClient.getRecord(t,o.id,{fields:void 0,show_decrypted:a},n);return i(d),d}catch(a){return{error:{code:"GET_ERROR",message:a instanceof Error?a.message:"Unknown error occurred"}}}}async list(e,t={},r){try{const s=await this.getTableInfo(e,r);if(!s)return{error:{code:"TABLE_NOT_FOUND",message:`Table '${e}' not found`}};const a={...t,table_id:s.id},n=await this.apiClient.listRecords(a,r);return i(n),n}catch(s){return{error:{code:"LIST_ERROR",message:s instanceof Error?s.message:"Unknown error occurred"}}}}async update(e,t,r){try{const s=await this.getTableInfo(e,r);if(!s)return{error:{code:"TABLE_NOT_FOUND",message:`Table '${e}' not found`}};const a={...t,table_id:s.id},n=await this.apiClient.updateRecords(a,r);return i(n),n}catch(s){return{error:{code:"UPDATE_ERROR",message:s instanceof Error?s.message:"Unknown error occurred"}}}}async updateById(e,t,r,s,a){try{let n=!1,o=a;"string"==typeof s?o=s:"object"==typeof s&&(n=s.show_decrypted||!1,o=s.dbId||a);const d=await this.getTableInfo(e,o);if(!d)return{error:{code:"TABLE_NOT_FOUND",message:`Table '${e}' not found`}};const l={id:t,set:r,table_id:d.id,show_decrypted:n},u=await this.apiClient.updateRecordById(t,l,o);return i(u),u}catch(n){return{error:{code:"UPDATE_BY_ID_ERROR",message:n instanceof Error?n.message:"Unknown error occurred"}}}}async delete(e,t,r){try{const s=await this.getTableInfo(e,r);if(!s)return{error:{code:"TABLE_NOT_FOUND",message:`Table '${e}' not found`}};const a={...t,table_id:s.id},n=await this.apiClient.deleteRecords(a,r);return i(n),n}catch(s){return{error:{code:"DELETE_ERROR",message:s instanceof Error?s.message:"Unknown error occurred"}}}}async deleteById(e,t,r){try{const s=await this.getTableInfo(e,r);if(!s)return{error:{code:"TABLE_NOT_FOUND",message:`Table '${e}' not found`}};const a=await this.apiClient.deleteRecordById(t,{table_id:s.id},r);return i(a),a}catch(s){return{error:{code:"DELETE_BY_ID_ERROR",message:s instanceof Error?s.message:"Unknown error occurred"}}}}async getTableInfo(e,t){try{const r=new ie(this.client),s=await r.findByName(e,t);return s.data?{id:s.data.id,snapshot_url:s.data.snapshot_url}:null}catch(r){return console.error("Error getting table info:",r),null}}async ensureCompleteRecordData(e,t){try{const r=new ae(this.client),s=await r.findAll(e);if(i(s))return s;const a=Array.isArray(s.data)?s.data:[],n={...t};for(const e of a)"id"!==e.name&&"created_at"!==e.name&&"updated_at"!==e.name&&(e.name in t||(n[e.name]=null));return n}catch(r){return{error:{code:"COMPLETE_DATA_ERROR",message:r instanceof Error?r.message:"Unknown error occurred"}}}}}class Ne{constructor(e){this.queryOptions={},this.updateData={},this.tableName=e.tableName,this.recordResource=e.recordResource}where(e){return this.queryOptions.filters||(this.queryOptions.filters=[]),Object.entries(e).forEach(([e,t])=>{this.queryOptions.filters.push({field:e,operator:"equals",values:[t]})}),this}orderBy(e,t="asc"){return this.queryOptions.sort||(this.queryOptions.sort=[]),this.queryOptions.sort.push({field:e,order:t}),this}limit(e){return this.queryOptions.page?this.queryOptions.page.page_size=e:this.queryOptions.page={page_no:1,page_size:e},this}offset(e){if(this.queryOptions.page){const t=this.queryOptions.page.page_size||50;this.queryOptions.page.page_no=Math.floor(e/t)+1}else this.queryOptions.page={page_no:Math.floor(e/50)+1,page_size:50};return this}select(e){return this.queryOptions.fields=e,this}set(e){return this.updateData={...this.updateData,...e},this}page(e,t=50){return this.queryOptions.page={page_no:e,page_size:t},this}async list(){return this.recordResource.list(this.tableName,this.queryOptions)}async findAll(){return this.recordResource.list(this.tableName,this.queryOptions)}async findOne(){const e={...this.queryOptions,limit:1},t=await this.recordResource.list(this.tableName,e);if("error"in t)return t;const r=t.data.length>0?t.data[0]:null;return{data:r,message:r?"Record found":"No record found"}}buildWhereConditions(){const e={};return this.queryOptions.filters&&this.queryOptions.filters.forEach(t=>{if("field"in t&&"values"in t){const r=t,s=String(r.field);"equals"===r.operator?e[s]=r.values[0]:"contains"===r.operator?e[s]={$like:`%${String(r.values[0])}%`}:e[s]=r.values[0]}else Object.assign(e,t)}),e}async update(){if(!this.updateData)return{error:{code:"MISSING_UPDATE_DATA",message:"Update data is required for update operation"}};const e={set:this.updateData,filters:this.queryOptions.filters||[]};return this.recordResource.update(this.tableName,e)}async updateById(e){return this.recordResource.updateById(this.tableName,e,this.updateData)}async deleteById(e){return this.recordResource.deleteById(this.tableName,e)}async deleteByIds(e){return this.recordResource.delete(this.tableName,{record_ids:e})}async delete(){if(!this.queryOptions.filters||0===this.queryOptions.filters.length)return{error:{code:"MISSING_DELETE_CONDITIONS",message:"Filter conditions are required for delete operation. Use where() to specify conditions."}};const e={filters:this.buildWhereConditions()};return this.recordResource.delete(this.tableName,e)}getQueryOptions(){return{...this.queryOptions}}getUpdateData(){return{...this.updateData}}async insert(e){return this.recordResource.insert(this.tableName,e)}}function $e(e){return new Ne(e)}const Le={path:"/tables/query/text-to-sql",method:"POST",authenticated:!0,rateLimit:{requests:100,window:6e4}},qe={path:"/tables/query/execute",method:"POST",authenticated:!0,rateLimit:{requests:200,window:6e4}},Ue=(e,t={})=>{let r=e.path;return Object.entries(t).forEach(([e,t])=>{r=r.replace(`{${e}}`,encodeURIComponent(t))}),r};class De extends R{constructor(e,t={}){super(e,t)}async textToSQL(e,t){try{const r=Le;let s=`${this.baseURL}${Ue(r)}`;t&&(s+=`?db_id=${encodeURIComponent(t)}`);const i=await this.httpAdapter.request({url:s,method:r.method,headers:{...this.buildHeaders(),"x-request-source":"sdk"},data:e,timeout:this.config.timeout});if(i.status>=400)return this.formatErrorResponse({response:{data:i.data,status:i.status}},"SQL");const a=i.data;return this.createAsyncIterable(a.data)}catch(r){return this.formatErrorResponse(r,"SQL")}}async executeSQL(e,t){try{const r=qe;let s=`${this.baseURL}${Ue(r)}`;t&&(s+=`?db_id=${encodeURIComponent(t)}`);const i=await this.httpAdapter.request({url:s,method:r.method,headers:{...this.buildHeaders(),"x-request-source":"sdk"},data:e,timeout:this.config.timeout});return i.status>=400?this.formatErrorResponse({response:{data:i.data,status:i.status}},"SQL"):i.data}catch(r){return this.formatErrorResponse(r,"SQL")}}async*createAsyncIterable(e){yield e}}class ke{constructor(e){const t=e.getConfig();this.sqlApiClient=new De(t.apiKey,{environment:t.environment,region:t.region,timeout:t.timeout,debug:t.debug,retryAttempts:t.retryAttempts,retryDelay:t.retryDelay,headers:t.headers})}async textToSQL(e,t={},r){const s=function(e,t={}){return{prompt:e,current_query:t.currentQuery}}(e,t),i=await this.sqlApiClient.textToSQL(s,r);if("error"in i&&void 0!==i.error)throw i;return i}async executeSQL(e,t){const r=await this.sqlApiClient.executeSQL({query:e},t);return i(r),r}}class Pe{constructor(e,t){this.fields=[],this.tableName=e.name,this.description=e.description,this.tablesApiClient=t}name(e){return this.tableName=e,this}describe(e){return this.description=e,this}text(e,t={}){return this.fields.push({name:e,type:"text",is_nullable:t.nullable??!0,is_unique:t.unique??!1,is_indexed:t.indexed??!1,is_primary_key:!1,default_value:t.defaultValue,description:t.description,alignment:t.alignment||"left",field_order:this.fields.length+1}),this}longText(e,t={}){return this.fields.push({name:e,type:"long-text",is_nullable:t.nullable??!0,is_unique:!1,is_indexed:!1,is_primary_key:!1,description:t.description,alignment:t.alignment||"left",field_order:this.fields.length+1}),this}number(e,t={}){return this.fields.push({name:e,type:"number",is_nullable:t.nullable??!0,is_unique:t.unique??!1,is_indexed:t.indexed??!1,is_primary_key:!1,default_value:t.defaultValue,description:t.description,decimals:t.decimals,alignment:t.alignment||"right",field_order:this.fields.length+1}),this}currency(e,t={}){return this.fields.push({name:e,type:"currency",is_nullable:t.nullable??!0,is_unique:!1,is_indexed:!1,is_primary_key:!1,default_value:t.defaultValue,description:t.description,currency_format:t.currencyFormat,decimals:t.decimals,alignment:"right",field_order:this.fields.length+1}),this}checkbox(e,t={}){return this.fields.push({name:e,type:"checkbox",is_nullable:t.nullable??!0,is_unique:!1,is_indexed:!1,is_primary_key:!1,default_value:t.defaultValue,description:t.description,alignment:"center",field_order:this.fields.length+1}),this}dropdown(e,t,r={}){return this.fields.push({name:e,type:"dropdown",is_nullable:r.nullable??!0,is_unique:!1,is_indexed:!1,is_primary_key:!1,default_value:r.defaultValue,description:r.description,selection_source:"provide-static-list",selectable_items:t,multiple_selections:r.multiple??!1,alignment:"left",field_order:this.fields.length+1}),this}email(e,t={}){return this.fields.push({name:e,type:"email",is_nullable:t.nullable??!0,is_unique:t.unique??!1,is_indexed:t.indexed??!1,is_primary_key:!1,description:t.description,alignment:"left",field_order:this.fields.length+1}),this}phone(e,t={}){return this.fields.push({name:e,type:"phone-number",is_nullable:t.nullable??!0,is_unique:!1,is_indexed:!1,is_primary_key:!1,description:t.description,phone_format:t.format,alignment:"left",field_order:this.fields.length+1}),this}link(e,t={}){return this.fields.push({name:e,type:"link",is_nullable:t.nullable??!0,is_unique:!1,is_indexed:!1,is_primary_key:!1,description:t.description,alignment:"left",field_order:this.fields.length+1}),this}json(e,t={}){return this.fields.push({name:e,type:"json",is_nullable:t.nullable??!0,is_unique:!1,is_indexed:!1,is_primary_key:!1,description:t.description,alignment:"left",field_order:this.fields.length+1}),this}dateTime(e,t={}){return this.fields.push({name:e,type:"date-time",is_nullable:t.nullable??!0,is_unique:!1,is_indexed:!1,is_primary_key:!1,description:t.description,date_format:t.dateFormat,time_format:t.timeFormat,timezone:t.timezone,alignment:"left",field_order:this.fields.length+1}),this}vector(e,t,r={}){return this.fields.push({name:e,type:"vector",is_nullable:r.nullable??!0,is_unique:!1,is_indexed:!1,is_primary_key:!1,description:r.description,vector_dimension:t,alignment:"left",field_order:this.fields.length+1}),this}addField(e){return this.fields.push({...e,field_order:e.field_order||this.fields.length+1}),this}removeField(e){return this.fields=this.fields.filter(t=>t.name!==e),this.fields.forEach((e,t)=>{e.field_order=t+1}),this}getFields(){return[...this.fields]}getName(){return this.tableName}getDescription(){return this.description}build(){if(!this.tableName)throw new n("Table name is required",[{field:"name",message:"Table name cannot be empty"}]);if(0===this.fields.length)throw new n("At least one field is required",[{field:"fields",message:"Table must have at least one field"}]);return{name:this.tableName,description:this.description,fields:this.fields}}async create(e={}){if(!this.tablesApiClient)throw new Error("TablesApiClient is required for table creation");const t=this.build();return this.tablesApiClient.createTable(t,e)}}function Me(e,t){return new Pe(e,t)}const He={string:{type:"string",fallback_value:""},number:{type:"number",fallback_value:""},boolean:{type:"boolean",secondary_type:"string",fallback_value:""},int:{type:"number",fallback_value:""},integer:{type:"number",fallback_value:""},"date-time":{type:"date-time",secondary_type:"string",fallback_value:""},date:{type:"date",secondary_type:"string",fallback_value:""},json:{type:"object",fallback_value:{}},text:{type:"string",fallback_value:""},email:{type:"string",fallback_value:""},password:{type:"string",fallback_value:""},url:{type:"string",fallback_value:""},textarea:{type:"string",fallback_value:""},select:{type:"string",fallback_value:""},multiselect:{type:"string",fallback_value:""},autocomplete:{type:"array",fallback_value:[]},radio:{type:"string",fallback_value:""},radiobuttons:{type:"string",fallback_value:""},checkbox:{type:"array",fallback_value:[]},toggle:{type:"boolean",fallback_value:""},hidden:{type:"string",fallback_value:""},slider:{type:"number",fallback_value:""},datepicker:{type:"string",fallback_value:""},phoneinput:{type:"string",fallback_value:""},time:{type:"string",fallback_value:""},datetime:{type:"string",fallback_value:""},code:{type:"string",fallback_value:""},multitext:{type:"array",fallback_value:[]},array:{type:"array",fallback_value:[]},keyvalue:{type:"object",fallback_value:{}},object:{type:"object",fallback_value:{}},phone:{type:"string",fallback_value:""},"number[]":{type:"string",fallback_value:""},"number []":{type:"string",fallback_value:""},"object | any":{type:"string",fallback_value:""}},Be={path:"/workflows/execute/activity",method:"POST",authenticated:!0},Fe={path:"/workflows/run/{run_id}",method:"GET",authenticated:!0},je={path:"/integrations",method:"GET",authenticated:!0},Ye={path:"/integrations/entity/{entity}",method:"GET",authenticated:!0},ze={path:"/integrations/{integration_slug}/schema",method:"GET",authenticated:!0},Ke={path:"/integrations/{integration_slug}/fields",method:"GET",authenticated:!0};function We(e,t={}){let r=e.path;for(const[s,i]of Object.entries(t))r=r.replace(`{${s}}`,i);return r}class Qe extends R{constructor(e,t={}){super(e,t,b),this.integrationBaseURL=this.resolveAdditionalServiceURL(y)}async executeActivity(e){try{const t=Be,r=`${this.baseURL}${t.path}`;return(await this.httpAdapter.request({url:r,method:t.method,headers:this.buildHeaders(),data:e,timeout:this.config.timeout})).data}catch(t){return this.formatErrorResponse(t,"WORKFLOW")}}async getExecutionById(e){try{const t=Fe,r=We(t,{run_id:e}),s=`${this.baseURL}${r}`;return(await this.httpAdapter.request({url:s,method:t.method,headers:this.buildHeaders(),timeout:this.config.timeout})).data}catch(t){return this.formatErrorResponse(t,"WORKFLOW")}}async getIntegrations(e={}){try{const t=je,r=new URLSearchParams({page:String(e.page??1),per_page:String(e.per_page??999)}),s=`${this.baseURL}${t.path}?${r.toString()}`;return(await this.httpAdapter.request({url:s,method:t.method,headers:this.buildHeaders(),timeout:this.config.timeout})).data}catch(t){return this.formatErrorResponse(t,"WORKFLOW")}}async getCredentials(e){try{const t=Ye,r=We(t,{entity:e.entity.toUpperCase()}),s=new URLSearchParams({current_page:String(e.current_page??1),page_size:String(e.page_size??999)}),i=`${this.integrationBaseURL}${r}?${s.toString()}`;return(await this.httpAdapter.request({url:i,method:t.method,headers:this.buildHeaders(),timeout:this.config.timeout})).data}catch(t){return this.formatErrorResponse(t,"INTEGRATION")}}async getIntegrationResource(e){try{const t=ze,r=We(t,{integration_slug:e.integration_slug}),s=`${this.baseURL}${r}`;return(await this.httpAdapter.request({url:s,method:t.method,headers:this.buildHeaders(),timeout:this.config.timeout})).data}catch(t){return this.formatErrorResponse(t,"WORKFLOW")}}async getIntegrationForm(e){try{const t=Ke,r=We(t,{integration_slug:e.integration_slug}),s=new URLSearchParams({resource:e.resource,operation:e.operation,secret:e.secret}),i=`${this.baseURL}${r}?${s.toString()}`;return(await this.httpAdapter.request({url:i,method:t.method,headers:this.buildHeaders(),timeout:this.config.timeout})).data}catch(t){return this.formatErrorResponse(t,"WORKFLOW")}}}const Ge=new Set(["resource","operation"]);function Ve(e){return He[e]??{type:"string",fallback_value:""}}function Je(e){return new Promise(t=>setTimeout(t,e))}class Xe extends A{constructor(e){super(e,"/workflows");const t=e.getConfig();this.apiClient=new Qe(t.apiKey,{environment:t.environment,region:t.region,timeout:t.timeout,debug:t.debug})}async executeIntegration(e){const t=function(e){return{nodes:[{data:{type:e.data.type,name:e.data.name,properties:e.data.properties}}],result:e.result??{payload:{},global_variables:{}}}}(e),r=await this.apiClient.executeActivity(t);if(i(r))return r;if(e.executeOnly)return r;const s=r.data?.execution_id;return s?this.pollExecution(s):{error:{code:"MISSING_EXECUTION_ID",message:"Execute API response did not contain an execution_id",meta:[]}}}async getIntegrationExecuteById(e){return this.apiClient.getExecutionById(e)}async getIntegrations(e={}){return this.apiClient.getIntegrations(e)}async getCredentials(e){return this.apiClient.getCredentials(e)}async getIntegrationResource(e){return this.apiClient.getIntegrationResource(e)}async getIntegrationForm(e){const t=await this.apiClient.getIntegrationForm(e);if(console.log("rawResult",JSON.stringify(t,null,2)),i(t))return t;const r=(t.data?.parameters||t.data)??[],s=e.asJsonSchema?function(e,t=Ge){const r={};for(const s of e){if(t.has(s.name))continue;const e=Ve(s.meta?.displayType||"text"),i=s.meta?.validation?.required??!1,a=void 0!==s.meta?.value?s.meta.value:e.fallback_value,n={type:e.type,required:i,default:a};s.meta?.description&&(n.description=s.meta.description),s.meta?.options&&Array.isArray(s.meta.options)&&s.meta.options.length>0&&(n.enum=s.meta.options.map(e=>e.value)),r[s.name]=n}return{type:"object",properties:r}}(r):function(e,t=Ge){const r={};for(const s of e){if(t.has(s.name))continue;const e=Ve(s.meta?.displayType||"text");r[s.name]=void 0!==s.meta?.value?s.meta.value:e.fallback_value}return r}(r);if(e.asJsonSchema){const t=s;t.properties.secret&&(t.properties.secret.default=e.secret)}else{"secret"in s&&(s.secret=e.secret)}return{data:s,message:t.message}}async pollExecution(e){const t=this.client.getConfig().debug;for(let r=0;r<30;r++){const s=await this.apiClient.getExecutionById(e);if(i(s))return s;if(s.data&&Object.keys(s.data).length>0)return t&&console.log(`[WorkflowResource] Execution ${e} completed after ${r+1} poll(s)`),s;await Je(1e3)}return{error:{code:"EXECUTION_TIMEOUT",message:`Execution ${e} did not complete within 30 polling attempts`,meta:[`execution_id: ${e}`,"max_attempts: 30"]}}}}const Ze=["running","failed","degraded","suspended"],et={path:"/apps",method:"GET",authenticated:!0},tt={path:"/apps/{app_id}",method:"GET",authenticated:!0},rt={path:"/apps",method:"POST",authenticated:!0},st={path:"/apps/{app_id}",method:"PUT",authenticated:!0},it={path:"/apps/{app_id}/builds",method:"GET",authenticated:!0},at={path:"/apps/{app_id}/logs",method:"GET",authenticated:!0},nt={path:"/apps/{app_id}/builds/{build_id}/logs",method:"GET",authenticated:!0};function ot(e,t={}){let r=e.path;for(const[s,i]of Object.entries(t))r=r.replace(`{${s}}`,i);return r}class dt extends R{constructor(e,t={}){super(e,t,w)}async list(e={}){try{const t=et,r=new URLSearchParams({page:String(e.page??1),limit:String(e.limit??20),sortBy:e.sortBy??"CreatedAt",sortOrder:e.sortOrder??"desc"});e.query&&r.set("q",e.query);const s=`${this.baseURL}${t.path}?${r.toString()}`;return(await this.httpAdapter.request({url:s,method:t.method,headers:this.buildHeaders(),timeout:this.config.timeout})).data}catch(t){return this.formatErrorResponse(t,"SERVERLESS")}}async get(e){try{const t=tt,r=ot(t,{app_id:e}),s=`${this.baseURL}${r}`;console.log("url",s);const i=await this.httpAdapter.request({url:s,method:t.method,headers:this.buildHeaders(),timeout:this.config.timeout});return console.log("response",i.data),i.data}catch(t){return this.formatErrorResponse(t,"SERVERLESS")}}async create(e){try{const t=rt,r=`${this.baseURL}${t.path}`;return(await this.httpAdapter.request({url:r,method:t.method,headers:this.buildHeaders(),data:e,timeout:this.config.timeout})).data}catch(t){return this.formatErrorResponse(t,"SERVERLESS")}}async update(e){try{const t=st,r=ot(t,{app_id:e.appId}),s=`${this.baseURL}${r}`;return(await this.httpAdapter.request({url:s,method:t.method,headers:this.buildHeaders(),data:e.payload,timeout:this.config.timeout})).data}catch(t){return this.formatErrorResponse(t,"SERVERLESS")}}async getBuilds(e){try{const t=it,r=ot(t,{app_id:e.appId}),s=new URLSearchParams({page:String(e.page??1),limit:String(e.limit??20),sortBy:"CreatedAt",sortOrder:"desc"}),i=`${this.baseURL}${r}?${s.toString()}`;return(await this.httpAdapter.request({url:i,method:t.method,headers:this.buildHeaders(),timeout:this.config.timeout})).data}catch(t){return this.formatErrorResponse(t,"SERVERLESS")}}async getLogs(e){try{const t=at,r=ot(t,{app_id:e.appId}),s=Math.floor(Date.now()/1e3),i=s-86400,a=new URLSearchParams({page:String(e.page??1),limit:String(e.limit??50),sortBy:"Timestamp",sortOrder:e.sortOrder??"DESC",timestampStart:String(e.timestampStart??i),timestampEnd:String(e.timestampEnd??s),metric_interval:"60"}),n=`${this.baseURL}${r}?${a.toString()}`;return(await this.httpAdapter.request({url:n,method:t.method,headers:this.buildHeaders(),timeout:this.config.timeout})).data}catch(t){return this.formatErrorResponse(t,"SERVERLESS")}}async getBuildLogs(e){try{const t=nt,r=ot(t,{app_id:e.appId,build_id:e.buildId}),s=new URLSearchParams({limit:"-1",tail:"false",sortOrder:"asc",sortBy:"Timestamp"}),i=`${this.baseURL}${r}?${s.toString()}`;return(await this.httpAdapter.request({url:i,method:t.method,headers:this.buildHeaders(),timeout:this.config.timeout})).data}catch(t){return this.formatErrorResponse(t,"SERVERLESS")}}}function lt(e){return new Promise(t=>setTimeout(t,e))}class ut extends A{constructor(e){super(e,"/serverless");const t=e.getConfig();this.apiClient=new dt(t.apiKey,{environment:t.environment,region:t.region,timeout:t.timeout,debug:t.debug})}async list(e={}){return this.apiClient.list(e)}async get(e){return this.apiClient.get(e)}async create(e){return this.apiClient.create(e)}async createAndWait(e){const t=await this.apiClient.create(e);if(i(t))return t;const r=t.data?.ID;return r?this.pollStatus(r):{error:{code:"SERVERLESS_MISSING_ID",message:"Create API response did not contain an ID",meta:[]}}}async update(e){return this.apiClient.update(e)}async updateAndWait(e){const t=await this.apiClient.update(e);return i(t)?t:this.pollStatus(e.appId)}async getBuilds(e){return this.apiClient.getBuilds(e)}async getLogs(e){return this.apiClient.getLogs(e)}async getBuildLogs(e){return this.apiClient.getBuildLogs(e)}async pollStatus(e,t={}){const r=t.intervalMs??5e3,s=t.maxAttempts??60,a=this.client.getConfig().debug;for(let n=0;n<s;n++){const t=await this.apiClient.get(e);if(i(t))return t;const s=t.data?.Status;if(a&&console.log(`[ServerlessResource] Poll #${n+1}: status=${s}`),s&&Ze.includes(s))return a&&console.log(`[ServerlessResource] Reached terminal state: ${s} after ${n+1} poll(s)`),t;await lt(r)}return{error:{code:"SERVERLESS_STATUS_TIMEOUT",message:`Serverless ${e} did not reach a terminal state within ${s} polling attempts`,meta:[`app_id: ${e}`,`max_attempts: ${s}`,`interval_ms: ${r}`]}}}}const ct={path:"/storage/list",method:"GET",authenticated:!0},ht={path:"/storage/upload",method:"POST",authenticated:!0},pt={path:"/storage/directory",method:"POST",authenticated:!0},mt={path:"/storage/file",method:"DELETE",authenticated:!0},ft={path:"/storage/change-object-access",method:"POST",authenticated:!0},gt={path:"/storage/file-export",method:"POST",authenticated:!0};function _t(e){return e.path}const bt="STORAGE";class yt extends R{constructor(e,t={}){super(e,t,E)}async requestStorage(e){try{return(await this.httpAdapter.request(e)).data}catch(t){return this.formatErrorResponse(t,bt)}}url(e,t){const r=t?.toString();return r?`${this.baseURL}${e}?${r}`:`${this.baseURL}${e}`}storageTypeQuery(e){const t=new URLSearchParams;return t.set("storageType",e??"gcs"),t}listQuery(e){const t=this.storageTypeQuery(e.storageType);return void 0!==e.basePath&&t.set("basePath",e.basePath),void 0!==e.pageSize&&t.set("pageSize",String(e.pageSize)),void 0!==e.nextPageToken&&t.set("nextPageToken",e.nextPageToken),t}normalizeExpireInMinutes(e){const t="number"==typeof e?e:Number(e);if(!Number.isFinite(t)||t<=0)throw new Error("expire_in must be a positive number of minutes (max 7 days for temporary signed URLs)");const r=Math.trunc(t);return Math.min(Math.max(1,r),10080)}isTruthyFormFlag(e){if(void 0===e)return!1;if("boolean"==typeof e)return e;const t=String(e).toLowerCase();return"true"===t||"1"===t||"yes"===t}appendUploadVisibility(e,t){if(Object.prototype.hasOwnProperty.call(t,"public")){return this.isTruthyFormFlag(t.public)?void 0!==t.expire_in?(e.append("is_public","true"),void e.append("expire_in",String(this.normalizeExpireInMinutes(t.expire_in)))):(e.append("is_public","false"),void e.append("is_public_permanent","true")):void e.append("is_public","false")}void 0!==t.is_public&&e.append("is_public",String(t.is_public)),void 0!==t.expire_in&&e.append("expire_in",String(this.normalizeExpireInMinutes(t.expire_in))),void 0!==t.is_public_permanent&&e.append("is_public_permanent",String(t.is_public_permanent))}buildUploadForm(e){const t=e.filename??e.file_name;if(null==t||""===t)throw new Error("upload requires filename or file_name");const r=new FormData;return r.append("file",e.file,t),r.append("filename",t),void 0!==e.filepath&&r.append("filepath",e.filepath),void 0!==e.overwrite&&r.append("overwrite",String(e.overwrite)),this.appendUploadVisibility(r,e),r}isErrorResult(e){return"object"==typeof e&&null!==e&&"error"in e&&void 0!==e.error}isAclErrorResult(e){return"object"==typeof e&&null!==e&&"error"in e&&void 0!==e.error}buildObjectAccessSummary(e,t,r){return{name:t?.name??t?.fullPath??e,size:t?.size??null,updated:t?.updatedAt??null,public:null!=t?Boolean(t.isPublic):r}}async findFileListItem(e,t){const r=e.lastIndexOf("/"),s=-1===r?e:e.slice(r+1),i=-1===r?"":e.slice(0,r),a=i?`${i}/`:"",n=await this.list({basePath:a,storageType:t});if(this.isErrorResult(n))return n;return(n.files?.data??[]).find(t=>t.fullPath===e||!t.isDirectory&&(t.name===s||t.fullPath===e))??null}normalizeListItem(e){const t=e.metadata??{};let r;void 0!==t.size&&null!==t.size&&(r=String(t.size));const s=t.updated??t.timeUpdated;let i;null!=s&&(i=String(s));const a=e.name,n=e.parentPath,o=Boolean(e.isDirectory);let d;!o&&a&&(d=n?`${n}/${a}`:a);const l=e.cdnUrl,u=null==l?null:l,c={name:a,path:e.path,folderName:e.folderName,parentPath:n,isDirectory:o,isPublic:e.isPublic,cdnUrl:u,fullPath:d};return void 0!==r&&(c.size=r),void 0!==i&&(c.updatedAt=i),c}normalizeUploadData(e){const t={message:String(e.message??""),path:String(e.path??"")},r=e.temporary_sharable_link??e.shareable_link;return null!=r&&""!==String(r)&&(t.temporary_sharable_link=String(r)),void 0!==e.public_url&&null!==e.public_url&&(t.public_url=String(e.public_url)),t}normalizeListResponse(e){const t=e.files;return t?.data?{files:{...t,data:t.data.map(e=>this.normalizeListItem(e))}}:e}async list(e={}){const t=ct,r=_t(t),s=await this.requestStorage({url:this.url(r,this.listQuery(e)),method:t.method,headers:this.buildHeaders(),timeout:this.config.timeout});return this.isErrorResult(s)?s:this.normalizeListResponse(s)}async createFolder(e){const t=pt,r=_t(t),s=this.storageTypeQuery(e.storageType);return this.requestStorage({url:this.url(r,s),method:t.method,headers:this.buildHeaders(),data:{folder_path:e.folder_path},timeout:this.config.timeout})}async deleteFile(e){const t=mt,r=_t(t),s=this.storageTypeQuery(e.storageType);s.set("filename",e.filename);const i={};return void 0!==e.filepath&&(i.filepath=e.filepath),void 0!==e.totalsize&&(i.totalsize=e.totalsize),this.requestStorage({url:this.url(r,s),method:t.method,headers:this.buildHeaders(),data:Object.keys(i).length?i:void 0,timeout:this.config.timeout})}async setObjectAccess(e){const t=ft,r=_t(t),s=await this.requestStorage({url:this.url(r),method:t.method,headers:this.buildHeaders(),data:{file_path:e.file_path,public:e.public},timeout:this.config.timeout});if(this.isAclErrorResult(s))return s;const i=await this.findFileListItem(e.file_path);return this.isAclErrorResult(i)?i:this.buildObjectAccessSummary(e.file_path,i,e.public)}async upload(e){const t=ht,r=_t(t),s=this.storageTypeQuery(e.storageType),i={...this.buildHeaders()};delete i["Content-Type"];const a=await this.requestStorage({url:this.url(r,s),method:t.method,headers:i,data:this.buildUploadForm(e),timeout:this.config.timeout});return this.isAclErrorResult(a)?a:this.normalizeUploadData(a)}async resolveFileSizeBytes(e,t){const r=e.lastIndexOf("/"),s=-1===r?e:e.slice(r+1),i=-1===r?"":e.slice(0,r),a=i?`${i}/`:"",n=await this.list({basePath:a,storageType:t});if(this.isErrorResult(n))throw new Error(n.error?.message??"List failed while resolving file size");const o=(n.files?.data??[]).find(t=>t.fullPath===e||!t.isDirectory&&t.name===s),d=o?.size;if(void 0===d)throw new Error(`Could not resolve size for "${e}". Pass sizeBytes (from list() item size).`);return Number(d)}async downloadFile(e){try{const t=void 0!==e.sizeBytes?Number(e.sizeBytes):await this.resolveFileSizeBytes(e.file_name,e.storageType);if(!Number.isFinite(t)||t<=0)throw new Error("Invalid or unknown file size. Pass sizeBytes from list() item size.");const r=_t(gt),s=this.storageTypeQuery(e.storageType),i=await this.httpAdapter.request({url:this.url(r,s),method:"POST",headers:{...this.buildHeaders(),Accept:"*/*"},data:{file_name:e.file_name,start_byte:0,end_byte:t-1},timeout:this.config.timeout,responseType:"arraybuffer"});if(i.status<200||i.status>=300){const e=i.data;return e&&"object"==typeof e&&null!==e&&"error"in e?e:this.formatErrorResponse(new Error(`Download failed: HTTP ${i.status}`),bt)}if(!(i.data instanceof ArrayBuffer))throw new Error("Expected binary response body");const a=i.headers,n=a["content-type"]??a["Content-Type"]??void 0;return{bytes:i.data,status:i.status,contentType:n}}catch(t){return this.formatErrorResponse(t,bt)}}}class wt extends A{constructor(e){super(e,"/storage");const t=e.getConfig();this.apiClient=new yt(t.apiKey,{environment:t.environment,region:t.region,timeout:t.timeout,debug:t.debug,headers:t.headers})}async list(e={}){return this.apiClient.list(e)}async upload(e){return this.apiClient.upload(e)}async createFolder(e){return this.apiClient.createFolder(e)}async deleteFile(e){return this.apiClient.deleteFile(e)}async makePublic(e){return this.apiClient.setObjectAccess({file_path:e,public:!0})}async makePrivate(e){return this.apiClient.setObjectAccess({file_path:e,public:!1})}async downloadFile(e){return this.apiClient.downloadFile(e)}}class Et{constructor(e,t={}){this.currentDatabase=null,this.clientOptions=t,this.configManager=new C(e,t.environment||"prod",t.region||"asia-south1",t);const r=this.configManager.getConfig();this.authManager=new g({apiKey:r.apiKey,maxRetries:r.maxRetries}),this.baseClient=new v(r,this.authManager),this.tableResource=new ie(this.baseClient),this.columnResource=new ae(this.baseClient),this.recordResource=new Oe(this.baseClient),this.sqlResource=new ke(this.baseClient),this.indexResource=new we(this.baseClient),this.databaseResource=new me(this.baseClient),this.workflowResource=new Xe(this.baseClient),this.serverlessResource=new ut(this.baseClient),this.storageResource=new wt(this.baseClient),this.currentDatabase=null}getCurrentDatabase(){return this.currentDatabase}async useDatabase(e){if(console.log(`Database internal name:${e}`),!e||""===e)return void(this.currentDatabase=null);const t=await this.databaseResource.findOne(e);if(console.log(`Result:${JSON.stringify(t,null,2)}`),i(t))throw console.log(`Error:${t.error.message}`),new Error(t.error.message||`Failed to switch database to internal name '${e}'`);const r=t.data;this.currentDatabase={databaseId:r.id,dbInternalName:r.db_internal_name||e}}get databases(){return{create:e=>this.databaseResource.create(e),findAll:e=>this.databaseResource.findAll(e),findOne:(e,t)=>this.databaseResource.findOne(e,t),getDefault:()=>this.databaseResource.getDefault(),update:(e,t)=>this.databaseResource.update(e,t),delete:e=>this.databaseResource.delete(e),listJobs:e=>this.databaseResource.listJobs(e),pollDeleteStatus:e=>this.databaseResource.pollDeleteStatus(e)}}get tables(){const e=this.currentDatabase?.databaseId;return{create:t=>this.tableResource.create(t,e),findAll:t=>this.tableResource.findAll(t,e),findById:t=>this.tableResource.findById(t,e),findByName:t=>this.tableResource.findByName(t,e),findOne:t=>this.tableResource.findOne(t,e),update:(t,r)=>this.tableResource.update(t,r,e),delete:t=>this.tableResource.delete(t,e),rename:(t,r)=>this.tableResource.rename(t,r,e)}}get columns(){return{create:(e,t)=>this.columnResource.create(e,t),createMany:(e,t)=>this.columnResource.createMany(e,t),findAll:(e,t)=>this.columnResource.findAll(e,t),findOne:(e,t)=>this.columnResource.get(e,t),findById:(e,t)=>this.columnResource.findById(e,t),update:(e,t,r)=>this.columnResource.update(e,t,r),delete:(e,t)=>this.columnResource.delete(e,t)}}get indexes(){return{addIndex:(e,t)=>this.indexResource.addIndex(e,t),listIndexes:(e,t)=>this.indexResource.listIndexes(e,t),deleteIndex:(e,t)=>this.indexResource.deleteIndex(e,t)}}table(e){return Me({name:e})}from(e){const t=this.currentDatabase?.databaseId;return{indexes:()=>({addIndex:r=>this.indexResource.addIndex(e,r,t),listIndexes:r=>this.indexResource.listIndexes(e,r,t),deleteIndex:r=>this.indexResource.deleteIndex(e,r,t)}),records:()=>({insert:r=>this.recordResource.insert(e,r,t),insertMany:(r,s)=>this.recordResource.insertMany(e,r,s,t),findOne:r=>this.recordResource.get(e,r,t),update:r=>this.recordResource.update(e,r,t),updateById:(r,s)=>this.recordResource.updateById(e,r,s,t),delete:r=>this.recordResource.delete(e,r,t),deleteById:r=>this.recordResource.deleteById(e,r,t)})}}get records(){const e=this.currentDatabase?.databaseId;return{insert:(t,r)=>this.recordResource.insert(t,r,e),insertMany:(t,r,s)=>this.recordResource.insertMany(t,r,s,e),findAll:(t,r)=>this.recordResource.list(t,r,e),findOne:(t,r,s)=>this.recordResource.get(t,r,s,e),update:(t,r)=>this.recordResource.update(t,r,e),updateById:(t,r,s,i)=>this.recordResource.updateById(t,r,s,i,e),delete:(t,r)=>this.recordResource.delete(t,r,e),deleteById:(t,r)=>this.recordResource.deleteById(t,r,e)}}record(e){return $e({tableName:e,recordResource:this.recordResource})}get sql(){const e=this.currentDatabase?.databaseId;return{textToSQL:(t,r)=>this.sqlResource.textToSQL(t,r,e),executeSQL:t=>this.sqlResource.executeSQL(t,e)}}get workflow(){return{executeIntegration:e=>this.workflowResource.executeIntegration(e),getIntegrationExecuteById:e=>this.workflowResource.getIntegrationExecuteById(e),getIntegrations:e=>this.workflowResource.getIntegrations(e),getCredentials:e=>this.workflowResource.getCredentials(e),getIntegrationResource:e=>this.workflowResource.getIntegrationResource(e),getIntegrationForm:e=>this.workflowResource.getIntegrationForm(e)}}get serverless(){return{list:e=>this.serverlessResource.list(e),get:e=>this.serverlessResource.get(e),create:e=>this.serverlessResource.create(e),createAndWait:e=>this.serverlessResource.createAndWait(e),update:e=>this.serverlessResource.update(e),updateAndWait:e=>this.serverlessResource.updateAndWait(e),getBuilds:e=>this.serverlessResource.getBuilds(e),getLogs:e=>this.serverlessResource.getLogs(e),getBuildLogs:e=>this.serverlessResource.getBuildLogs(e),pollStatus:(e,t)=>this.serverlessResource.pollStatus(e,t)}}get storage(){return{list:e=>this.storageResource.list(e),upload:e=>this.storageResource.upload(e),createFolder:e=>this.storageResource.createFolder(e),deleteFile:e=>this.storageResource.deleteFile(e),makePublic:e=>this.storageResource.makePublic(e),makePrivate:e=>this.storageResource.makePrivate(e),downloadFile:e=>this.storageResource.downloadFile(e)}}getSqlResource(){return this.sqlResource}updateApiKey(e){this.configManager.updateConfig({apiKey:e}),this.authManager.updateApiKey(e)}updateConfig(e){this.configManager.updateConfig(e),this.baseClient.updateConfig(this.configManager.getConfig()),this.updateAllResourcesConfig()}getConfig(){return this.configManager.getConfig()}async validateApiKey(){return this.authManager.validateApiKeyAsync()}isAuthenticated(){return this.authManager.isAuthenticated()}getHttpClient(){return this.baseClient}addRequestInterceptor(e){return this.baseClient.getInterceptors().request.use(e)}addResponseInterceptor(e,t){return this.baseClient.getInterceptors().response.use(e,t)}ejectRequestInterceptor(e){this.baseClient.getInterceptors().request.eject(e)}ejectResponseInterceptor(e){this.baseClient.getInterceptors().response.eject(e)}async testConnection(){try{return await this.authManager.validateApiKeyAsync()}catch(e){return!1}}getVersion(){return"1.0.0"}getEnvironment(){return this.configManager.getConfig().environment}getRegion(){return this.configManager.getConfig().region}enableDebug(){this.configManager.updateConfig({debug:!0}),this.baseClient.updateConfig(this.configManager.getConfig()),this.updateAllResourcesConfig()}disableDebug(){this.configManager.updateConfig({debug:!1}),this.baseClient.updateConfig(this.configManager.getConfig()),this.updateAllResourcesConfig()}isDebugEnabled(){return this.configManager.getConfig().debug||!1}updateAllResourcesConfig(){this.tableResource=new ie(this.baseClient),this.columnResource=new ae(this.baseClient),this.recordResource=new Oe(this.baseClient),this.sqlResource=new ke(this.baseClient),this.indexResource=new we(this.baseClient),this.databaseResource=new me(this.baseClient),this.workflowResource=new Xe(this.baseClient),this.serverlessResource=new ut(this.baseClient),this.storageResource=new wt(this.baseClient)}toString(){const e=this.getConfig();return`BolticClient { environment: "${e.environment}", region: "${e.region}", debug: ${e.debug} }`}toJSON(){const e=this.getConfig();return{environment:e.environment,region:e.region,debug:e.debug,timeout:e.timeout,version:this.getVersion()}}[Symbol.for("nodejs.util.inspect.custom")](){return this.toString()}}exports.ALLOWED_FIELD_TYPE_CONVERSIONS=M,exports.ApiError=o,exports.BolticClient=Et,exports.DateFormatEnum=D,exports.ENV_CONFIGS=t,exports.FIELD_SPECIFIC_KEYS_MAP=H,exports.FILTER_OPERATORS=J,exports.FieldTypeEnum=P,exports.FilterBuilder=te,exports.REGION_BASE_HOSTS=r,exports.REGION_CONFIGS=e,exports.SqlResource=ke,exports.TimeFormatEnum=k,exports.ValidationError=n,exports.buildApiFilters=function(e,t="AND"){const r=Z(e);return r.forEach((e,t)=>{if(!e.field)throw new Error(`Filter at index ${t} missing required field`);if(!e.operator)throw new Error(`Filter at index ${t} missing required operator`);if(!Array.isArray(e.values))throw new Error(`Filter at index ${t} values must be an array`)}),{filters:r,whereOperator:t}},exports.createErrorResponse=function(e,t){return{error:e,details:t}},exports.createErrorWithContext=d,exports.createFilter=function(){return new te},exports.createMockResponse=function(e,t){return{data:e,pagination:t}},exports.createRecordBuilder=$e,exports.createTableBuilder=Me,exports.createTestClient=function(e={}){return new Et(e.apiKey||"test-api-key-12345",{environment:"local",region:"asia-south1",debug:e.debug??!0,timeout:3e4,...e})},exports.formatError=u,exports.getHttpStatusCode=l,exports.isErrorResponse=i,exports.isListResponse=a,exports.isNetworkError=function(e){return e instanceof Error&&(e.message.includes("network")||e.message.includes("fetch")||e.message.includes("timeout")||"AbortError"===e.name)},exports.mapFiltersToWhere=function(e){const t={};return e.forEach(e=>{const r={};Object.entries(X).forEach(([e,t])=>{r[t]=e});const s=r[e.operator];if(!s)throw new Error(`Unsupported API operator: ${e.operator}`);t[e.field]||(t[e.field]={});const i=t[e.field];"$between"===s&&2===e.values.length?i[s]=e.values:i[s]="$in"===s||"$notIn"===s||"$isOneOfArray"===s?e.values:"$isNull"===s||"$isNotNull"===s||"$isEmpty"===s||e.values[0]}),t},exports.mapWhereToFilters=ee,exports.normalizeFilters=Z,exports.resolveServiceURL=s;
2
+ //# sourceMappingURL=test-client-DzMli6cH.js.map