@bshsolutions/sdk 0.0.1-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -0
- package/dist/chunk-KVBU5VZS.js +55 -0
- package/dist/chunk-KVBU5VZS.js.map +1 -0
- package/dist/chunk-ZBA6OGQL.js +780 -0
- package/dist/chunk-ZBA6OGQL.js.map +1 -0
- package/dist/chunk-ZQGQYH6Q.js +236 -0
- package/dist/chunk-ZQGQYH6Q.js.map +1 -0
- package/dist/client/index.d.ts +7 -0
- package/dist/client/index.js +4 -0
- package/dist/client/index.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +118 -0
- package/dist/index.js.map +1 -0
- package/dist/services/core/index.d.ts +18 -0
- package/dist/services/core/index.js +20 -0
- package/dist/services/core/index.js.map +1 -0
- package/dist/services/index.d.ts +2 -0
- package/dist/services/index.js +3 -0
- package/dist/services/index.js.map +1 -0
- package/dist/types/index.d.ts +415 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types-c8ObQmiL.d.ts +324 -0
- package/package.json +74 -0
package/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# @bshsolutions/sdk
|
|
2
|
+
|
|
3
|
+
A TypeScript SDK for integrating with [BSH Engine](https://engine.bousalih.com) - a low code backend platform that allows you to create APIs for your application with minimal configuration.
|
|
4
|
+
|
|
5
|
+
## What is BSH Engine?
|
|
6
|
+
|
|
7
|
+
[BSH Engine](https://engine.bousalih.com) is a backend tool that enables you to build robust APIs quickly without writing boilerplate code. It provides:
|
|
8
|
+
|
|
9
|
+
- **Entity Management**: Create, read, update, and delete entities with built-in CRUD operations
|
|
10
|
+
- **Search & Filtering**: Advanced search and filtering for your entities
|
|
11
|
+
- **Authentication**: User registration, login, and JWT token management
|
|
12
|
+
- **File Storage**: Upload and manage images and files
|
|
13
|
+
- **Email Services**: Send emails with templates
|
|
14
|
+
- **API Key Management**: Secure API key generation and management
|
|
15
|
+
- Visit [https://engine.bousalih.com](https://engine.bousalih.com) for more details.
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @bshsolutions/sdk
|
|
21
|
+
# or
|
|
22
|
+
yarn add @bshsolutions/sdk
|
|
23
|
+
# or
|
|
24
|
+
pnpm add @bshsolutions/sdk
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
### Basic Setup
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { BshEngine } from '@bshsolutions/sdk';
|
|
33
|
+
|
|
34
|
+
export const bshServices = new BshEngine()
|
|
35
|
+
.withHost('https://you-instance.com')
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
> for full documtation on how to use it visit: [https://docs.bousalih.com/docs/bsh-engine/sdk](https://docs.bousalih.com/docs/bsh-engine/sdk)
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// src/types/response/index.ts
|
|
2
|
+
var isOk = (response) => response == void 0 ? false : response?.code >= 200 && response?.code < 300;
|
|
3
|
+
var BshError = class extends Error {
|
|
4
|
+
constructor(status, endpoint, response) {
|
|
5
|
+
if (response) response.endpoint = endpoint;
|
|
6
|
+
super(JSON.stringify(response, null, 2));
|
|
7
|
+
this.status = status;
|
|
8
|
+
this.endpoint = endpoint;
|
|
9
|
+
this.response = response;
|
|
10
|
+
this.name = "BshError";
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// src/types/entities/index.ts
|
|
15
|
+
var BshEntityTypes = ["Table", "View", "Function"];
|
|
16
|
+
var BshUpdateStrategies = ["Replace", "Upsert"];
|
|
17
|
+
var BshInsertDuplicates = ["Upsert", "Error"];
|
|
18
|
+
var BshPKStrategies = ["AutoIncrement", "UUID", "Fixed"];
|
|
19
|
+
var BshPKTypes = ["string", "number"];
|
|
20
|
+
var BshEntityPermissions = ["read", "write", "update", "delete"];
|
|
21
|
+
|
|
22
|
+
// src/types/security/index.ts
|
|
23
|
+
var PrincipalType = [
|
|
24
|
+
"user",
|
|
25
|
+
"role",
|
|
26
|
+
"any",
|
|
27
|
+
"apiKey"
|
|
28
|
+
/*'group'*/
|
|
29
|
+
];
|
|
30
|
+
var PolicyActions = ["*", "READ", "WRITE", "DELETE", "UPDATE", "SEARCH"];
|
|
31
|
+
|
|
32
|
+
// src/types/config/index.ts
|
|
33
|
+
var defaultSettings = {
|
|
34
|
+
name: "BshEngine",
|
|
35
|
+
api: {
|
|
36
|
+
response: {
|
|
37
|
+
showSql: true
|
|
38
|
+
},
|
|
39
|
+
auth: {
|
|
40
|
+
enableRegister: false
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// src/types/storage/index.ts
|
|
46
|
+
var formatFileSize = (file) => {
|
|
47
|
+
if (!file?.bytes) return "Unknown";
|
|
48
|
+
const sizes = ["Bytes", "KB", "MB", "GB"];
|
|
49
|
+
const i = Math.floor(Math.log(file.bytes) / Math.log(1024));
|
|
50
|
+
return Math.round(file.bytes / Math.pow(1024, i) * 100) / 100 + " " + sizes[i];
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export { BshEntityPermissions, BshEntityTypes, BshError, BshInsertDuplicates, BshPKStrategies, BshPKTypes, BshUpdateStrategies, PolicyActions, PrincipalType, defaultSettings, formatFileSize, isOk };
|
|
54
|
+
//# sourceMappingURL=chunk-KVBU5VZS.js.map
|
|
55
|
+
//# sourceMappingURL=chunk-KVBU5VZS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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":";AAwBO,IAAM,IAAA,GAAO,CAAC,QAAA,KAA+C,QAAA,IAAY,MAAA,GAAY,QAAQ,QAAA,EAAU,IAAA,IAAQ,GAAA,I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C,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-KVBU5VZS.js","sourcesContent":["export type BshResponse<T> = {\n data: T[]\n timestamp: number\n code: number\n status: 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 plugin?: string\n auditable?: 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 plugin: string\n properties: {\n type: string\n\n name: string\n displayName: string\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} & BshObject;\n\nexport type BshSchemasPure = BshObjectPure<BshSchemas>;\nexport type BshSchemaProperty = BshSchemas['properties'][number];\n\nexport type BshTypes = {\n name: string\n label: string\n plugin?: 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 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 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 description?: 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} & 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\n","import {BshObject} from \"@types\";\n\nexport type BshConfigurations<T extends Record<string, unknown> = Record<string, unknown>> = {\n name: string;\n description: 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 uri: string,\n folder: string,\n secureUri: string,\n tags?: string[],\n assetId: string,\n bytes: number,\n context?: { [key: string]: string },\n publicId: string,\n fileId: string,\n width: number,\n height: number,\n format: 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"]}
|