@bshsolutions/sdk 0.0.32 → 0.0.34

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.
@@ -11,6 +11,11 @@ var BshError = class extends Error {
11
11
  }
12
12
  };
13
13
 
14
+ // src/types/search/index.ts
15
+ var LogicalOperators = ["and", "or", "not"];
16
+ var ComparisonOperators = ["eq", "ne", "gt", "gte", "lt", "lte", "like", "ilike", "contains", "icontains", "starts", "istarts", "in", "nin", "between", "isnull", "notnull"];
17
+ var AggregateFunctions = ["COUNT", "SUM", "AVG", "MIN", "MAX"];
18
+
14
19
  // src/types/entities/index.ts
15
20
  var BshEntityTypes = ["Table", "View", "Function"];
16
21
  var BshUpdateStrategies = ["Replace", "Upsert"];
@@ -50,6 +55,6 @@ var formatFileSize = (file) => {
50
55
  return Math.round(file.bytes / Math.pow(1024, i) * 100) / 100 + " " + sizes[i];
51
56
  };
52
57
 
53
- export { BshEntityPermissions, BshEntityTypes, BshError, BshInsertDuplicates, BshPKStrategies, BshPKTypes, BshUpdateStrategies, PolicyActions, PrincipalType, defaultSettings, formatFileSize, isOk };
54
- //# sourceMappingURL=chunk-BAYFQNFR.js.map
55
- //# sourceMappingURL=chunk-BAYFQNFR.js.map
58
+ export { AggregateFunctions, BshEntityPermissions, BshEntityTypes, BshError, BshInsertDuplicates, BshPKStrategies, BshPKTypes, BshUpdateStrategies, ComparisonOperators, LogicalOperators, PolicyActions, PrincipalType, defaultSettings, formatFileSize, isOk };
59
+ //# sourceMappingURL=chunk-2E5HSZT4.js.map
60
+ //# sourceMappingURL=chunk-2E5HSZT4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types/response/index.ts","../src/types/search/index.ts","../src/types/entities/index.ts","../src/types/security/index.ts","../src/types/config/index.ts","../src/types/storage/index.ts"],"names":[],"mappings":";AAyBO,IAAM,IAAA,GAAO,CAAC,QAAA,KAA+C,QAAA,IAAY,MAAA,GAAY,QAAQ,QAAA,EA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AAA;AAAA,EAAQ,KAAA;AAAA,EAAO;AAAA;AAAqB;AACnE,IAAM,gBAAgB,CAAC,GAAA,EAAK,QAAQ,OAAA,EAAS,QAAA,EAAU,UAAU,QAAQ;;;ACtCzE,IAAM,eAAA,GAA+B;AAAA,EACxC,IAAA,EAAM,WAAA;AAAA,EACN,GAAA,EAAK;AAAA,IACD,QAAA,EAAU;AAAA,MACN,OAAA,EAAS;AAAA,KACb;AAAA,IACA,IAAA,EAAM;AAAA,MACF,cAAA,EAAgB;AAAA;AACpB;AAER;;;ACgBO,IAAM,cAAA,GAAiB,CAAC,IAAA,KAA2B;AACtD,EAAA,IAAI,CAAC,IAAA,EAAM,KAAA,EAAO,OAAO,SAAA;AACzB,EAAA,MAAM,KAAA,GAAQ,CAAC,OAAA,EAAS,IAAA,EAAM,MAAM,IAAI,CAAA;AACxC,EAAA,MAAM,CAAA,GAAI,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,GAAA,CAAI,IAAA,CAAK,KAAK,CAAA,GAAI,IAAA,CAAK,GAAA,CAAI,IAAI,CAAC,CAAA;AAC1D,EAAA,OAAO,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,KAAA,GAAQ,KAAK,GAAA,CAAI,IAAA,EAAM,CAAC,CAAA,GAAI,GAAG,CAAA,GAAI,GAAA,GAAM,GAAA,GAAM,MAAM,CAAC,CAAA;AACjF","file":"chunk-2E5HSZT4.js","sourcesContent":["export type BshResponse<T> = {\n data: T[]\n timestamp: number\n code: number\n status: string\n message?: string\n error?: string\n meta?: {\n type?: string,\n sql?: string,\n error?: string,\n tips?: {[key: string]: string}\n }\n pagination?: {\n current: number,\n total: number,\n pages: number,\n first: boolean,\n last: boolean\n }\n endpoint?: string,\n api?: string,\n validations?: {field: string, error: string}[]\n}\n\nexport const isOk = (response: BshResponse<unknown> | undefined) => response == undefined ? false : response?.code >= 200 && response?.code < 300\n\nexport class BshError extends Error {\n constructor(\n public status: number,\n public endpoint: string,\n public response?: BshResponse<unknown>\n ) {\n if (response) response.endpoint = endpoint\n super(JSON.stringify(response, null, 2));\n this.name = 'BshError';\n }\n}\n","type CaseInsensitive<T extends string> = T | Uppercase<T>;\n\nexport type BshSearch<T = unknown> = {\n entity?: string\n alias?: string\n fields?: keyof T | string[]\n filters?: Filter<T>[]\n groupBy?: GroupBy<T>\n sort?: Sort<T>[]\n pagination?: Pagination\n from?: BshSearch<unknown>\n}\n\nexport const LogicalOperators = [\"and\", \"or\", \"not\"] as const;\nexport type LogicalOperator = CaseInsensitive<typeof LogicalOperators[number]>;\n\nexport const ComparisonOperators = [\"eq\", \"ne\", \"gt\", \"gte\", \"lt\", \"lte\", \"like\", \"ilike\", \"contains\", \"icontains\", \"starts\", \"istarts\", \"in\", \"nin\", \"between\", \"isnull\", \"notnull\"] as const;\nexport type ComparisonOperator = CaseInsensitive<typeof ComparisonOperators[number]>;\n\nexport type Filter<T = unknown> = {\n operator?: ComparisonOperator | LogicalOperator;\n field?: string | keyof T;\n value?: unknown;\n type?: string;\n filters?: Filter<T>[];\n};\n\nexport type GroupBy<T = unknown> = {\n fields?: string[] | keyof T[]\n aggregate?: Aggregate<T>[]\n}\n\nexport const AggregateFunctions = [\"COUNT\", \"SUM\", \"AVG\", \"MIN\", \"MAX\"] as const;\nexport type AggregateFunction = CaseInsensitive<typeof AggregateFunctions[number]>;\n\nexport type Aggregate<T = unknown> = {\n function?: AggregateFunction\n field?: string | keyof T\n alias?: string\n}\n\nexport type Sort<T> = {\n field?: string | keyof T\n direction?: -1 | 1 | 0\n}\n\nexport type Pagination = {\n page?: number\n size?: number\n}\n","import { BshObject, BshObjectPure } from '@types';\n\nexport type BshEntities = {\n name: string\n dbTable: string\n dbSchema: string\n type: 'Table' | 'View' | 'Function'\n dbSource: string\n updateStrategy: 'Replace' | 'Upsert'\n insertDuplicate: 'Upsert' | 'Error'\n bshSchema?: string\n bshPlugin?: string\n auditable?: boolean\n isPluginBased?: boolean\n isMultiTenant?: boolean\n pks: {\n key: string\n strategy: 'AutoIncrement' | 'UUID' | 'Fixed'\n type: 'string' | 'number'\n }[]\n permissions?: {\n write?: boolean\n read?: boolean\n delete?: boolean\n update?: boolean\n }\n} & BshObject;\n\nexport type BshEntitiesPure = BshObjectPure<BshEntities>;\nexport type BshEntityPermissions = 'read' | 'write' | 'update' | 'delete';\nexport const BshEntityTypes = ['Table', 'View', 'Function'] as const;\nexport const BshUpdateStrategies = ['Replace', 'Upsert'] as const;\nexport const BshInsertDuplicates = ['Upsert', 'Error'] as const;\nexport const BshPKStrategies = ['AutoIncrement', 'UUID', 'Fixed'] as const;\nexport const BshPKTypes = ['string', 'number'] as const;\nexport const BshEntityPermissions = ['read', 'write', 'update', 'delete'] as const;\n\nexport type BshSchemas = {\n name: string\n label: string\n description: string\n bshPlugin: string\n properties: {\n type: string\n name: string\n label: string\n\n meta?: {\n description?: string\n\n required?: boolean\n unique?: boolean\n default?: string\n\n length?: number\n maxLength?: number\n minLength?: number\n\n pattern?: string\n }\n }[]\n} & BshObject;\n\nexport type BshSchemasPure = BshObjectPure<BshSchemas>;\nexport type BshSchemaProperty = BshSchemas['properties'][number];\n\nexport type BshTypes = {\n name: string\n label: string\n bshPlugin?: string\n baseType?: string\n schema?: string\n meta?: {\n description?: string\n pattern?: string\n maxLength?: number\n minLength?: number\n max?: number\n min?: number\n }\n} & BshObject;\n\nexport type BshTypesPure = BshObjectPure<BshTypes>;\n\n","import {BshDate, BshObject, BshObjectPure} from '@types';\n\nexport type BshUser = {\n userId: string\n tenantId: string\n email: string\n password?: string\n roles: string[]\n status: 'ACTIVATED' | 'REQUIRED_ACTIVATION' | 'DISABLED' | 'REQUIRED_RESET_PASSWORD'\n profile?: {\n firstName?: string\n lastName?: string\n phone?: string\n picture?: string\n tags?: string[]\n [k: string]: unknown\n }\n} & BshObject;\n\nexport type BshUserInit = {\n email: string\n tenantId?: string\n password?: string\n roles?: string[]\n profile: BshUser['profile']\n}\n\nexport type BshUserPure = BshObjectPure<BshUser>;\n\nexport type BshRole = {\n name: string\n public?: boolean\n admin?: boolean\n description?: string\n bshPlugin?: string;\n} & BshObject;\n\nexport type BshRolePure = BshObjectPure<BshRole>;\n\nexport type BshPolicy = {\n name: string\n description?: string\n principals: {\n type: Uppercase<'user' | 'group' | 'role' | 'apiKey' | 'any'>\n value: string[]\n }[]\n permissions: {\n entity: string[]\n actions: ('READ' | 'WRITE' | 'DELETE' | 'UPDATE' | 'SEARCH' | '*')[]\n allow: boolean\n }[]\n enabled: boolean\n priority?: number\n apiKeyId?: number\n bshPlugin?: string;\n} & BshObject;\n\nexport type BshPolicyPure = BshObjectPure<BshPolicy>;\nexport const PrincipalType = ['user', 'role', 'any', 'apiKey', /*'group'*/] as const;\nexport const PolicyActions = ['*', 'READ', 'WRITE', 'DELETE', 'UPDATE', 'SEARCH'] as const;\n\nexport type BshApiKeysScopes = {\n read: boolean\n write: boolean\n delete: boolean\n update: boolean\n}\n\nexport type BshApiKeysForm = {\n name: string\n description?: string\n duration: number\n type: 'PERSONAL' | 'MACHINE'\n scopes: string[] // Format: [\"EntityName:ACTION\", ...]\n}\n\nexport type BshApiKeys = BshApiKeysForm & {\n id: number\n apiKey: string\n startedAt: BshDate\n expiresAt?: BshDate\n status: 'ACTIVE' | 'REVOKED'\n userId?: string\n} & BshObject;\n\nexport type BshTenant = {\n tenantId: string;\n name: string;\n status: 'Active' | 'Inactive' | 'Blocked';\n description?: string;\n domain?: string;\n email?: string;\n adminId?: string;\n settings?: Record<string, unknown>;\n} & BshObject;\n\nexport type BshTenantPure = BshObjectPure<BshTenant>;\n","import {BshObject} from \"@types\";\n\nexport type BshConfigurations<T extends Record<string, unknown> = Record<string, unknown>> = {\n name: string;\n description: string;\n bshPlugin?: string;\n config?: T;\n} & BshObject\n\nexport type BshSettings = {\n name: string;\n api: {\n response?: {\n showSql?: boolean;\n };\n auth?: {\n enableRegister?: boolean;\n };\n };\n}\n\nexport const defaultSettings: BshSettings = {\n name: 'BshEngine',\n api: {\n response: {\n showSql: true\n },\n auth: {\n enableRegister: false\n }\n }\n}\n\n","import { BshObject, BshConfigurations } from '@types';\n\nexport type StorageProvider = 'cloudinary';\n\nexport type CloudinaryConfig = {\n url: string;\n folder?: string;\n}\n\nexport type StorageConfiguration = BshConfigurations & {\n enabled?: StorageProvider;\n cloudinary: CloudinaryConfig\n}\n\nexport type BshFiles = {\n storageId: string;\n id: string;\n filename: string;\n mediaType: string;\n uri: string;\n secureUri: string;\n bytes: number;\n format: string;\n folder: string;\n width: number;\n height: number;\n tags: string[];\n context: { [key: string]: unknown };\n fileId: string;\n} & BshObject\n\nexport type UploadOptions = {\n tags: string[]\n context: { [key: string]: unknown }\n [key: string]: unknown;\n}\n\nexport type UploadResponse = {\n fileId: string\n publicId: string\n assetId: string\n uri: string\n secureUri: string\n tags: string[]\n context: { [key: string]: unknown }\n}\n\nexport const formatFileSize = (file: BshFiles): string => {\n if (!file?.bytes) return 'Unknown';\n const sizes = ['Bytes', 'KB', 'MB', 'GB'];\n const i = Math.floor(Math.log(file.bytes) / Math.log(1024));\n return Math.round(file.bytes / Math.pow(1024, i) * 100) / 100 + ' ' + sizes[i];\n};\n\n"]}
@@ -1,4 +1,4 @@
1
- import { BshError } from './chunk-BAYFQNFR.js';
1
+ import { BshError } from './chunk-2E5HSZT4.js';
2
2
 
