@bshsolutions/sdk 0.0.36 → 0.0.38

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,4 +1,4 @@
1
- import { BshError } from './chunk-2E5HSZT4.js';
1
+ import { BshError } from './chunk-TCZ7ZZEE.js';
2
2
 
3
3
  // src/client/types.ts
4
4
  var defaultClientFn = async (params) => {
@@ -53,6 +53,7 @@ var BshClient = class {
53
53
  const data = await response.json();
54
54
  let result = data;
55
55
  result.api = params.api;
56
+ await this.notifyTokenRefreshedIfPresent(result);
56
57
  const byPassPostInterceptors = params.bshOptions.byPass?.interceptors?.post;
57
58
  if ((byPassPostInterceptors == void 0 || !byPassPostInterceptors) && this.bshEngine?.getPostInterceptors().length) {
58
59
  for (const interceptor of this.bshEngine.getPostInterceptors()) {
@@ -73,29 +74,11 @@ var BshClient = class {
73
74
  } else return blob;
74
75
  }
75
76
  }
76
- async refreshTokenIfNeeded(auth, refreshTokenFn) {
77
- if (!refreshTokenFn || !auth || auth.type !== "JWT") return auth;
78
- const accessToken = auth.token;
79
- try {
80
- const tokenPayload = JSON.parse(atob(accessToken.split(".")[1] || ""));
81
- const exp = tokenPayload.exp * 1e3;
82
- const now = (/* @__PURE__ */ new Date()).getTime();
83
- if (exp && now < exp) return auth;
84
- const refreshToken = await refreshTokenFn();
85
- if (!refreshToken || !this.bshEngine) return auth;
86
- const response = await this.bshEngine.auth.refreshToken({
87
- payload: { refresh: refreshToken },
88
- onError: () => {
89
- }
90
- });
91
- if (response) return {
92
- type: "JWT",
93
- token: response.data[0].access
94
- };
95
- return auth;
96
- } catch (error) {
97
- return auth;
98
- }
77
+ async notifyTokenRefreshedIfPresent(result) {
78
+ const accessToken = result.meta?.accessToken;
79
+ if (!accessToken) return;
80
+ const handler = this.bshEngine?.getOnTokenRefreshed();
81
+ if (handler) await handler(accessToken);
99
82
  }
100
83
  getCookie(name) {
101
84
  if (typeof document === "undefined") return void 0;
@@ -115,12 +98,14 @@ var BshClient = class {
115
98
  }
116
99
  async getAuthHeaders(params) {
117
100
  if (params.path.includes("/api/auth/")) return {};
118
- let auth = this.authFn ? await this.authFn() : void 0;
119
- if (auth) auth = await this.refreshTokenIfNeeded(auth, this.refreshTokenFn);
101
+ const auth = this.authFn ? await this.authFn() : void 0;
120
102
  let authHeaders = {};
121
103
  if (auth) {
122
- if (auth.type === "JWT") authHeaders = { Authorization: `Bearer ${auth.token}` };
123
- else if (auth.type === "APIKEY") authHeaders = { "X-BSH-APIKEY": auth.token };
104
+ if (auth.type === "JWT") {
105
+ authHeaders = { Authorization: `Bearer ${auth.token}` };
106
+ const refreshToken = await this.refreshTokenFn?.();
107
+ if (refreshToken) authHeaders = { ...authHeaders, "X-BSH-REFRESHTOKEN": refreshToken };
108
+ } else if (auth.type === "APIKEY") authHeaders = { Authorization: auth.token };
124
109
  else authHeaders = this.getCsrfHeaders(params);
125
110
  } else authHeaders = this.getCsrfHeaders(params);
126
111
  return { ...authHeaders };
@@ -270,5 +255,5 @@ var fetchClientFn = async (params) => {
270
255
  };
271
256
 
272
257
  export { BshClient, defaultClientFn, fetchClientFn };
273
- //# sourceMappingURL=chunk-PXKQN4D4.js.map
274
- //# sourceMappingURL=chunk-PXKQN4D4.js.map
258
+ //# sourceMappingURL=chunk-35P3LGGA.js.map
259
+ //# sourceMappingURL=chunk-35P3LGGA.js.map
@@ -0,0 +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,KAAA;AAAA,IACH,MAAA,CAAO,IAAA;AAAA,IACP;AAAA,MACI,MAAA,EAAQ,OAAO,OAAA,CAAQ,MAAA;AAAA,MACvB,MAAM,MAAA,CAAO,OAAA,CAAQ,aAAA,KAAkB,MAAA,GACnC,OAAO,OAAA,CAAQ,IAAA,GAAmB,MAAA,CAAO,OAAA,CAA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AAO,OAAA;AAAA,QACV,MAAA,EAAQ,KAAA;AAAA,QACR,OAAA,EAAS;AAAA,UACL,GAAG,OAAO,OAAA,CAAQ,OAAA;AAAA,UAClB,GAAG;AAAA;AACP;AACJ,KACJ;AAEA,IAAA,YAAA,GAAe,MAAM,IAAA,CAAK,oBAAA,CAAwB,YAAY,CAAA;AAC9D,IAAA,MAAM,QAAA,GAAW,MAAM,IAAA,CAAK,UAAA,CAAW,YAAY,CAAA;AACnD,IAAA,OAAO,IAAA,CAAK,cAAA,CAAe,QAAA,EAAU,YAAA,EAAc,MAAM,CAAA;AAAA,EAC7D;AACJ;;;ACpRO,IAAM,aAAA,GAA6B,OAAO,MAAA,KAAW;AACxD,EAAA,OAAO,KAAA;AAAA,IACH,MAAA,CAAO,IAAA;AAAA,IACP;AAAA,MACI,MAAA,EAAQ,OAAO,OAAA,CAAQ,MAAA;AAAA,MACvB,MAAM,MAAA,CAAO,OAAA,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-35P3LGGA.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 BshOnTokenRefreshedFn = (accessToken: string) => void | Promise<void>;\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 await this.notifyTokenRefreshedIfPresent(result);\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 notifyTokenRefreshedIfPresent(result: BshResponse<unknown>) {\n const accessToken = result.meta?.accessToken;\n if (!accessToken) return;\n const handler = this.bshEngine?.getOnTokenRefreshed();\n if (handler) await handler(accessToken);\n }\n\n private getCookie(name: string): string | undefined {\n if (typeof document === 'undefined') return undefined;\n\n const cookies = document.cookie.split(';');\n\n for (const cookie of cookies) {\n const [key, ...valueParts] = cookie.trim().split('=');\n if (key === name) return decodeURIComponent(valueParts.join('='));\n }\n\n return undefined;\n }\n\n private getCsrfHeaders(params: BshClientFnParams<any>): Record<string, string> {\n const method = params.options?.method?.toUpperCase() || 'GET';\n if (method === 'GET' || method === 'HEAD' || method === 'OPTIONS') return {};\n const csrfToken = this.getCookie('XSRF-TOKEN');\n if (!csrfToken) return {};\n return { 'X-XSRF-TOKEN': csrfToken };\n }\n\n private async getAuthHeaders(params: BshClientFnParams<any>): Promise<Record<string, string>> {\n if (params.path.includes('/api/auth/')) return {};\n\n const auth = this.authFn ? await this.authFn() : undefined;\n\n let authHeaders = {};\n if (auth) {\n if (auth.type === 'JWT') {\n authHeaders = { Authorization: `Bearer ${auth.token}` };\n const refreshToken = await this.refreshTokenFn?.();\n if (refreshToken) authHeaders = { ...authHeaders, 'X-BSH-REFRESHTOKEN': refreshToken };\n }\n else if (auth.type === 'APIKEY') authHeaders = { Authorization: auth.token };\n else authHeaders = this.getCsrfHeaders(params);\n } else authHeaders = this.getCsrfHeaders(params);\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\n return {\n ...authHeaders,\n ...tenantHeaders,\n };\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, options: { ...params.options, method: 'GET' } });\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, options: { ...params.options, method: 'POST' } });\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, options: { ...params.options, method: 'PUT' } });\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, options: { ...params.options, method: 'DELETE' } });\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, options: { ...params.options, method: 'PATCH' } });\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, options: { ...params.options, method: 'GET' } });\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, '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"]}
@@ -56,5 +56,5 @@ var formatFileSize = (file) => {
56
56
  };