3
3
  // src/client/types.ts
4
4
  var defaultClientFn = async (params) => {
@@ -249,5 +249,5 @@ var fetchClientFn = async (params) => {
249
249
  };
250
250
 
251
251
  export { BshClient, defaultClientFn, fetchClientFn };
252
- //# sourceMappingURL=chunk-ZVXIIW4X.js.map
253
- //# sourceMappingURL=chunk-ZVXIIW4X.js.map
252
+ //# sourceMappingURL=chunk-WER47MVE.js.map
253
+ //# sourceMappingURL=chunk-WER47MVE.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/client/types.ts","../src/client/bsh-client.ts","../src/client/index.ts"],"names":["error"],"mappings":";;;AAqBO,IAAM,eAAA,GAA+B,OAAO,MAAA,KAAW;AAC1D,EAAA,OAAO,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AA,GAAmB,MAAA,CAAO,OAAA,CAAQ,OAC7C,IAAA,CAAK,SAAA,CAAU,MAAA,CAAO,OAAA,CAAQ,IAAI,CAAA,GAAI,MAAA;AAAA,MAC9C,OAAA,EAAS,OAAO,OAAA,CAAQ;AAAA;AAC5B,GACJ;AACJ","file":"chunk-ZVXIIW4X.js","sourcesContent":["import { BshCallbackParams } from \"@src/services\";\nimport { BshError, BshResponse, BshSearch } from \"@types\";\n\nexport type BshClientFnParams<T = unknown, R = T> = {\n path: string,\n options: {\n method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH',\n responseType?: 'json' | 'blob' | 'text' | 'arrayBuffer',\n requestFormat?: 'json' | 'text' | 'form',\n body?: T | BshSearch<T> | unknown,\n formData?: FormData,\n queryParams?: Record<string, string>,\n headers?: Record<string, string>,\n },\n bshOptions: BshCallbackParams<T, R>,\n api?: string,\n entity?: string\n}\n\nexport type BshClientFn = <T = unknown>(params: BshClientFnParams<T>) => Promise<Response>;\n\nexport const defaultClientFn: BshClientFn = async (params) => {\n return fetch(\n params.path,\n {\n method: params.options.method,\n body: params.options.requestFormat === 'form' ?\n params.options.body as BodyInit : params.options.body ?\n JSON.stringify(params.options.body) : undefined,\n headers: params.options.headers,\n }\n );\n};\n\nexport type AuthToken = {\n type: 'JWT' | 'APIKEY';\n token: string\n}\n\nexport type BshAuthFn = () => Promise<AuthToken | undefined | null>;\n\nexport type BshRefreshTokenFn = () => Promise<string | undefined | null>;\n\nexport type BshTenantFn = () => Promise<string | undefined | null>;\n\nexport type BshPostInterceptor<T = any> = (response: BshResponse<T>, params?: BshClientFnParams<T>) => Promise<BshResponse<T>>;\nexport type BshPreInterceptor<T = any, R = T> = (params: BshClientFnParams<T, R>) => Promise<BshClientFnParams<T, R>>;\nexport type BshErrorInterceptor<T = any> = (error: BshError, response?: BshResponse<T>, params?: BshClientFnParams<T>) => Promise<BshError | undefined>;\n","import { BshResponse, BshError } from \"@types\";\nimport { AuthToken, BshAuthFn, BshClientFn, BshClientFnParams, BshRefreshTokenFn, BshTenantFn, defaultClientFn } from \"@src/client/types\";\nimport { BshEngine } from \"@src/bshengine\";\n\nexport class BshClient {\n private readonly httpClient: BshClientFn;\n private readonly authFn?: BshAuthFn;\n private readonly refreshTokenFn?: BshRefreshTokenFn;\n private readonly tenantFn?: BshTenantFn;\n private readonly host: string;\n private readonly bshEngine?: BshEngine;\n\n constructor(\n host?: string,\n httpClient?: BshClientFn,\n authFn?: BshAuthFn,\n refreshTokenFn?: BshRefreshTokenFn,\n tenantFn?: BshTenantFn,\n bshEngine?: BshEngine\n ) {\n this.host = host || '';\n this.httpClient = httpClient || defaultClientFn;\n this.authFn = authFn;\n this.refreshTokenFn = refreshTokenFn;\n this.tenantFn = tenantFn;\n this.bshEngine = bshEngine;\n }\n\n private async handleResponse<T = any>(response: Response, params: BshClientFnParams<T>, type: 'json'): Promise<BshResponse<T> | undefined>\n private async handleResponse<T = any>(response: Response, params: BshClientFnParams<T>, type: 'blob'): Promise<Blob | undefined>\n private async handleResponse<T = any>(response: Response, params: BshClientFnParams<T>, type: 'json' | 'blob'): Promise<BshResponse<T> | Blob | undefined> {\n if (!response.ok) {\n let data: any = undefined;\n try {\n data = await response.json();\n } catch (error) {\n try {\n data = await response.text();\n } catch (error) {\n data = {\n message: 'Connection Issue'\n };\n }\n }\n let error = new BshError(response.status, params.path, data);\n const byPassErrorInterceptor = params.bshOptions.byPass?.interceptors?.error;\n if ((byPassErrorInterceptor == undefined || !byPassErrorInterceptor) && this.bshEngine?.getErrorInterceptors().length) {\n for (const interceptor of this.bshEngine.getErrorInterceptors()) {\n const newError = await interceptor(error, error.response, params as BshClientFnParams<any>);\n if (newError) error = newError;\n }\n }\n if (params.bshOptions.onError) {\n params.bshOptions.onError(error);\n return undefined;\n }\n else throw error;\n }\n\n if (type === 'json') {\n const data = await response.json();\n let result = data as BshResponse<T>;\n result.api = params.api;\n const byPassPostInterceptors = params.bshOptions.byPass?.interceptors?.post;\n if ((byPassPostInterceptors == undefined || !byPassPostInterceptors) && this.bshEngine?.getPostInterceptors().length) {\n for (const interceptor of this.bshEngine.getPostInterceptors()) {\n const newResult = await interceptor(result, params as BshClientFnParams<any>);\n if (newResult) result = newResult as BshResponse<T>;\n }\n }\n if (params.bshOptions.onSuccess) {\n params.bshOptions.onSuccess(data);\n return undefined;\n }\n return result;\n }\n else if (type === 'blob') {\n const blob = await response.blob();\n if (params.bshOptions.onDownload) {\n params.bshOptions.onDownload(blob);\n return undefined;\n }\n else return blob;\n }\n }\n\n private async refreshTokenIfNeeded(\n auth: AuthToken,\n refreshTokenFn?: BshRefreshTokenFn\n ): Promise<AuthToken | undefined | null> {\n if (!refreshTokenFn || !auth || auth.type !== 'JWT') return auth;\n const accessToken = auth.token;\n try {\n const tokenPayload = JSON.parse(atob(accessToken.split('.')[1] || ''));\n const exp = tokenPayload.exp * 1000;\n const now = new Date().getTime();\n\n if (exp && now < exp) return auth;\n\n const refreshToken = await refreshTokenFn();\n if (!refreshToken || !this.bshEngine) return auth;\n\n const response = await this.bshEngine.auth.refreshToken({\n payload: { refresh: refreshToken },\n onError: () => { }\n });\n\n if (response) return {\n type: 'JWT',\n token: response.data[0].access\n };\n\n return auth;\n } catch (error) {\n return auth;\n }\n }\n\n private async getAuthHeaders(params: BshClientFnParams<any>): Promise<Record<string, string>> {\n if (params.path.includes('/api/auth/')) return {};\n\n let auth = this.authFn ? await this.authFn() : undefined;\n if (auth) auth = await this.refreshTokenIfNeeded(auth, this.refreshTokenFn);\n\n let authHeaders = {};\n if (auth) {\n if (auth.type === 'JWT') authHeaders = { Authorization: `Bearer ${auth.token}` };\n else if (auth.type === 'APIKEY') authHeaders = { 'X-BSH-APIKEY': auth.token };\n }\n return { ...authHeaders };\n }\n\n private async getTenantHeaders(params: BshClientFnParams<any>): Promise<Record<string, string>> {\n const tenant = await this.tenantFn?.();\n if (!tenant) return {};\n return { 'X-Tenant-Id': tenant };\n }\n\n private async injectHeaders(params: BshClientFnParams<any>): Promise<Record<string, string>> {\n const authHeaders = await this.getAuthHeaders(params);\n const tenantHeaders = await this.getTenantHeaders(params);\n return { ...authHeaders, ...tenantHeaders };\n }\n\n private async applyPreInterceptors<T = unknown, R = T>(params: BshClientFnParams<T, R>): Promise<BshClientFnParams<T, R>> {\n const byPassPreInterceptors = params.bshOptions.byPass?.interceptors?.pre;\n if (byPassPreInterceptors == true || !this.bshEngine?.getPreInterceptors().length) return params;\n for (const interceptor of this.bshEngine.getPreInterceptors()) {\n const newParams = await interceptor(params as BshClientFnParams<unknown, unknown>);\n if (newParams) return newParams as BshClientFnParams<T, R>;\n }\n return params;\n }\n\n async get<T = unknown>(params: BshClientFnParams<T>): Promise<BshResponse<T> | undefined> {\n const authHeaders = await this.injectHeaders(params);\n\n let clientParams = {\n ...params,\n path: `${this.host}${params.path}`,\n options: {\n ...params.options,\n method: 'GET',\n headers: {\n ...params.options.headers,\n ...authHeaders\n }\n }\n } as BshClientFnParams<T>;\n\n clientParams = await this.applyPreInterceptors<T>(clientParams);\n const response = await this.httpClient(clientParams);\n return this.handleResponse(response, clientParams, 'json');\n }\n\n async post<T = unknown, R = T>(params: BshClientFnParams<T, R>): Promise<BshResponse<R> | undefined> {\n const authHeaders = await this.injectHeaders(params);\n\n let clientParams = {\n ...params,\n path: `${this.host}${params.path}`,\n options: {\n ...params.options,\n method: 'POST',\n headers: {\n ...params.options.headers,\n ...authHeaders\n }\n }\n } as BshClientFnParams<T, R>;\n\n clientParams = await this.applyPreInterceptors<T, R>(clientParams);\n const response = await this.httpClient(clientParams);\n return this.handleResponse(response, clientParams, 'json');\n }\n\n async put<T = unknown, R = T>(params: BshClientFnParams<T, R>): Promise<BshResponse<R> | undefined> {\n const authHeaders = await this.injectHeaders(params);\n let clientParams = {\n ...params,\n path: `${this.host}${params.path}`,\n options: {\n ...params.options,\n method: 'PUT',\n headers: {\n ...params.options.headers,\n ...authHeaders\n }\n }\n } as BshClientFnParams<T, R>;\n\n clientParams = await this.applyPreInterceptors<T, R>(clientParams);\n const response = await this.httpClient(clientParams);\n return this.handleResponse(response, clientParams, 'json');\n }\n\n async delete<T = unknown>(params: BshClientFnParams<T>): Promise<BshResponse<T> | undefined> {\n const authHeaders = await this.injectHeaders(params);\n let clientParams = {\n ...params,\n path: `${this.host}${params.path}`,\n options: {\n ...params.options,\n method: 'DELETE',\n headers: {\n ...params.options.headers,\n ...authHeaders\n }\n }\n } as BshClientFnParams<T>;\n\n clientParams = await this.applyPreInterceptors<T>(clientParams);\n const response = await this.httpClient(clientParams);\n return this.handleResponse(response, clientParams, 'json');\n }\n\n async patch<T = unknown>(params: BshClientFnParams<T>): Promise<BshResponse<T> | undefined> {\n const authHeaders = await this.injectHeaders(params);\n let clientParams = {\n ...params,\n path: `${this.host}${params.path}`,\n options: {\n ...params.options,\n method: 'PATCH',\n headers: {\n ...params.options.headers,\n ...authHeaders\n }\n }\n } as BshClientFnParams<T>;\n\n clientParams = await this.applyPreInterceptors<T>(clientParams);\n const response = await this.httpClient(clientParams);\n return this.handleResponse(response, clientParams, 'json');\n }\n\n async download<T = unknown>(params: BshClientFnParams<T>): Promise<Blob | undefined> {\n const authHeaders = await this.injectHeaders(params);\n let clientParams = {\n ...params,\n path: `${this.host}${params.path}`,\n options: {\n ...params.options,\n headers: {\n ...params.options.headers,\n ...authHeaders\n }\n }\n } as BshClientFnParams<T>;\n\n clientParams = await this.applyPreInterceptors<T>(clientParams);\n const response = await this.httpClient(clientParams);\n return this.handleResponse(response, clientParams, 'blob');\n }\n}\n","import { BshClientFn } from './types';\n\nexport * from './types';\nexport * from './bsh-client';\n\nexport const fetchClientFn: BshClientFn = async (params) => {\n return fetch(\n params.path,\n {\n method: params.options.method,\n body: params.options.requestFormat === 'form' ?\n params.options.body as BodyInit : params.options.body ?\n JSON.stringify(params.options.body) : undefined,\n headers: params.options.headers,\n }\n );\n};\n"]}
1
+ {"version":3,"sources":["../src/client/types.ts","../src/client/bsh-client.ts","../src/client/index.ts"],"names":["error"],"mappings":";;;AAqBO,I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,CAAQ,aAAA,KAAkB,MAAA,GACnC,OAAO,OAAA,CAAQ,IAAA,GAAmB,MAAA,CAAO,OAAA,CAAQ,OAC7C,IAAA,CAAK,SAAA,CAAU,MAAA,CAAO,OAAA,CAAQ,IAAI,CAAA,GAAI,MAAA;AAAA,MAC9C,OAAA,EAAS,OAAO,OAAA,CAAQ;AAAA;AAC5B,GACJ;AACJ","file":"chunk-WER47MVE.js","sourcesContent":["import { BshCallbackParams } from \"@src/services\";\nimport { BshError, BshResponse, BshSearch } from \"@types\";\n\nexport type BshClientFnParams<T = unknown, R = T> = {\n path: string,\n options: {\n method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH',\n responseType?: 'json' | 'blob' | 'text' | 'arrayBuffer',\n requestFormat?: 'json' | 'text' | 'form',\n body?: T | BshSearch<T> | unknown,\n formData?: FormData,\n queryParams?: Record<string, string>,\n headers?: Record<string, string>,\n },\n bshOptions: BshCallbackParams<T, R>,\n api?: string,\n entity?: string\n}\n\nexport type BshClientFn = <T = unknown>(params: BshClientFnParams<T>) => Promise<Response>;\n\nexport const defaultClientFn: BshClientFn = async (params) => {\n return fetch(\n params.path,\n {\n method: params.options.method,\n body: params.options.requestFormat === 'form' ?\n params.options.body as BodyInit : params.options.body ?\n JSON.stringify(params.options.body) : undefined,\n headers: params.options.headers,\n }\n );\n};\n\nexport type AuthToken = {\n type: 'JWT' | 'APIKEY';\n token: string\n}\n\nexport type BshAuthFn = () => Promise<AuthToken | undefined | null>;\n\nexport type BshRefreshTokenFn = () => Promise<string | undefined | null>;\n\nexport type BshTenantFn = () => Promise<string | undefined | null>;\n\nexport type BshPostInterceptor<T = any> = (response: BshResponse<T>, params?: BshClientFnParams<T>) => Promise<BshResponse<T>>;\nexport type BshPreInterceptor<T = any, R = T> = (params: BshClientFnParams<T, R>) => Promise<BshClientFnParams<T, R>>;\nexport type BshErrorInterceptor<T = any> = (error: BshError, response?: BshResponse<T>, params?: BshClientFnParams<T>) => Promise<BshError | undefined>;\n","import { BshResponse, BshError } from \"@types\";\nimport { AuthToken, BshAuthFn, BshClientFn, BshClientFnParams, BshRefreshTokenFn, BshTenantFn, defaultClientFn } from \"@src/client/types\";\nimport { BshEngine } from \"@src/bshengine\";\n\nexport class BshClient {\n private readonly httpClient: BshClientFn;\n private readonly authFn?: BshAuthFn;\n private readonly refreshTokenFn?: BshRefreshTokenFn;\n private readonly tenantFn?: BshTenantFn;\n private readonly host: string;\n private readonly bshEngine?: BshEngine;\n\n constructor(\n host?: string,\n httpClient?: BshClientFn,\n authFn?: BshAuthFn,\n refreshTokenFn?: BshRefreshTokenFn,\n tenantFn?: BshTenantFn,\n bshEngine?: BshEngine\n ) {\n this.host = host || '';\n this.httpClient = httpClient || defaultClientFn;\n this.authFn = authFn;\n this.refreshTokenFn = refreshTokenFn;\n this.tenantFn = tenantFn;\n this.bshEngine = bshEngine;\n }\n\n private async handleResponse<T = any>(response: Response, params: BshClientFnParams<T>, type: 'json'): Promise<BshResponse<T> | undefined>\n private async handleResponse<T = any>(response: Response, params: BshClientFnParams<T>, type: 'blob'): Promise<Blob | undefined>\n private async handleResponse<T = any>(response: Response, params: BshClientFnParams<T>, type: 'json' | 'blob'): Promise<BshResponse<T> | Blob | undefined> {\n if (!response.ok) {\n let data: any = undefined;\n try {\n data = await response.json();\n } catch (error) {\n try {\n data = await response.text();\n } catch (error) {\n data = {\n message: 'Connection Issue'\n };\n }\n }\n let error = new BshError(response.status, params.path, data);\n const byPassErrorInterceptor = params.bshOptions.byPass?.interceptors?.error;\n if ((byPassErrorInterceptor == undefined || !byPassErrorInterceptor) && this.bshEngine?.getErrorInterceptors().length) {\n for (const interceptor of this.bshEngine.getErrorInterceptors()) {\n const newError = await interceptor(error, error.response, params as BshClientFnParams<any>);\n if (newError) error = newError;\n }\n }\n if (params.bshOptions.onError) {\n params.bshOptions.onError(error);\n return undefined;\n }\n else throw error;\n }\n\n if (type === 'json') {\n const data = await response.json();\n let result = data as BshResponse<T>;\n result.api = params.api;\n const byPassPostInterceptors = params.bshOptions.byPass?.interceptors?.post;\n if ((byPassPostInterceptors == undefined || !byPassPostInterceptors) && this.bshEngine?.getPostInterceptors().length) {\n for (const interceptor of this.bshEngine.getPostInterceptors()) {\n const newResult = await interceptor(result, params as BshClientFnParams<any>);\n if (newResult) result = newResult as BshResponse<T>;\n }\n }\n if (params.bshOptions.onSuccess) {\n params.bshOptions.onSuccess(data);\n return undefined;\n }\n return result;\n }\n else if (type === 'blob') {\n const blob = await response.blob();\n if (params.bshOptions.onDownload) {\n params.bshOptions.onDownload(blob);\n return undefined;\n }\n else return blob;\n }\n }\n\n private async refreshTokenIfNeeded(\n auth: AuthToken,\n refreshTokenFn?: BshRefreshTokenFn\n ): Promise<AuthToken | undefined | null> {\n if (!refreshTokenFn || !auth || auth.type !== 'JWT') return auth;\n const accessToken = auth.token;\n try {\n const tokenPayload = JSON.parse(atob(accessToken.split('.')[1] || ''));\n const exp = tokenPayload.exp * 1000;\n const now = new Date().getTime();\n\n if (exp && now < exp) return auth;\n\n const refreshToken = await refreshTokenFn();\n if (!refreshToken || !this.bshEngine) return auth;\n\n const response = await this.bshEngine.auth.refreshToken({\n payload: { refresh: refreshToken },\n onError: () => { }\n });\n\n if (response) return {\n type: 'JWT',\n token: response.data[0].access\n };\n\n return auth;\n } catch (error) {\n return auth;\n }\n }\n\n private async getAuthHeaders(params: BshClientFnParams<any>): Promise<Record<string, string>> {\n if (params.path.includes('/api/auth/')) return {};\n\n let auth = this.authFn ? await this.authFn() : undefined;\n if (auth) auth = await this.refreshTokenIfNeeded(auth, this.refreshTokenFn);\n\n let authHeaders = {};\n if (auth) {\n if (auth.type === 'JWT') authHeaders = { Authorization: `Bearer ${auth.token}` };\n else if (auth.type === 'APIKEY') authHeaders = { 'X-BSH-APIKEY': auth.token };\n }\n return { ...authHeaders };\n }\n\n private async getTenantHeaders(params: BshClientFnParams<any>): Promise<Record<string, string>> {\n const tenant = await this.tenantFn?.();\n if (!tenant) return {};\n return { 'X-Tenant-Id': tenant };\n }\n\n private async injectHeaders(params: BshClientFnParams<any>): Promise<Record<string, string>> {\n const authHeaders = await this.getAuthHeaders(params);\n const tenantHeaders = await this.getTenantHeaders(params);\n return { ...authHeaders, ...tenantHeaders };\n }\n\n private async applyPreInterceptors<T = unknown, R = T>(params: BshClientFnParams<T, R>): Promise<BshClientFnParams<T, R>> {\n const byPassPreInterceptors = params.bshOptions.byPass?.interceptors?.pre;\n if (byPassPreInterceptors == true || !this.bshEngine?.getPreInterceptors().length) return params;\n for (const interceptor of this.bshEngine.getPreInterceptors()) {\n const newParams = await interceptor(params as BshClientFnParams<unknown, unknown>);\n if (newParams) return newParams as BshClientFnParams<T, R>;\n }\n return params;\n }\n\n async get<T = unknown>(params: BshClientFnParams<T>): Promise<BshResponse<T> | undefined> {\n const authHeaders = await this.injectHeaders(params);\n\n let clientParams = {\n ...params,\n path: `${this.host}${params.path}`,\n options: {\n ...params.options,\n method: 'GET',\n headers: {\n ...params.options.headers,\n ...authHeaders\n }\n }\n } as BshClientFnParams<T>;\n\n clientParams = await this.applyPreInterceptors<T>(clientParams);\n const response = await this.httpClient(clientParams);\n return this.handleResponse(response, clientParams, 'json');\n }\n\n async post<T = unknown, R = T>(params: BshClientFnParams<T, R>): Promise<BshResponse<R> | undefined> {\n const authHeaders = await this.injectHeaders(params);\n\n let clientParams = {\n ...params,\n path: `${this.host}${params.path}`,\n options: {\n ...params.options,\n method: 'POST',\n headers: {\n ...params.options.headers,\n ...authHeaders\n }\n }\n } as BshClientFnParams<T, R>;\n\n clientParams = await this.applyPreInterceptors<T, R>(clientParams);\n const response = await this.httpClient(clientParams);\n return this.handleResponse(response, clientParams, 'json');\n }\n\n async put<T = unknown, R = T>(params: BshClientFnParams<T, R>): Promise<BshResponse<R> | undefined> {\n const authHeaders = await this.injectHeaders(params);\n let clientParams = {\n ...params,\n path: `${this.host}${params.path}`,\n options: {\n ...params.options,\n method: 'PUT',\n headers: {\n ...params.options.headers,\n ...authHeaders\n }\n }\n } as BshClientFnParams<T, R>;\n\n clientParams = await this.applyPreInterceptors<T, R>(clientParams);\n const response = await this.httpClient(clientParams);\n return this.handleResponse(response, clientParams, 'json');\n }\n\n async delete<T = unknown>(params: BshClientFnParams<T>): Promise<BshResponse<T> | undefined> {\n const authHeaders = await this.injectHeaders(params);\n let clientParams = {\n ...params,\n path: `${this.host}${params.path}`,\n options: {\n ...params.options,\n method: 'DELETE',\n headers: {\n ...params.options.headers,\n ...authHeaders\n }\n }\n } as BshClientFnParams<T>;\n\n clientParams = await this.applyPreInterceptors<T>(clientParams);\n const response = await this.httpClient(clientParams);\n return this.handleResponse(response, clientParams, 'json');\n }\n\n async patch<T = unknown>(params: BshClientFnParams<T>): Promise<BshResponse<T> | undefined> {\n const authHeaders = await this.injectHeaders(params);\n let clientParams = {\n ...params,\n path: `${this.host}${params.path}`,\n options: {\n ...params.options,\n method: 'PATCH',\n headers: {\n ...params.options.headers,\n ...authHeaders\n }\n }\n } as BshClientFnParams<T>;\n\n clientParams = await this.applyPreInterceptors<T>(clientParams);\n const response = await this.httpClient(clientParams);\n return this.handleResponse(response, clientParams, 'json');\n }\n\n async download<T = unknown>(params: BshClientFnParams<T>): Promise<Blob | undefined> {\n const authHeaders = await this.injectHeaders(params);\n let clientParams = {\n ...params,\n path: `${this.host}${params.path}`,\n options: {\n ...params.options,\n headers: {\n ...params.options.headers,\n ...authHeaders\n }\n }\n } as BshClientFnParams<T>;\n\n clientParams = await this.applyPreInterceptors<T>(clientParams);\n const response = await this.httpClient(clientParams);\n return this.handleResponse(response, clientParams, 'blob');\n }\n}\n","import { BshClientFn } from './types';\n\nexport * from './types';\nexport * from './bsh-client';\n\nexport const fetchClientFn: BshClientFn = async (params) => {\n return fetch(\n params.path,\n {\n method: params.options.method,\n body: params.options.requestFormat === 'form' ?\n params.options.body as BodyInit : params.options.body ?\n JSON.stringify(params.options.body) : undefined,\n headers: params.options.headers,\n }\n );\n};\n"]}
@@ -1,5 +1,5 @@
1
- import { B as BshClientFn } from '../types-ogSt75xm.js';
2
- export { A as AuthToken, a as BshAuthFn, j as BshClient, c as BshClientFnParams, i as BshErrorInterceptor, g as BshPostInterceptor, h as BshPreInterceptor, e as BshRefreshTokenFn, f as BshTenantFn, d as defaultClientFn } from '../types-ogSt75xm.js';
1
+ import { a as BshClientFn } from '../types-B0_3Fol9.js';
2
+ export { A as AuthToken, B as BshAuthFn, c as BshClient, d as BshClientFnParams, e as BshErrorInterceptor, f as BshPostInterceptor, g as BshPreInterceptor, h as BshRefreshTokenFn, i as BshTenantFn, j as defaultClientFn } from '../types-B0_3Fol9.js';
3
3
  import '../types/index.js';
4
4
 
5
5
  declare const fetchClientFn: BshClientFn;
@@ -1,5 +1,5 @@
1
- export { BshClient, defaultClientFn, fetchClientFn } from '../chunk-ZVXIIW4X.js';
2
- import '../chunk-BAYFQNFR.js';
1
+ export { BshClient, defaultClientFn, fetchClientFn } from '../chunk-WER47MVE.js';
2
+ import '../chunk-2E5HSZT4.js';
3
3
  import '../chunk-ZOCNJXUZ.js';
4
4
  //# sourceMappingURL=index.js.map
5
5
  //# sourceMappingURL=index.js.map
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { a as BshAuthFn, B as BshClientFn, b as BshEngine } from './types-ogSt75xm.js';
1
+ export { B as BshAuthFn, a as BshClientFn, b as BshEngine } from './types-B0_3Fol9.js';
2
2
  export { BshResponse } from './types/index.js';
3
3
 
4
4
  declare const version: "0.0.1";
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { fetchClientFn, BshClient } from './chunk-ZVXIIW4X.js';
1
+ import { fetchClientFn, BshClient } from './chunk-WER47MVE.js';
2
2
  import { EntityService, AuthService, UserService, TenantService, SettingsService, ImageService, MailingService, BshUtilsService, CachingService, ApiKeyService } from './chunk-E75ULHMO.js';
3
- import './chunk-BAYFQNFR.js';
3
+ import './chunk-2E5HSZT4.js';
4
4
  import { CoreEntities } from './chunk-ZOCNJXUZ.js';
5
5
 
6
6
  // src/services/plugins/index.ts
@@ -1,2 +1,2 @@
1
1
  import '../types/index.js';
2
- export { r as AdminUserService, u as ApiKeyService, q as AuthService, k as BshCallbackParams, l as BshCallbackParamsWithPayload, m as BshSearchCallbackParams, s as BshUtilsService, C as CacheRemoveResponse, t as CachingService, E as EntityFnParams, n as EntityFnParamsWithPayload, o as EntitySearchFnParams, p as EntityService, I as ImageService, M as MailingService, S as SettingsService, T as TenantService, U as UserService } from '../types-ogSt75xm.js';
2
+ export { k as AdminUserService, l as ApiKeyService, m as AuthService, n as BshCallbackParams, o as BshCallbackParamsWithPayload, p as BshSearchCallbackParams, q as BshUtilsService, C as CacheRemoveResponse, r as CachingService, E as EntityFnParams, s as EntityFnParamsWithPayload, t as EntitySearchFnParams, u as EntityService, I as ImageService, M as MailingService, S as SettingsService, T as TenantService, U as UserService } from '../types-B0_3Fol9.js';
@@ -79,8 +79,10 @@ type BshSearch<T = unknown> = {
79
79
  pagination?: Pagination;
80
80
  from?: BshSearch<unknown>;
81
81
  };
82
- type LogicalOperator = CaseInsensitive<"and" | "or">;
83
- type ComparisonOperator = CaseInsensitive<"eq" | "ne" | "gt" | "gte" | "lt" | "lte" | "like" | "ilike" | "contains" | "icontains" | "starts" | "istarts" | "in" | "nin" | "between" | "isnull" | "notnull">;
82
+ declare const LogicalOperators: readonly ["and", "or", "not"];
83
+ type LogicalOperator = CaseInsensitive<typeof LogicalOperators[number]>;
84
+ declare const ComparisonOperators: readonly ["eq", "ne", "gt", "gte", "lt", "lte", "like", "ilike", "contains", "icontains", "starts", "istarts", "in", "nin", "between", "isnull", "notnull"];
85
+ type ComparisonOperator = CaseInsensitive<typeof ComparisonOperators[number]>;
84
86
  type Filter<T = unknown> = {
85
87
  operator?: ComparisonOperator | LogicalOperator;
86
88
  field?: string | keyof T;
@@ -92,7 +94,8 @@ type GroupBy<T = unknown> = {
92
94
  fields?: string[] | keyof T[];
93
95
  aggregate?: Aggregate<T>[];
94
96
  };
95
- type AggregateFunction = "COUNT" | "SUM" | "AVG" | "MIN" | "MAX";
97
+ declare const AggregateFunctions: readonly ["COUNT", "SUM", "AVG", "MIN", "MAX"];
98
+ type AggregateFunction = CaseInsensitive<typeof AggregateFunctions[number]>;
96
99
  type Aggregate<T = unknown> = {
97
100
  function?: AggregateFunction;
98
101
  field?: string | keyof T;
@@ -284,6 +287,10 @@ type BshTrigger<Event = BshTriggerEvent> = {
284
287
  criteria?: string;
285
288
  entity: string;
286
289
  action: ('READ' | 'INSERT' | 'UPDATE' | 'SEARCH' | 'DELETE' | 'COLUMNS' | 'EXPORT')[];
290
+ lookups: {
291
+ key: string;
292
+ search: BshSearch;
293
+ }[];
287
294
  events: Event[];
288
295
  enabled: boolean;
289
296
  bshPlugin?: string;
@@ -637,4 +644,4 @@ type AuthTokens = {
637
644
  refresh: string;
638
645
  };
639
646
 
640
- export { type AdminDetails, type AdminServiceStatus, type Aggregate, type AggregateFunction, type AllServiceStatuses, type AuthTokens, type BshApiKeys, type BshApiKeysForm, type BshApiKeysScopes, type BshConfigurations, type BshDate, type BshEmailTemplate, type BshEmailTemplatePure, type BshEntities, type BshEntitiesPure, BshEntityPermissions, BshEntityTypes, BshError, type BshEventLogs, type BshFiles, BshInsertDuplicates, type BshObject, type BshObjectPure, BshPKStrategies, BshPKTypes, type BshPlugin, type BshPluginHistory, type BshPluginPure, type BshPolicy, type BshPolicyPure, type BshResponse, type BshRole, type BshRolePure, type BshSchemaProperty, type BshSchemas, type BshSchemasPure, type BshSearch, type BshSettings, type BshTenant, type BshTenantPure, type BshTrigger, type BshTriggerAction, type BshTriggerEvent, type BshTriggerEventPure, type BshTriggerFunction, type BshTriggerInstance, type BshTriggerPure, type BshTriggerSanitizer, type BshTypes, type BshTypesPure, BshUpdateStrategies, type BshUser, type BshUserInit, type BshUserPure, type CacheInfo, type CachesDetails, type CachesServiceStatus, type CloudinaryConfig, type ComparisonOperator, type ConfigurationDetails, type ConfigurationServiceStatus, CoreEntities, type CorePluginDetails, type CorePluginServiceStatus, type DatabaseDetails, type DatabaseServiceStatus, type EmailConfiguration, type EmailProvider, type EngineStatus, type EngineStatusType, type Filter, type GmailConfig, type GroupBy, type HealthCheckData, type LogicalOperator, type LoginParams, type MailDevConfig, type MailingPayload, type MailingServiceStatus, type Pagination, PluginBasedEntities, type PluginInstalledResponse, PolicyActions, PrincipalType, type ProviderDetails, type SecretSource, type SecretsDetails, type SecretsServiceStatus, type SentEmail, type ServiceStatus, type ServiceStatusType, type Sort, type StorageConfiguration, type StorageProvider, type StorageServiceStatus, type UploadOptions, type UploadResponse, defaultSettings, formatFileSize, isOk };
647
+ export { type AdminDetails, type AdminServiceStatus, type Aggregate, type AggregateFunction, AggregateFunctions, type AllServiceStatuses, type AuthTokens, type BshApiKeys, type BshApiKeysForm, type BshApiKeysScopes, type BshConfigurations, type BshDate, type BshEmailTemplate, type BshEmailTemplatePure, type BshEntities, type BshEntitiesPure, BshEntityPermissions, BshEntityTypes, BshError, type BshEventLogs, type BshFiles, BshInsertDuplicates, type BshObject, type BshObjectPure, BshPKStrategies, BshPKTypes, type BshPlugin, type BshPluginHistory, type BshPluginPure, type BshPolicy, type BshPolicyPure, type BshResponse, type BshRole, type BshRolePure, type BshSchemaProperty, type BshSchemas, type BshSchemasPure, type BshSearch, type BshSettings, type BshTenant, type BshTenantPure, type BshTrigger, type BshTriggerAction, type BshTriggerEvent, type BshTriggerEventPure, type BshTriggerFunction, type BshTriggerInstance, type BshTriggerPure, type BshTriggerSanitizer, type BshTypes, type BshTypesPure, BshUpdateStrategies, type BshUser, type BshUserInit, type BshUserPure, type CacheInfo, type CachesDetails, type CachesServiceStatus, type CloudinaryConfig, type ComparisonOperator, ComparisonOperators, type ConfigurationDetails, type ConfigurationServiceStatus, CoreEntities, type CorePluginDetails, type CorePluginServiceStatus, type DatabaseDetails, type DatabaseServiceStatus, type EmailConfiguration, type EmailProvider, type EngineStatus, type EngineStatusType, type Filter, type GmailConfig, type GroupBy, type HealthCheckData, type LogicalOperator, LogicalOperators, type LoginParams, type MailDevConfig, type MailingPayload, type MailingServiceStatus, type Pagination, PluginBasedEntities, type PluginInstalledResponse, PolicyActions, PrincipalType, type ProviderDetails, type SecretSource, type SecretsDetails, type SecretsServiceStatus, type SentEmail, type ServiceStatus, type ServiceStatusType, type Sort, type StorageConfiguration, type StorageProvider, type StorageServiceStatus, type UploadOptions, type UploadResponse, defaultSettings, formatFileSize, isOk };
@@ -1,4 +1,4 @@
1
- export { BshEntityPermissions, BshEntityTypes, BshError, BshInsertDuplicates, BshPKStrategies, BshPKTypes, BshUpdateStrategies, PolicyActions, PrincipalType, defaultSettings, formatFileSize, isOk } from '../chunk-BAYFQNFR.js';
1
+ export { AggregateFunctions, BshEntityPermissions, BshEntityTypes, BshError, BshInsertDuplicates, BshPKStrategies, BshPKTypes, BshUpdateStrategies, ComparisonOperators, LogicalOperators, PolicyActions, PrincipalType, defaultSettings, formatFileSize, isOk } from '../chunk-2E5HSZT4.js';
2
2
  export { CoreEntities, PluginBasedEntities } from '../chunk-ZOCNJXUZ.js';
3
3
  //# sourceMappingURL=index.js.map
4
4
  //# sourceMappingURL=index.js.map
@@ -451,4 +451,4 @@ type BshPostInterceptor<T = any> = (response: BshResponse<T>, params?: BshClient
451
451
  type BshPreInterceptor<T = any, R = T> = (params: BshClientFnParams<T, R>) => Promise<BshClientFnParams<T, R>>;
452
452
  type BshErrorInterceptor<T = any> = (error: BshError, response?: BshResponse<T>, params?: BshClientFnParams<T>) => Promise<BshError | undefined>;
453
453
 
454
- export { type AuthToken as A, type BshClientFn as B, type CacheRemoveResponse as C, type EntityFnParams as E, ImageService as I, MailingService as M, SettingsService as S, TenantService as T, UserService as U, type BshAuthFn as a, BshEngine as b, type BshClientFnParams as c, defaultClientFn as d, type BshRefreshTokenFn as e, type BshTenantFn as f, type BshPostInterceptor as g, type BshPreInterceptor as h, type BshErrorInterceptor as i, BshClient as j, type BshCallbackParams as k, type BshCallbackParamsWithPayload as l, type BshSearchCallbackParams as m, type EntityFnParamsWithPayload as n, type EntitySearchFnParams as o, EntityService as p, AuthService as q, AdminUserService as r, BshUtilsService as s, CachingService as t, ApiKeyService as u };
454
+ export { type AuthToken as A, type BshAuthFn as B, type CacheRemoveResponse as C, type EntityFnParams as E, ImageService as I, MailingService as M, SettingsService as S, TenantService as T, UserService as U, type BshClientFn as a, BshEngine as b, BshClient as c, type BshClientFnParams as d, type BshErrorInterceptor as e, type BshPostInterceptor as f, type BshPreInterceptor as g, type BshRefreshTokenFn as h, type BshTenantFn as i, defaultClientFn as j, AdminUserService as k, ApiKeyService as l, AuthService as m, type BshCallbackParams as n, type BshCallbackParamsWithPayload as o, type BshSearchCallbackParams as p, BshUtilsService as q, CachingService as r, type EntityFnParamsWithPayload as s, type EntitySearchFnParams as t, EntityService as u };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bshsolutions/sdk",
3
- "version": "0.0.32",
3
+ "version": "0.0.34",
4
4
  "description": "TypeScript SDK for integrating with BSH Engine <https://engine.bousalih.com>",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -58,11 +58,11 @@
58
58
  },
59
59
  "devDependencies": {
60
60
  "@types/node": "^20.0.0",
61
- "@vitest/coverage-v8": "^2.0.0",
61
+ "@vitest/coverage-v8": "^4.1.4",
62
62
  "tsup": "^8.0.0",
63
63
  "typescript": "^5.0.0",
64
64
  "vite-tsconfig-paths": "^5.1.4",
65
- "vitest": "^2.0.0"
65
+ "vitest": "^4.1.4"
66
66
  },
67
67
  "overrides": {
68
68
  "esbuild": "^0.25.0"
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/types/response/index.ts","../src/types/entities/index.ts","../src/types/security/index.ts","../src/types/config/index.ts","../src/types/storage/index.ts"],"names":[],"mappings":";AAyBO,IAAM,IAAA,GAAO,CAAC,QAAA,KAA+C,QAAA,IAAY,MAAA,GAAY,QAAQ,QAAA,EAAU,IAAA,IAAQ,GAAA,IAAO,QAAA,EAAU,IAAA,GAAO;AAEvI,IAAM,QAAA,G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AAM,KAAA,EAAO,OAAO,SAAA;AACzB,EAAA,MAAM,KAAA,GAAQ,CAAC,OAAA,EAAS,IAAA,EAAM,MAAM,IAAI,CAAA;AACxC,EAAA,MAAM,CAAA,GAAI,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,GAAA,CAAI,IAAA,CAAK,KAAK,CAAA,GAAI,IAAA,CAAK,GAAA,CAAI,IAAI,CAAC,CAAA;AAC1D,EAAA,OAAO,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,KAAA,GAAQ,KAAK,GAAA,CAAI,IAAA,EAAM,CAAC,CAAA,GAAI,GAAG,CAAA,GAAI,GAAA,GAAM,GAAA,GAAM,MAAM,CAAC,CAAA;AACjF","file":"chunk-BAYFQNFR.js","sourcesContent":["export type BshResponse<T> = {\n data: T[]\n timestamp: number\n code: number\n status: string\n message?: string\n error?: string\n meta?: {\n type?: string,\n sql?: string,\n error?: string,\n tips?: {[key: string]: string}\n }\n pagination?: {\n current: number,\n total: number,\n pages: number,\n first: boolean,\n last: boolean\n }\n endpoint?: string,\n api?: string,\n validations?: {field: string, error: string}[]\n}\n\nexport const isOk = (response: BshResponse<unknown> | undefined) => response == undefined ? false : response?.code >= 200 && response?.code < 300\n\nexport class BshError extends Error {\n constructor(\n public status: number,\n public endpoint: string,\n public response?: BshResponse<unknown>\n ) {\n if (response) response.endpoint = endpoint\n super(JSON.stringify(response, null, 2));\n this.name = 'BshError';\n }\n}\n","import { BshObject, BshObjectPure } from '@types';\n\nexport type BshEntities = {\n name: string\n dbTable: string\n dbSchema: string\n type: 'Table' | 'View' | 'Function'\n dbSource: string\n updateStrategy: 'Replace' | 'Upsert'\n insertDuplicate: 'Upsert' | 'Error'\n bshSchema?: string\n bshPlugin?: string\n auditable?: boolean\n isPluginBased?: boolean\n isMultiTenant?: boolean\n pks: {\n key: string\n strategy: 'AutoIncrement' | 'UUID' | 'Fixed'\n type: 'string' | 'number'\n }[]\n permissions?: {\n write?: boolean\n read?: boolean\n delete?: boolean\n update?: boolean\n }\n} & BshObject;\n\nexport type BshEntitiesPure = BshObjectPure<BshEntities>;\nexport type BshEntityPermissions = 'read' | 'write' | 'update' | 'delete';\nexport const BshEntityTypes = ['Table', 'View', 'Function'] as const;\nexport const BshUpdateStrategies = ['Replace', 'Upsert'] as const;\nexport const BshInsertDuplicates = ['Upsert', 'Error'] as const;\nexport const BshPKStrategies = ['AutoIncrement', 'UUID', 'Fixed'] as const;\nexport const BshPKTypes = ['string', 'number'] as const;\nexport const BshEntityPermissions = ['read', 'write', 'update', 'delete'] as const;\n\nexport type BshSchemas = {\n name: string\n label: string\n description: string\n bshPlugin: string\n properties: {\n type: string\n name: string\n label: string\n\n meta?: {\n description?: string\n\n required?: boolean\n unique?: boolean\n default?: string\n\n length?: number\n maxLength?: number\n minLength?: number\n\n pattern?: string\n }\n }[]\n} & BshObject;\n\nexport type BshSchemasPure = BshObjectPure<BshSchemas>;\nexport type BshSchemaProperty = BshSchemas['properties'][number];\n\nexport type BshTypes = {\n name: string\n label: string\n bshPlugin?: string\n baseType?: string\n schema?: string\n meta?: {\n description?: string\n pattern?: string\n maxLength?: number\n minLength?: number\n max?: number\n min?: number\n }\n} & BshObject;\n\nexport type BshTypesPure = BshObjectPure<BshTypes>;\n\n","import {BshDate, BshObject, BshObjectPure} from '@types';\n\nexport type BshUser = {\n userId: string\n tenantId: string\n email: string\n password?: string\n roles: string[]\n status: 'ACTIVATED' | 'REQUIRED_ACTIVATION' | 'DISABLED' | 'REQUIRED_RESET_PASSWORD'\n profile?: {\n firstName?: string\n lastName?: string\n phone?: string\n picture?: string\n tags?: string[]\n [k: string]: unknown\n }\n} & BshObject;\n\nexport type BshUserInit = {\n email: string\n tenantId?: string\n password?: string\n roles?: string[]\n profile: BshUser['profile']\n}\n\nexport type BshUserPure = BshObjectPure<BshUser>;\n\nexport type BshRole = {\n name: string\n public?: boolean\n admin?: boolean\n description?: string\n bshPlugin?: string;\n} & BshObject;\n\nexport type BshRolePure = BshObjectPure<BshRole>;\n\nexport type BshPolicy = {\n name: string\n description?: string\n principals: {\n type: Uppercase<'user' | 'group' | 'role' | 'apiKey' | 'any'>\n value: string[]\n }[]\n permissions: {\n entity: string[]\n actions: ('READ' | 'WRITE' | 'DELETE' | 'UPDATE' | 'SEARCH' | '*')[]\n allow: boolean\n }[]\n enabled: boolean\n priority?: number\n apiKeyId?: number\n bshPlugin?: string;\n} & BshObject;\n\nexport type BshPolicyPure = BshObjectPure<BshPolicy>;\nexport const PrincipalType = ['user', 'role', 'any', 'apiKey', /*'group'*/] as const;\nexport const PolicyActions = ['*', 'READ', 'WRITE', 'DELETE', 'UPDATE', 'SEARCH'] as const;\n\nexport type BshApiKeysScopes = {\n read: boolean\n write: boolean\n delete: boolean\n update: boolean\n}\n\nexport type BshApiKeysForm = {\n name: string\n description?: string\n duration: number\n type: 'PERSONAL' | 'MACHINE'\n scopes: string[] // Format: [\"EntityName:ACTION\", ...]\n}\n\nexport type BshApiKeys = BshApiKeysForm & {\n id: number\n apiKey: string\n startedAt: BshDate\n expiresAt?: BshDate\n status: 'ACTIVE' | 'REVOKED'\n userId?: string\n} & BshObject;\n\nexport type BshTenant = {\n tenantId: string;\n name: string;\n status: 'Active' | 'Inactive' | 'Blocked';\n description?: string;\n domain?: string;\n email?: string;\n adminId?: string;\n settings?: Record<string, unknown>;\n} & BshObject;\n\nexport type BshTenantPure = BshObjectPure<BshTenant>;\n","import {BshObject} from \"@types\";\n\nexport type BshConfigurations<T extends Record<string, unknown> = Record<string, unknown>> = {\n name: string;\n description: string;\n bshPlugin?: string;\n config?: T;\n} & BshObject\n\nexport type BshSettings = {\n name: string;\n api: {\n response?: {\n showSql?: boolean;\n };\n auth?: {\n enableRegister?: boolean;\n };\n };\n}\n\nexport const defaultSettings: BshSettings = {\n name: 'BshEngine',\n api: {\n response: {\n showSql: true\n },\n auth: {\n enableRegister: false\n }\n }\n}\n\n","import { BshObject, BshConfigurations } from '@types';\n\nexport type StorageProvider = 'cloudinary';\n\nexport type CloudinaryConfig = {\n url: string;\n folder?: string;\n}\n\nexport type StorageConfiguration = BshConfigurations & {\n enabled?: StorageProvider;\n cloudinary: CloudinaryConfig\n}\n\nexport type BshFiles = {\n storageId: string;\n id: string;\n filename: string;\n mediaType: string;\n uri: string;\n secureUri: string;\n bytes: number;\n format: string;\n folder: string;\n width: number;\n height: number;\n tags: string[];\n context: { [key: string]: unknown };\n fileId: string;\n} & BshObject\n\nexport type UploadOptions = {\n tags: string[]\n context: { [key: string]: unknown }\n [key: string]: unknown;\n}\n\nexport type UploadResponse = {\n fileId: string\n publicId: string\n assetId: string\n uri: string\n secureUri: string\n tags: string[]\n context: { [key: string]: unknown }\n}\n\nexport const formatFileSize = (file: BshFiles): string => {\n if (!file?.bytes) return 'Unknown';\n const sizes = ['Bytes', 'KB', 'MB', 'GB'];\n const i = Math.floor(Math.log(file.bytes) / Math.log(1024));\n return Math.round(file.bytes / Math.pow(1024, i) * 100) / 100 + ' ' + sizes[i];\n};\n\n"]}