57
57
 
58
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
59
+ //# sourceMappingURL=chunk-TCZ7ZZEE.js.map
60
+ //# sourceMappingURL=chunk-TCZ7ZZEE.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":";AA0BO,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,GAAN,cAAuB,KAAA,CAAM;AAAA,EAChC,WAAA,CACW,MAAA,EACA,QAAA,EACA,QAAA,EACT;AACE,IAAA,IAAI,QAAA,WAAmB,QAAA,GAAW,QAAA;AAClC,IAAA,KAAA,CAAM,IAAA,CAAK,SAAA,CAAU,QAAA,EAAU,IAAA,EAAM,CAAC,CAAC,CAAA;AALhC,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AACA,IAAA,IAAA,CAAA,QAAA,GAAA,QAAA;AACA,IAAA,IAAA,CAAA,QAAA,GAAA,QAAA;AAIP,IAAA,IAAA,CAAK,IAAA,GAAO,UAAA;AAAA,EAChB;AACJ;;;ACzBO,IAAM,gBAAA,GAAmB,CAAC,KAAA,EAAO,IAAA,EAAM,KAAK;AAG5C,IAAM,sBAAsB,CAAC,IAAA,EAAM,MAAM,IAAA,EAAM,KAAA,EAAO,MAAM,KAAA,EAAO,MAAA,EAAQ,OAAA,EAAS,UAAA,EAAY,aAAa,QAAA,EAAU,SAAA,EAAW,MAAM,KAAA,EAAO,SAAA,EAAW,UAAU,SAAS;AAgB7K,IAAM,qBAAqB,CAAC,OAAA,EAAS,KAAA,EAAO,KAAA,EAAO,OAAO,KAAK;;;ACF/D,IAAM,cAAA,GAAiB,CAAC,OAAA,EAAS,MAAA,EAAQ,UAAU;AACnD,IAAM,mBAAA,GAAsB,CAAC,SAAA,EA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\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 accessToken?: 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,5 +1,5 @@
1
- import { a as BshClientFn } from '../types-DSzlEe09.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-DSzlEe09.js';
1
+ import { a as BshClientFn } from '../types-CbNqDVZY.js';
2
+ export { A as AuthToken, B as BshAuthFn, c as BshClient, d as BshClientFnParams, e as BshErrorInterceptor, f as BshOnTokenRefreshedFn, g as BshPostInterceptor, h as BshPreInterceptor, i as BshRefreshTokenFn, j as BshTenantFn, k as defaultClientFn } from '../types-CbNqDVZY.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-PXKQN4D4.js';
2
- import '../chunk-2E5HSZT4.js';
1
+ export { BshClient, defaultClientFn, fetchClientFn } from '../chunk-35P3LGGA.js';
2
+ import '../chunk-TCZ7ZZEE.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 { B as BshAuthFn, a as BshClientFn, b as BshEngine } from './types-DSzlEe09.js';
1
+ export { B as BshAuthFn, a as BshClientFn, b as BshEngine } from './types-CbNqDVZY.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-PXKQN4D4.js';
1
+ import { fetchClientFn, BshClient } from './chunk-35P3LGGA.js';
2
2
  import { EntityService, AuthService, UserService, TenantService, SettingsService, ImageService, MailingService, BshUtilsService, CachingService, ApiKeyService } from './chunk-C6W32LLO.js';
3
- import './chunk-2E5HSZT4.js';
3
+ import './chunk-TCZ7ZZEE.js';
4
4
  import { CoreEntities } from './chunk-ZOCNJXUZ.js';
5
5
 
6
6
  // src/services/plugins/index.ts
@@ -81,6 +81,7 @@ var BshEngine = class {
81
81
  this.clientFn = params.clientFn || this.clientFn || fetchClientFn;
82
82
  this.authFn = params.authFn || this.authFn;
83
83
  this.refreshTokenFn = params.refreshTokenFn || this.refreshTokenFn;
84
+ this.onTokenRefreshed = params.onTokenRefreshed;
84
85
  this.tenantFn = params.tenantFn || this.tenantFn;
85
86
  this.postInterceptors = params.postInterceptors || [];
86
87
  this.preInterceptors = params.preInterceptors || [];
@@ -99,6 +100,10 @@ var BshEngine = class {
99
100
  this.refreshTokenFn = refreshTokenFn;
100
101
  return this;
101
102
  }
103
+ withOnTokenRefreshed(handler) {
104
+ this.onTokenRefreshed = handler;
105
+ return this;
106
+ }
102
107
  withTenant(tenantFn) {
103
108
  this.tenantFn = tenantFn;
104
109
  return this;
@@ -126,6 +131,9 @@ var BshEngine = class {
126
131
  getErrorInterceptors() {
127
132
  return this.errorInterceptors;
128
133
  }
134
+ getOnTokenRefreshed() {
135
+ return this.onTokenRefreshed;
136
+ }
129
137
  // Client
130
138
  get client() {
131
139
  return new BshClient(
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/services/plugins/index.ts","../src/services/status/index.ts","../src/bshengine.ts","../src/index.ts"],"names":[],"mappings":";;;;;;AAKO,IAAM,gBAAN,MAAoB;AAAA,EAGhB,YAA6B,MAAA,EAAmB;AAAnB,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AAFpC,IAAA,IAAA,CAAiB,YAAA,GAAe,cAAA;AAAA,EAGhC;AAAA,EAEA,MAAa,WACT,MAAA,EACyD;AACzD,IAAA,MAAM,QAAA,GAAW,IAAI,QAAA,EAAS;AAC9B,IAAA,QAAA,CAAS,GAAA,CAAI,MAAA,EAAQ,MAAA,CAAO,OAAA,CAAQ,IAAI,CAAA;AAExC,IAAA,OAAO,IAAA,CAAK,OAAO,IAAA,CAA8B;AAAA,MAC7C,IAAA,EAAM,CAAA,EAAG,IAAA,CAAK,YAAY,CAAA,YAAA,CAAA;AAAA,MAC1B,OAAA,EAAS;AAAA,QACL,YAAA,EAAc,MAAA;AAAA,QACd,aAAA,EAAe,MAAA;AAAA,QACf,IAAA,EAAM;AAAA,OACV;AAAA,MACA,UAA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AAA,GAAS;AAChB,IAAA,OAAO,IAAI,aAAA,CAAc,IAAA,CAAK,MAAM,CAAA;AAAA,EACxC;AACJ;;;AC7KO,IAAM,OAAA,GAAU","file":"index.js","sourcesContent":["import { BshClient } from \"@src/client/bsh-client\";\nimport { BshResponse, PluginInstalledResponse } from \"@types\";\nimport { BshCallbackParams, BshCallbackParamsWithPayload } from \"@src/services\";\nimport { CoreEntities } from \"@src/types/core\";\n\nexport class PluginService {\n private readonly baseEndpoint = '/api/plugins';\n\n public constructor(private readonly client: BshClient) {\n }\n\n public async installZip(\n params: BshCallbackParamsWithPayload<{ file: File }, PluginInstalledResponse>\n ): Promise<BshResponse<PluginInstalledResponse> | undefined> {\n const formData = new FormData();\n formData.set('file', params.payload.file);\n\n return this.client.post<PluginInstalledResponse>({\n path: `${this.baseEndpoint}/install/zip`,\n options: {\n responseType: 'json',\n requestFormat: 'form',\n body: formData,\n },\n bshOptions: params,\n api: 'plugins.installZip',\n entity: CoreEntities.BshPlugins,\n });\n }\n\n public async installCore(\n params: BshCallbackParams<PluginInstalledResponse>\n ): Promise<BshResponse<PluginInstalledResponse> | undefined> {\n return this.client.post<PluginInstalledResponse>({\n path: `${this.baseEndpoint}/install/core`,\n options: {\n responseType: 'json'\n },\n bshOptions: params,\n api: 'plugins.installZip',\n entity: CoreEntities.BshPlugins,\n });\n }\n}\n","import { BshClient } from \"@src/client/bsh-client\";\nimport { BshResponse } from \"@types\";\nimport { BshCallbackParams } from \"@src/services\";\nimport { EngineStatus, HealthCheckData } from \"@src/types\";\n\nexport class StatusService {\n private readonly baseEndpoint = '/api/status';\n\n public constructor(private readonly client: BshClient) {\n }\n\n public async load(params?: BshCallbackParams<unknown, EngineStatus>): Promise<BshResponse<EngineStatus> | undefined> {\n return this.client.get<EngineStatus>({\n path: this.baseEndpoint,\n options: {\n responseType: 'json',\n requestFormat: 'json',\n },\n bshOptions: { onSuccess: params?.onSuccess, onError: params?.onError },\n api: 'status.load',\n });\n }\n\n public async health(params?: BshCallbackParams<unknown, HealthCheckData>): Promise<BshResponse<HealthCheckData> | undefined> {\n return this.client.get<HealthCheckData>({\n path: `${this.baseEndpoint}/health`,\n options: {\n responseType: 'json',\n requestFormat: 'json',\n },\n bshOptions: { onSuccess: params?.onSuccess, onError: params?.onError },\n api: 'status.health',\n });\n }\n}\n","import { BshAuthFn, BshClient, BshClientFn, BshErrorInterceptor, BshPostInterceptor, BshPreInterceptor, BshRefreshTokenFn, BshTenantFn, fetchClientFn } from \"@client\";\nimport { ApiKeyService, AuthService, BshUtilsService, CachingService, EntityService, ImageService, MailingService, SettingsService, TenantService, UserService } from \"@src/services\";\nimport { BshEntities, BshPolicy, BshRole, BshEmailTemplate, BshEventLogs, BshSchemas, BshTypes, BshUser, SentEmail, BshTrigger, BshTriggerInstance, BshFiles, BshConfigurations, BshPlugin, BshTenant } from \"@types\";\nimport { PluginService } from \"./services/plugins\";\nimport { StatusService } from \"./services/status\";\n\nexport class BshEngine {\n private host?: string;\n private clientFn: BshClientFn = fetchClientFn;\n private authFn?: BshAuthFn;\n private refreshTokenFn?: BshRefreshTokenFn;\n private tenantFn?: BshTenantFn;\n \n private postInterceptors: BshPostInterceptor<unknown>[] = [];\n private preInterceptors: BshPreInterceptor<unknown>[] = [];\n private errorInterceptors: BshErrorInterceptor<unknown>[] = [];\n\n constructor(params: {\n host?: string;\n apiKey?: string;\n jwtToken?: string;\n refreshToken?: string;\n clientFn?: BshClientFn;\n authFn?: BshAuthFn;\n tenantFn?: BshTenantFn;\n refreshTokenFn?: BshRefreshTokenFn;\n postInterceptors?: BshPostInterceptor<unknown>[];\n preInterceptors?: BshPreInterceptor<unknown>[];\n errorInterceptors?: BshErrorInterceptor<unknown>[];\n } = {}) {\n this.host = params.host;\n if (params.apiKey && !params.authFn) this.authFn = async () => ({ type: 'APIKEY', token: params.apiKey! });\n if (params.jwtToken && !params.authFn) this.authFn = async () => ({ type: 'JWT', token: params.jwtToken! });\n if (params.refreshToken) this.refreshTokenFn = async () => params.refreshToken!;\n this.clientFn = params.clientFn || this.clientFn || fetchClientFn;\n this.authFn = params.authFn || this.authFn;\n this.refreshTokenFn = params.refreshTokenFn || this.refreshTokenFn;\n this.tenantFn = params.tenantFn || this.tenantFn;\n this.postInterceptors = params.postInterceptors || [];\n this.preInterceptors = params.preInterceptors || [];\n this.errorInterceptors = params.errorInterceptors || [];\n }\n\n // Configuration\n public withClient(clientFn: BshClientFn) {\n this.clientFn = clientFn;\n return this;\n }\n\n public withAuth(authFn: BshAuthFn) {\n this.authFn = authFn;\n return this;\n }\n\n public withRefreshToken(refreshTokenFn: BshRefreshTokenFn) {\n this.refreshTokenFn = refreshTokenFn;\n return this;\n }\n\n public withTenant(tenantFn: BshTenantFn) {\n this.tenantFn = tenantFn;\n return this;\n }\n\n // Interceptors\n public postInterceptor(interceptor: BshPostInterceptor<unknown>) {\n this.postInterceptors.push(interceptor);\n return this;\n }\n\n public preInterceptor(interceptor: BshPreInterceptor<unknown>) {\n this.preInterceptors.push(interceptor);\n return this;\n }\n\n public errorInterceptor(interceptor: BshErrorInterceptor<unknown>) {\n this.errorInterceptors.push(interceptor);\n return this;\n }\n\n // getters\n public getPostInterceptors() {\n return this.postInterceptors;\n }\n\n public getPreInterceptors() {\n return this.preInterceptors;\n }\n\n public getErrorInterceptors() {\n return this.errorInterceptors;\n }\n\n // Client\n private get client(): BshClient {\n return new BshClient(\n this.host, \n this.clientFn, \n this.authFn, \n this.refreshTokenFn, \n this.tenantFn, \n this\n );\n }\n\n // Services\n public get entities() {\n return new EntityService(this.client);\n }\n\n public entity<T>(entity: string) {\n return new EntityService<T>(this.client, entity);\n }\n\n public get core() {\n return {\n BshEntities: this.entity<BshEntities>('BshEntities'),\n BshSchemas: this.entity<BshSchemas>('BshSchemas'),\n BshTypes: this.entity<BshTypes>('BshTypes'),\n BshUsers: this.entity<BshUser>('BshUsers'),\n BshPolicies: this.entity<BshPolicy>('BshPolicies'),\n BshRoles: this.entity<BshRole>('BshRoles'),\n BshFiles: this.entity<BshFiles>('BshFiles'),\n BshConfigurations: this.entity<BshConfigurations>('BshConfigurations'),\n BshEmails: this.entity<SentEmail>('BshEmails'),\n BshEmailTemplates: this.entity<BshEmailTemplate>('BshEmailTemplates'),\n BshEventLogs: this.entity<BshEventLogs>('BshEventLogs'),\n BshTriggers: this.entity<BshTrigger>('BshTriggers'),\n BshTriggerInstances: this.entity<BshTriggerInstance>('BshTriggerInstances'),\n BshPlugins: this.entity<BshPlugin>('BshPlugins'),\n }\n }\n\n public get auth() {\n return new AuthService(this.client);\n }\n\n public get users() {\n return new UserService(this.client);\n }\n\n public get tenants() {\n return new TenantService(this.client);\n }\n\n public get settings() {\n return new SettingsService(this.client);\n }\n\n public get image() {\n return new ImageService(this.client);\n }\n\n public get mailing() {\n return new MailingService(this.client);\n }\n\n public get utils() {\n return new BshUtilsService(this.client);\n }\n\n public get caching() {\n return new CachingService(this.client);\n }\n\n public get apiKey() {\n return new ApiKeyService(this.client);\n }\n\n public get plugins() {\n return new PluginService(this.client);\n }\n\n public get status() {\n return new StatusService(this.client);\n }\n}\n","export { type BshClientFn, type BshAuthFn } from './client'\nexport { type BshResponse } from './types'\nexport { BshEngine } from './bshengine';\nexport const version = '0.0.1' as const;\n"]}
1
+ {"version":3,"sources":["../src/services/plugins/index.ts","../src/services/status/index.ts","../src/bshengine.ts","../src/index.ts"],"names":[],"mappings":";;;;;;AAKO,IAAM,gBAAN,MAAoB;AAAA,EAGhB,YAA6B,MAAA,EAAmB;AAAnB,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AAFpC,IAAA,IAAA,CAAiB,YAAA,GAAe,cAAA;AAAA,EAGhC;AAAA,EAEA,MAAa,WACT,MAAA,EACyD;AACzD,IAAA,MAAM,QAAA,GAAW,IAAI,QAAA,EAAS;AAC9B,IAAA,QAAA,CAAS,GAAA,CAAI,MAAA,EAAQ,MAAA,CAAO,OAAA,CAAQ,IAAI,CAAA;AAExC,IAAA,OAAO,IAAA,CAAK,OAAO,IAAA,C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,MAAM,CAAA;AAAA,EACzC;AAAA,EAEA,IAAW,KAAA,GAAQ;AACf,IAAA,OAAO,IAAI,eAAA,CAAgB,IAAA,CAAK,MAAM,CAAA;AAAA,EAC1C;AAAA,EAEA,IAAW,OAAA,GAAU;AACjB,IAAA,OAAO,IAAI,cAAA,CAAe,IAAA,CAAK,MAAM,CAAA;AAAA,EACzC;AAAA,EAEA,IAAW,MAAA,GAAS;AAChB,IAAA,OAAO,IAAI,aAAA,CAAc,IAAA,CAAK,MAAM,CAAA;AAAA,EACxC;AAAA,EAEA,IAAW,OAAA,GAAU;AACjB,IAAA,OAAO,IAAI,aAAA,CAAc,IAAA,CAAK,MAAM,CAAA;AAAA,EACxC;AAAA,EAEA,IAAW,MAAA,GAAS;AAChB,IAAA,OAAO,IAAI,aAAA,CAAc,IAAA,CAAK,MAAM,CAAA;AAAA,EACxC;AACJ;;;ACzLO,IAAM,OAAA,GAAU","file":"index.js","sourcesContent":["import { BshClient } from \"@src/client/bsh-client\";\nimport { BshResponse, PluginInstalledResponse } from \"@types\";\nimport { BshCallbackParams, BshCallbackParamsWithPayload } from \"@src/services\";\nimport { CoreEntities } from \"@src/types/core\";\n\nexport class PluginService {\n private readonly baseEndpoint = '/api/plugins';\n\n public constructor(private readonly client: BshClient) {\n }\n\n public async installZip(\n params: BshCallbackParamsWithPayload<{ file: File }, PluginInstalledResponse>\n ): Promise<BshResponse<PluginInstalledResponse> | undefined> {\n const formData = new FormData();\n formData.set('file', params.payload.file);\n\n return this.client.post<PluginInstalledResponse>({\n path: `${this.baseEndpoint}/install/zip`,\n options: {\n responseType: 'json',\n requestFormat: 'form',\n body: formData,\n },\n bshOptions: params,\n api: 'plugins.installZip',\n entity: CoreEntities.BshPlugins,\n });\n }\n\n public async installCore(\n params: BshCallbackParams<PluginInstalledResponse>\n ): Promise<BshResponse<PluginInstalledResponse> | undefined> {\n return this.client.post<PluginInstalledResponse>({\n path: `${this.baseEndpoint}/install/core`,\n options: {\n responseType: 'json'\n },\n bshOptions: params,\n api: 'plugins.installZip',\n entity: CoreEntities.BshPlugins,\n });\n }\n}\n","import { BshClient } from \"@src/client/bsh-client\";\nimport { BshResponse } from \"@types\";\nimport { BshCallbackParams } from \"@src/services\";\nimport { EngineStatus, HealthCheckData } from \"@src/types\";\n\nexport class StatusService {\n private readonly baseEndpoint = '/api/status';\n\n public constructor(private readonly client: BshClient) {\n }\n\n public async load(params?: BshCallbackParams<unknown, EngineStatus>): Promise<BshResponse<EngineStatus> | undefined> {\n return this.client.get<EngineStatus>({\n path: this.baseEndpoint,\n options: {\n responseType: 'json',\n requestFormat: 'json',\n },\n bshOptions: { onSuccess: params?.onSuccess, onError: params?.onError },\n api: 'status.load',\n });\n }\n\n public async health(params?: BshCallbackParams<unknown, HealthCheckData>): Promise<BshResponse<HealthCheckData> | undefined> {\n return this.client.get<HealthCheckData>({\n path: `${this.baseEndpoint}/health`,\n options: {\n responseType: 'json',\n requestFormat: 'json',\n },\n bshOptions: { onSuccess: params?.onSuccess, onError: params?.onError },\n api: 'status.health',\n });\n }\n}\n","import { BshAuthFn, BshClient, BshClientFn, BshErrorInterceptor, BshOnTokenRefreshedFn, BshPostInterceptor, BshPreInterceptor, BshRefreshTokenFn, BshTenantFn, fetchClientFn } from \"@client\";\nimport { ApiKeyService, AuthService, BshUtilsService, CachingService, EntityService, ImageService, MailingService, SettingsService, TenantService, UserService } from \"@src/services\";\nimport { BshEntities, BshPolicy, BshRole, BshEmailTemplate, BshEventLogs, BshSchemas, BshTypes, BshUser, SentEmail, BshTrigger, BshTriggerInstance, BshFiles, BshConfigurations, BshPlugin, BshTenant } from \"@types\";\nimport { PluginService } from \"./services/plugins\";\nimport { StatusService } from \"./services/status\";\n\nexport class BshEngine {\n private host?: string;\n private clientFn: BshClientFn = fetchClientFn;\n private authFn?: BshAuthFn;\n private refreshTokenFn?: BshRefreshTokenFn;\n private onTokenRefreshed?: BshOnTokenRefreshedFn;\n private tenantFn?: BshTenantFn;\n \n private postInterceptors: BshPostInterceptor<unknown>[] = [];\n private preInterceptors: BshPreInterceptor<unknown>[] = [];\n private errorInterceptors: BshErrorInterceptor<unknown>[] = [];\n\n constructor(params: {\n host?: string;\n apiKey?: string;\n jwtToken?: string;\n refreshToken?: string;\n clientFn?: BshClientFn;\n authFn?: BshAuthFn;\n tenantFn?: BshTenantFn;\n refreshTokenFn?: BshRefreshTokenFn;\n onTokenRefreshed?: BshOnTokenRefreshedFn;\n postInterceptors?: BshPostInterceptor<unknown>[];\n preInterceptors?: BshPreInterceptor<unknown>[];\n errorInterceptors?: BshErrorInterceptor<unknown>[];\n } = {}) {\n this.host = params.host;\n if (params.apiKey && !params.authFn) this.authFn = async () => ({ type: 'APIKEY', token: params.apiKey! });\n if (params.jwtToken && !params.authFn) this.authFn = async () => ({ type: 'JWT', token: params.jwtToken! });\n if (params.refreshToken) this.refreshTokenFn = async () => params.refreshToken!;\n this.clientFn = params.clientFn || this.clientFn || fetchClientFn;\n this.authFn = params.authFn || this.authFn;\n this.refreshTokenFn = params.refreshTokenFn || this.refreshTokenFn;\n this.onTokenRefreshed = params.onTokenRefreshed;\n this.tenantFn = params.tenantFn || this.tenantFn;\n this.postInterceptors = params.postInterceptors || [];\n this.preInterceptors = params.preInterceptors || [];\n this.errorInterceptors = params.errorInterceptors || [];\n }\n\n // Configuration\n public withClient(clientFn: BshClientFn) {\n this.clientFn = clientFn;\n return this;\n }\n\n public withAuth(authFn: BshAuthFn) {\n this.authFn = authFn;\n return this;\n }\n\n public withRefreshToken(refreshTokenFn: BshRefreshTokenFn) {\n this.refreshTokenFn = refreshTokenFn;\n return this;\n }\n\n public withOnTokenRefreshed(handler: BshOnTokenRefreshedFn) {\n this.onTokenRefreshed = handler;\n return this;\n }\n\n public withTenant(tenantFn: BshTenantFn) {\n this.tenantFn = tenantFn;\n return this;\n }\n\n // Interceptors\n public postInterceptor(interceptor: BshPostInterceptor<unknown>) {\n this.postInterceptors.push(interceptor);\n return this;\n }\n\n public preInterceptor(interceptor: BshPreInterceptor<unknown>) {\n this.preInterceptors.push(interceptor);\n return this;\n }\n\n public errorInterceptor(interceptor: BshErrorInterceptor<unknown>) {\n this.errorInterceptors.push(interceptor);\n return this;\n }\n\n // getters\n public getPostInterceptors() {\n return this.postInterceptors;\n }\n\n public getPreInterceptors() {\n return this.preInterceptors;\n }\n\n public getErrorInterceptors() {\n return this.errorInterceptors;\n }\n\n public getOnTokenRefreshed() {\n return this.onTokenRefreshed;\n }\n\n // Client\n private get client(): BshClient {\n return new BshClient(\n this.host, \n this.clientFn, \n this.authFn, \n this.refreshTokenFn, \n this.tenantFn, \n this\n );\n }\n\n // Services\n public get entities() {\n return new EntityService(this.client);\n }\n\n public entity<T>(entity: string) {\n return new EntityService<T>(this.client, entity);\n }\n\n public get core() {\n return {\n BshEntities: this.entity<BshEntities>('BshEntities'),\n BshSchemas: this.entity<BshSchemas>('BshSchemas'),\n BshTypes: this.entity<BshTypes>('BshTypes'),\n BshUsers: this.entity<BshUser>('BshUsers'),\n BshPolicies: this.entity<BshPolicy>('BshPolicies'),\n BshRoles: this.entity<BshRole>('BshRoles'),\n BshFiles: this.entity<BshFiles>('BshFiles'),\n BshConfigurations: this.entity<BshConfigurations>('BshConfigurations'),\n BshEmails: this.entity<SentEmail>('BshEmails'),\n BshEmailTemplates: this.entity<BshEmailTemplate>('BshEmailTemplates'),\n BshEventLogs: this.entity<BshEventLogs>('BshEventLogs'),\n BshTriggers: this.entity<BshTrigger>('BshTriggers'),\n BshTriggerInstances: this.entity<BshTriggerInstance>('BshTriggerInstances'),\n BshPlugins: this.entity<BshPlugin>('BshPlugins'),\n }\n }\n\n public get auth() {\n return new AuthService(this.client);\n }\n\n public get users() {\n return new UserService(this.client);\n }\n\n public get tenants() {\n return new TenantService(this.client);\n }\n\n public get settings() {\n return new SettingsService(this.client);\n }\n\n public get image() {\n return new ImageService(this.client);\n }\n\n public get mailing() {\n return new MailingService(this.client);\n }\n\n public get utils() {\n return new BshUtilsService(this.client);\n }\n\n public get caching() {\n return new CachingService(this.client);\n }\n\n public get apiKey() {\n return new ApiKeyService(this.client);\n }\n\n public get plugins() {\n return new PluginService(this.client);\n }\n\n public get status() {\n return new StatusService(this.client);\n }\n}\n","export { type BshClientFn, type BshAuthFn } from './client'\nexport { type BshResponse } from './types'\nexport { BshEngine } from './bshengine';\nexport const version = '0.0.1' as const;\n"]}
@@ -1,2 +1,2 @@
1
1
  import '../types/index.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-DSzlEe09.js';
2
+ export { l as AdminUserService, m as ApiKeyService, n as AuthService, o as BshCallbackParams, p as BshCallbackParamsWithPayload, q as BshSearchCallbackParams, r as BshUtilsService, C as CacheRemoveResponse, s as CachingService, E as EntityFnParams, t as EntityFnParamsWithPayload, u as EntitySearchFnParams, v as EntityService, I as ImageService, M as MailingService, S as SettingsService, T as TenantService, U as UserService } from '../types-CbNqDVZY.js';
@@ -45,6 +45,7 @@ type BshResponse<T> = {
45
45
  tips?: {
46
46
  [key: string]: string;
47
47
  };
48
+ accessToken?: string;
48
49
  };
49
50
  pagination?: {
50
51
  current: number;
@@ -364,6 +365,7 @@ type SentEmail = {
364
365
  id: string;
365
366
  subject: string;
366
367
  from: string;
368
+ fromName?: string;
367
369
  to: string;
368
370
  bcc: string[];
369
371
  cc: string[];
@@ -385,7 +387,9 @@ type MailingPayload = {
385
387
  html: boolean;
386
388
  template?: string;
387
389
  data?: object;
390
+ fromName?: string;
388
391
  };
392
+ type EmailSenderTriggerInput = MailingPayload;
389
393
  type GmailConfig = {
390
394
  email: string;
391
395
  password: string;
@@ -395,6 +399,7 @@ type GmailConfig = {
395
399
  auth: boolean;
396
400
  starttls: boolean;
397
401
  from: string;
402
+ fromName?: string;
398
403
  };
399
404
  type MailDevConfig = GmailConfig;
400
405
  type EmailProvider = 'gmail' | 'maildev';
@@ -644,4 +649,4 @@ type AuthTokens = {
644
649
  refresh: string;
645
650
  };
646
651
 
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 };
652
+ 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 EmailSenderTriggerInput, 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 { AggregateFunctions, BshEntityPermissions, BshEntityTypes, BshError, BshInsertDuplicates, BshPKStrategies, BshPKTypes, BshUpdateStrategies, ComparisonOperators, LogicalOperators, PolicyActions, PrincipalType, defaultSettings, formatFileSize, isOk } from '../chunk-2E5HSZT4.js';
1
+ export { AggregateFunctions, BshEntityPermissions, BshEntityTypes, BshError, BshInsertDuplicates, BshPKStrategies, BshPKTypes, BshUpdateStrategies, ComparisonOperators, LogicalOperators, PolicyActions, PrincipalType, defaultSettings, formatFileSize, isOk } from '../chunk-TCZ7ZZEE.js';
2
2
  export { CoreEntities, PluginBasedEntities } from '../chunk-ZOCNJXUZ.js';
3
3
  //# sourceMappingURL=index.js.map
4
4
  //# sourceMappingURL=index.js.map
@@ -23,6 +23,7 @@ declare class BshEngine {
23
23
  private clientFn;
24
24
  private authFn?;
25
25
  private refreshTokenFn?;
26
+ private onTokenRefreshed?;
26
27
  private tenantFn?;
27
28
  private postInterceptors;
28
29
  private preInterceptors;
@@ -36,6 +37,7 @@ declare class BshEngine {
36
37
  authFn?: BshAuthFn;
37
38
  tenantFn?: BshTenantFn;
38
39
  refreshTokenFn?: BshRefreshTokenFn;
40
+ onTokenRefreshed?: BshOnTokenRefreshedFn;
39
41
  postInterceptors?: BshPostInterceptor<unknown>[];
40
42
  preInterceptors?: BshPreInterceptor<unknown>[];
41
43
  errorInterceptors?: BshErrorInterceptor<unknown>[];
@@ -43,6 +45,7 @@ declare class BshEngine {
43
45
  withClient(clientFn: BshClientFn): this;
44
46
  withAuth(authFn: BshAuthFn): this;
45
47
  withRefreshToken(refreshTokenFn: BshRefreshTokenFn): this;
48
+ withOnTokenRefreshed(handler: BshOnTokenRefreshedFn): this;
46
49
  withTenant(tenantFn: BshTenantFn): this;
47
50
  postInterceptor(interceptor: BshPostInterceptor<unknown>): this;
48
51
  preInterceptor(interceptor: BshPreInterceptor<unknown>): this;
@@ -50,6 +53,7 @@ declare class BshEngine {
50
53
  getPostInterceptors(): BshPostInterceptor<unknown>[];
51
54
  getPreInterceptors(): BshPreInterceptor<unknown>[];
52
55
  getErrorInterceptors(): BshErrorInterceptor<unknown>[];
56
+ getOnTokenRefreshed(): BshOnTokenRefreshedFn | undefined;
53
57
  private get client();
54
58
  get entities(): EntityService<unknown>;
55
59
  entity<T>(entity: string): EntityService<T>;
@@ -91,7 +95,7 @@ declare class BshClient {
91
95
  private readonly bshEngine?;
92
96
  constructor(host?: string, httpClient?: BshClientFn, authFn?: BshAuthFn, refreshTokenFn?: BshRefreshTokenFn, tenantFn?: BshTenantFn, bshEngine?: BshEngine);
93
97
  private handleResponse;
94
- private refreshTokenIfNeeded;
98
+ private notifyTokenRefreshedIfPresent;
95
99
  private getCookie;
96
100
  private getCsrfHeaders;
97
101
  private getAuthHeaders;
@@ -448,9 +452,10 @@ type AuthToken = {
448
452
  };
449
453
  type BshAuthFn = () => Promise<AuthToken | undefined | null>;
450
454
  type BshRefreshTokenFn = () => Promise<string | undefined | null>;
455
+ type BshOnTokenRefreshedFn = (accessToken: string) => void | Promise<void>;
451
456
  type BshTenantFn = () => Promise<string | undefined | null>;
452
457
  type BshPostInterceptor<T = any> = (response: BshResponse<T>, params?: BshClientFnParams<T>) => Promise<BshResponse<T>>;
453
458
  type BshPreInterceptor<T = any, R = T> = (params: BshClientFnParams<T, R>) => Promise<BshClientFnParams<T, R>>;
454
459
  type BshErrorInterceptor<T = any> = (error: BshError, response?: BshResponse<T>, params?: BshClientFnParams<T>) => Promise<BshError | undefined>;
455
460
 
456
- 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 };
461
+ 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 BshOnTokenRefreshedFn as f, type BshPostInterceptor as g, type BshPreInterceptor as h, type BshRefreshTokenFn as i, type BshTenantFn as j, defaultClientFn as k, AdminUserService as l, ApiKeyService as m, AuthService as n, type BshCallbackParams as o, type BshCallbackParamsWithPayload as p, type BshSearchCallbackParams as q, BshUtilsService as r, CachingService as s, type EntityFnParamsWithPayload as t, type EntitySearchFnParams as u, EntityService as v };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bshsolutions/sdk",
3
- "version": "0.0.36",
3
+ "version": "0.0.38",
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": "^4.1.4",
61
+ "@vitest/coverage-v8": "^4.1.11",
62
62
  "tsup": "^8.0.0",
63
63
  "typescript": "^5.0.0",
64
64
  "vite-tsconfig-paths": "^5.1.4",
65
- "vitest": "^4.1.4"
65
+ "vitest": "^4.1.11"
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/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,EAAU,IAAA,IAAQ,GAAA,IAAO,QAAA,EAAU,IAAA,GAAO;AAEvI,IAAM,QAAA,GAAN,cAAuB,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K,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 +0,0 @@
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,KAAA;AAAA,IACH,MAAA,CAAO,IAAA;AAAA,IACP;AAAA,MACI,MAAA,EAAQ,OAAO,OAAA,CAAQ,MAAA;AAAA,MACvB,MAAM,MAAA,CAAO,OAAA,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;;;AC5BO,IAAM,YAAN,MAAgB;AAAA,EAQnB,YACI,IAAA,EACA,UAAA,EACA,MAAA,EACA,cAAA,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A,EAAS,OAAO,OAAA,CAAQ;AAAA;AAC5B,GACJ;AACJ","file":"chunk-PXKQN4D4.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 getCookie(name: string): string | undefined {\n if (typeof document === 'undefined') return undefined;\n\n const cookies = document.cookie.split(';');\n\n for (const cookie of cookies) {\n const [key, ...valueParts] = cookie.trim().split('=');\n if (key === name) return decodeURIComponent(valueParts.join('='));\n }\n\n return undefined;\n }\n\n private getCsrfHeaders(params: BshClientFnParams<any>): Record<string, string> {\n const method = params.options?.method?.toUpperCase() || 'GET';\n if (method === 'GET' || method === 'HEAD' || method === 'OPTIONS') return {};\n const csrfToken = this.getCookie('XSRF-TOKEN');\n if (!csrfToken) return {};\n return { 'X-XSRF-TOKEN': csrfToken };\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 else authHeaders = this.getCsrfHeaders(params);\n } else authHeaders = this.getCsrfHeaders(params);\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\n return {\n ...authHeaders,\n ...tenantHeaders,\n };\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, options: { ...params.options, method: 'GET' } });\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, options: { ...params.options, method: 'POST' } });\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, options: { ...params.options, method: 'PUT' } });\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, options: { ...params.options, method: 'DELETE' } });\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, options: { ...params.options, method: 'PATCH' } });\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, options: { ...params.options, method: 'GET' } });\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, '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"]}