buildx-sdk 1.0.4

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.
@@ -0,0 +1,126 @@
1
+ import { BaseService } from "./BaseService";
2
+ import { Collection, Document, QueryOptions, ErrorResponse, SuccessResponse, ImportMapping, PaginatedResult, CollectionRealtimeHandlers, CollectionRealtimeSubscribeOptions, CollectionRealtimeSubscription } from "../types/index";
3
+ type UpdateDocumentOptions = {
4
+ updateOnly?: boolean;
5
+ };
6
+ /**
7
+ * Collections service for Buildx
8
+ * Handles collection management, documents, and queries
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const collections = buildx.collections();
13
+ *
14
+ * // Get all collections
15
+ * const collectionsList = await collections.list();
16
+ *
17
+ * // Get collection schema
18
+ * const schema = await collections.getSchema('collection-id');
19
+ *
20
+ * // Query documents
21
+ * const docs = await collections.query('collection-id', {
22
+ * filter: { status: 'active' },
23
+ * limit: 10
24
+ * });
25
+ * ```
26
+ */
27
+ export declare class Collections {
28
+ private baseService;
29
+ private static readonly RELATION_QUERY_CHUNK_SIZE;
30
+ private collectionWsClient;
31
+ private collectionWsCollectionId;
32
+ private collectionWsDisabledUntil;
33
+ constructor(baseService: BaseService);
34
+ /**
35
+ * List all collections in a project
36
+ */
37
+ list(withStats?: boolean, withBuildx?: boolean): Promise<Collection[] | ErrorResponse>;
38
+ /**
39
+ * Get collection schema
40
+ */
41
+ getSchema(collectionId: string, depth?: number): Promise<Collection | ErrorResponse>;
42
+ /**
43
+ * Create or update collection
44
+ */
45
+ set(collectionData: Partial<Collection>): Promise<Collection | ErrorResponse>;
46
+ /**
47
+ * Delete collection
48
+ */
49
+ deleteCollection(collectionId: string): Promise<SuccessResponse | ErrorResponse>;
50
+ /**
51
+ * Query documents in a collection
52
+ */
53
+ query(collectionId: string, options?: QueryOptions): Promise<Document[] | ErrorResponse>;
54
+ /**
55
+ * Query documents without server-side populate.
56
+ */
57
+ queryRaw(collectionId: string, options?: QueryOptions): Promise<Document[] | ErrorResponse>;
58
+ /**
59
+ * Query documents with pagination metadata.
60
+ */
61
+ queryWithPagination(collectionId: string, options?: QueryOptions): Promise<PaginatedResult<Document> | ErrorResponse>;
62
+ private queryWithPaginationViaHttp;
63
+ private queryWithPaginationViaWs;
64
+ private queryRawViaWs;
65
+ private getOrCreateCollectionWsClient;
66
+ private resetCollectionWsClient;
67
+ /**
68
+ * Subscribe realtime data events for a collection via SSE endpoint.
69
+ * Works in browser/EventSource-compatible runtimes.
70
+ */
71
+ subscribeRealtime(collectionId: string, handlers: CollectionRealtimeHandlers, options?: CollectionRealtimeSubscribeOptions): CollectionRealtimeSubscription;
72
+ /**
73
+ * Get lookup data for a collection (for dropdowns/autocomplete)
74
+ */
75
+ lookup(collectionId: string, options?: QueryOptions): Promise<Array<{
76
+ value: string;
77
+ label: string;
78
+ }> | ErrorResponse>;
79
+ private buildQueryParams;
80
+ private hydrateRelations;
81
+ /**
82
+ * Get single document by ID
83
+ */
84
+ getDocument(collectionId: string, documentId: string, populate?: string[]): Promise<Document | ErrorResponse>;
85
+ /**
86
+ * Create new document
87
+ */
88
+ createDocument(collectionId: string, data: any): Promise<Document | ErrorResponse>;
89
+ /**
90
+ * Update document
91
+ */
92
+ updateDocument(collectionId: string, documentId: string, data: any): Promise<Document | ErrorResponse>;
93
+ /**
94
+ * Update document with optional mode flags.
95
+ */
96
+ updateDocumentWithOptions(collectionId: string, documentId: string, data: any, options?: UpdateDocumentOptions): Promise<Document | ErrorResponse>;
97
+ /**
98
+ * Get document revisions
99
+ */
100
+ getDocumentRevisions(collectionId: string, documentId: string): Promise<Document[] | ErrorResponse>;
101
+ /**
102
+ * Delete document
103
+ */
104
+ deleteDocument(collectionId: string, documentId: string): Promise<SuccessResponse | ErrorResponse>;
105
+ /**
106
+ * Delete documents by filter
107
+ */
108
+ deleteByFilter(collectionId: string, filter: any): Promise<SuccessResponse | ErrorResponse>;
109
+ /**
110
+ * Import data to collection
111
+ */
112
+ import(collectionId: string, file: File, mapping: ImportMapping): Promise<SuccessResponse | ErrorResponse>;
113
+ /**
114
+ * Get collection data types
115
+ */
116
+ getDataTypes(): Promise<any | ErrorResponse>;
117
+ /**
118
+ * Validate collection data
119
+ */
120
+ validate(collectionId: string): Promise<SuccessResponse | ErrorResponse>;
121
+ /**
122
+ * Migrate collection data
123
+ */
124
+ migrate(collectionId: string): Promise<SuccessResponse | ErrorResponse>;
125
+ }
126
+ export {};
@@ -0,0 +1,41 @@
1
+ import { BaseService } from "./BaseService";
2
+ import { ErrorResponse } from "../types/index";
3
+ /**
4
+ * Flows service for Buildx
5
+ * Handles flow types and running flows
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const flows = buildx.flows();
10
+ *
11
+ * // Get flow types
12
+ * const types = await flows.getTypes();
13
+ *
14
+ * // Run a flow
15
+ * const result = await flows.run('flow-id', 'session-id', 'root', { arg1: 'value' });
16
+ * ```
17
+ */
18
+ export declare class Flows {
19
+ private baseService;
20
+ constructor(baseService: BaseService);
21
+ /**
22
+ * Get all flow types
23
+ */
24
+ getTypes(): Promise<any | ErrorResponse>;
25
+ /**
26
+ * Run a flow
27
+ */
28
+ run(flowId: string, sessionId?: string | null, state?: any, args?: any): Promise<any | ErrorResponse>;
29
+ /**
30
+ * Get GPT flow code suggestions
31
+ */
32
+ getGptFlowSuggestions(instruction: string): Promise<any | ErrorResponse>;
33
+ /**
34
+ * Get GPT collection suggestions
35
+ */
36
+ getGptCollectionSuggestions(instruction: string): Promise<any | ErrorResponse>;
37
+ /**
38
+ * Get GPT lifecycle suggestions
39
+ */
40
+ getGptLifecycleSuggestions(instruction: string): Promise<any | ErrorResponse>;
41
+ }
@@ -0,0 +1,40 @@
1
+ import { BaseService } from "./BaseService";
2
+ import { Function, FunctionLog, ErrorResponse } from "../types/index";
3
+ /**
4
+ * Functions service for Buildx
5
+ * Handles serverless functions management
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const functions = buildx.functions();
10
+ *
11
+ * // Get all functions
12
+ * const funcs = await functions.list();
13
+ *
14
+ * // Get function by name
15
+ * const func = await functions.getByName('function-name');
16
+ *
17
+ * // Update function
18
+ * await functions.update('function-name', { code: 'new code' });
19
+ * ```
20
+ */
21
+ export declare class Functions {
22
+ private baseService;
23
+ constructor(baseService: BaseService);
24
+ /**
25
+ * List all functions in a project
26
+ */
27
+ list(): Promise<Function[] | ErrorResponse>;
28
+ /**
29
+ * Get function by name
30
+ */
31
+ getByName(functionName: string): Promise<Function | ErrorResponse>;
32
+ /**
33
+ * Update function
34
+ */
35
+ update(functionName: string, data: Partial<Function>): Promise<Function | ErrorResponse>;
36
+ /**
37
+ * Get function logs
38
+ */
39
+ getLogs(functionName: string): Promise<FunctionLog[] | ErrorResponse>;
40
+ }
@@ -0,0 +1,55 @@
1
+ import { BaseService } from "./BaseService";
2
+ import { Project, ErrorResponse, SuccessResponse } from "../types/index";
3
+ /**
4
+ * Projects service for Buildx
5
+ * Handles project management operations
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const projects = buildx.projects();
10
+ *
11
+ * // List all projects
12
+ * const projectList = await projects.list();
13
+ *
14
+ * // Create a new project
15
+ * const newProject = await projects.create({
16
+ * name: 'My Project',
17
+ * description: 'A new project'
18
+ * });
19
+ *
20
+ * // Get project by ID
21
+ * const project = await projects.get('project-id');
22
+ * ```
23
+ */
24
+ export declare class Projects {
25
+ private baseService;
26
+ constructor(baseService: BaseService);
27
+ /**
28
+ * List all projects
29
+ */
30
+ list(): Promise<Project[] | ErrorResponse>;
31
+ /**
32
+ * Get project by ID
33
+ */
34
+ get(projectId: string): Promise<Project | ErrorResponse>;
35
+ /**
36
+ * Create a new project
37
+ */
38
+ create(projectData: Partial<Project>): Promise<Project | ErrorResponse>;
39
+ /**
40
+ * Update project
41
+ */
42
+ update(projectId: string, projectData: Partial<Project>): Promise<Project | ErrorResponse>;
43
+ /**
44
+ * Delete project
45
+ */
46
+ deleteById(projectId: string): Promise<SuccessResponse | ErrorResponse>;
47
+ /**
48
+ * Backup project
49
+ */
50
+ backup(projectId: string): Promise<SuccessResponse | ErrorResponse>;
51
+ /**
52
+ * Restore project from backup
53
+ */
54
+ restore(projectId: string, file: File): Promise<SuccessResponse | ErrorResponse>;
55
+ }
@@ -0,0 +1,44 @@
1
+ import { BaseService } from "./BaseService";
2
+ import { ErrorResponse, SuccessResponse } from "../types/index";
3
+ /**
4
+ * Storage service for Buildx
5
+ * Handles file upload, download, and management
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const storage = buildx.storage();
10
+ *
11
+ * // Upload file
12
+ * const result = await storage.upload(file, 'uploads/');
13
+ *
14
+ * // List files in directory
15
+ * const files = await storage.list('uploads/');
16
+ *
17
+ * // Delete file
18
+ * await storage.delete('uploads/file.txt');
19
+ * ```
20
+ */
21
+ export declare class Storage {
22
+ private baseService;
23
+ constructor(baseService: BaseService);
24
+ /**
25
+ * Upload file to storage
26
+ */
27
+ upload(file: File, prefix?: string): Promise<SuccessResponse | ErrorResponse>;
28
+ /**
29
+ * Upload file to collection storage
30
+ */
31
+ uploadToCollection(file: File, collectionId: string, prefix?: string): Promise<SuccessResponse | ErrorResponse>;
32
+ /**
33
+ * List files in directory
34
+ */
35
+ list(path: string): Promise<any | ErrorResponse>;
36
+ /**
37
+ * Get storage size for path
38
+ */
39
+ getSize(path: string): Promise<any | ErrorResponse>;
40
+ /**
41
+ * Delete file from storage
42
+ */
43
+ delete(path: string): Promise<SuccessResponse | ErrorResponse>;
44
+ }
@@ -0,0 +1,36 @@
1
+ import { BaseService } from "./BaseService";
2
+ import { ErrorResponse, SuccessResponse } from "../types/index";
3
+ /**
4
+ * Templates service for Buildx
5
+ * Handles template rendering and preview
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const templates = buildx.templates();
10
+ *
11
+ * // Preview a template
12
+ * const preview = await templates.preview('template', { name: 'John' });
13
+ *
14
+ * // Render a template
15
+ * const rendered = await templates.render('template-id', { name: 'John' });
16
+ *
17
+ * // Generate PDF
18
+ * await templates.generatePDF('template-id', data);
19
+ * ```
20
+ */
21
+ export declare class Templates {
22
+ private baseService;
23
+ constructor(baseService: BaseService);
24
+ /**
25
+ * Preview a template with data
26
+ */
27
+ preview(template: any, data: any): Promise<any | ErrorResponse>;
28
+ /**
29
+ * Render a template by ID with data
30
+ */
31
+ render(templateId: string, data: any): Promise<any | ErrorResponse>;
32
+ /**
33
+ * Render a template as PDF and download (browser only)
34
+ */
35
+ renderPDF(templateId: string, data: any): Promise<SuccessResponse | ErrorResponse>;
36
+ }
@@ -0,0 +1,256 @@
1
+ export interface ApiHeaders {
2
+ "Content-Type": string;
3
+ "Authorization"?: string;
4
+ "X-API-Key": string;
5
+ [key: string]: string | undefined;
6
+ }
7
+ export interface ErrorResponse {
8
+ error: string;
9
+ message: string;
10
+ statusCode: number;
11
+ success: false;
12
+ }
13
+ export interface SuccessResponse<T = any> {
14
+ success: true;
15
+ data?: T;
16
+ message?: string;
17
+ }
18
+ export interface Project {
19
+ _id: string;
20
+ name: string;
21
+ description?: string;
22
+ created_at: string;
23
+ updated_at: string;
24
+ [key: string]: any;
25
+ }
26
+ export interface Collection {
27
+ _id: string;
28
+ collection_id: string;
29
+ name: string;
30
+ description?: string;
31
+ schema?: any;
32
+ lifecycle?: any;
33
+ created_at: string;
34
+ updated_at: string;
35
+ [key: string]: any;
36
+ }
37
+ export interface Document {
38
+ _id: string;
39
+ [key: string]: any;
40
+ }
41
+ export interface QueryOptions {
42
+ filter?: any;
43
+ jsonFilter?: any;
44
+ select?: string | string[];
45
+ projection?: string;
46
+ options?: any;
47
+ sort?: any;
48
+ limit?: number;
49
+ skip?: number;
50
+ q?: string;
51
+ quick_filter_fields?: string | string[];
52
+ noPopulate?: boolean;
53
+ relations?: RelationHydrationConfig[];
54
+ relationSelect?: string | string[];
55
+ populate?: string[];
56
+ paginationTransport?: "auto" | "http" | "ws";
57
+ wsFactory?: (url: string) => PaginationWebSocketLike;
58
+ }
59
+ export interface PaginationWebSocketLike {
60
+ readyState: number;
61
+ send: (data: string) => void;
62
+ close: () => void;
63
+ onopen?: ((event: any) => void) | null;
64
+ onmessage?: ((event: {
65
+ data: string;
66
+ }) => void) | null;
67
+ onerror?: ((event: any) => void) | null;
68
+ onclose?: ((event: any) => void) | null;
69
+ addEventListener?: (event: "open" | "message" | "error" | "close", handler: (event: any) => void) => void;
70
+ }
71
+ export interface PaginationMeta {
72
+ count: number;
73
+ limit: number;
74
+ skip: number;
75
+ pagination_field?: string;
76
+ sort?: Record<string, any>;
77
+ select_fields?: string[];
78
+ transport?: "http" | "ws";
79
+ }
80
+ export interface PaginatedResult<T = Document> {
81
+ data: T[];
82
+ meta: PaginationMeta;
83
+ }
84
+ export interface RelationHydrationConfig {
85
+ field: string;
86
+ collectionId: string;
87
+ many?: boolean;
88
+ select?: string | string[];
89
+ }
90
+ export interface CollectionRealtimeEvent {
91
+ type: string;
92
+ project_id: string;
93
+ collection_id: string;
94
+ document_id?: string;
95
+ document_ids?: string[];
96
+ payload?: any;
97
+ timestamp: number;
98
+ }
99
+ export interface CollectionRealtimeHandlers {
100
+ onConnected?: () => void;
101
+ onEvent?: (event: CollectionRealtimeEvent) => void;
102
+ onError?: (error: any) => void;
103
+ }
104
+ export interface CollectionRealtimeSubscribeOptions {
105
+ apiKey?: string;
106
+ token?: string;
107
+ lastEventId?: string;
108
+ eventSourceFactory?: (url: string) => {
109
+ onopen: ((event: any) => void) | null;
110
+ onmessage: ((event: any) => void) | null;
111
+ onerror: ((event: any) => void) | null;
112
+ addEventListener?: (event: string, handler: (event: any) => void) => void;
113
+ close: () => void;
114
+ };
115
+ }
116
+ export interface CollectionRealtimeSubscription {
117
+ close: () => void;
118
+ }
119
+ export interface AuthUser {
120
+ _id: string;
121
+ username: string;
122
+ email?: string;
123
+ role?: string;
124
+ created_at: string;
125
+ updated_at: string;
126
+ access_token?: string;
127
+ refresh_token?: string;
128
+ [key: string]: any;
129
+ }
130
+ export interface AuthResponse {
131
+ user: AuthUser;
132
+ access_token: string;
133
+ refresh_token?: string;
134
+ }
135
+ export interface LoginCredentials {
136
+ username: string;
137
+ password: string;
138
+ }
139
+ export interface GoogleCredentials {
140
+ credential: string;
141
+ }
142
+ export interface EotpRequest {
143
+ email: string;
144
+ }
145
+ export interface EotpVerify {
146
+ email: string;
147
+ otp: string;
148
+ }
149
+ export interface PasswordResetRequest {
150
+ email: string;
151
+ reset_url?: string;
152
+ resetUrl?: string;
153
+ }
154
+ export interface PasswordResetPayload {
155
+ token: string;
156
+ new_password?: string;
157
+ password?: string;
158
+ email?: string;
159
+ }
160
+ export interface ChangePasswordRequest {
161
+ password?: string;
162
+ newPassword?: string;
163
+ new_password?: string;
164
+ currentPassword?: string;
165
+ current_password?: string;
166
+ }
167
+ export interface ApiKey {
168
+ _id: string;
169
+ name: string;
170
+ key: string;
171
+ permissions?: string[];
172
+ created_at: string;
173
+ updated_at: string;
174
+ [key: string]: any;
175
+ }
176
+ export interface StorageFile {
177
+ name: string;
178
+ size: number;
179
+ type: string;
180
+ url?: string;
181
+ path: string;
182
+ created_at: string;
183
+ [key: string]: any;
184
+ }
185
+ export interface Flow {
186
+ _id: string;
187
+ name: string;
188
+ type: string;
189
+ config: any;
190
+ created_at: string;
191
+ updated_at: string;
192
+ [key: string]: any;
193
+ }
194
+ export interface FlowRunOptions {
195
+ session_id?: string;
196
+ state?: string;
197
+ args?: any;
198
+ }
199
+ export interface Template {
200
+ _id: string;
201
+ name: string;
202
+ content: string;
203
+ type: string;
204
+ created_at: string;
205
+ updated_at: string;
206
+ [key: string]: any;
207
+ }
208
+ export interface BuildxObject {
209
+ _id: string;
210
+ _display?: string;
211
+ [key: string]: any;
212
+ }
213
+ export interface BuildxConfig {
214
+ apiEndpoint: string;
215
+ apiKey: string;
216
+ projectId?: string;
217
+ organizationId?: string;
218
+ }
219
+ export interface Function {
220
+ _id: string;
221
+ name: string;
222
+ code: string;
223
+ runtime: string;
224
+ created_at: string;
225
+ updated_at: string;
226
+ [key: string]: any;
227
+ }
228
+ export interface FunctionLog {
229
+ _id: string;
230
+ function_name: string;
231
+ level: string;
232
+ message: string;
233
+ timestamp: string;
234
+ [key: string]: any;
235
+ }
236
+ export interface Lifecycle {
237
+ states: string[];
238
+ transitions: LifecycleTransition[];
239
+ [key: string]: any;
240
+ }
241
+ export interface LifecycleTransition {
242
+ from: string;
243
+ to: string;
244
+ conditions?: any;
245
+ actions?: any;
246
+ }
247
+ export interface ImportMapping {
248
+ [field: string]: string;
249
+ }
250
+ export interface BackupData {
251
+ project: Project;
252
+ collections: Collection[];
253
+ data: {
254
+ [collectionId: string]: Document[];
255
+ };
256
+ }
package/package.json ADDED
@@ -0,0 +1,92 @@
1
+ {
2
+ "name": "buildx-sdk",
3
+ "version": "1.0.4",
4
+ "description": "Official JavaScript/TypeScript SDK for Buildx low-code platform",
5
+ "type": "module",
6
+ "main": "dist/index.cjs",
7
+ "module": "dist/index.esm.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.esm.js",
13
+ "require": "./dist/index.cjs",
14
+ "default": "./dist/index.esm.js"
15
+ },
16
+ "./dist/*": "./dist/*",
17
+ "./package.json": "./package.json"
18
+ },
19
+ "files": [
20
+ "dist",
21
+ "README.md",
22
+ "LICENSE"
23
+ ],
24
+ "scripts": {
25
+ "build": "rimraf dist && rollup -c",
26
+ "dev": "rollup -c -w",
27
+ "test": "jest",
28
+ "test:watch": "jest --watch",
29
+ "lint": "eslint src --ext .ts",
30
+ "lint:fix": "eslint src --ext .ts --fix",
31
+ "clean": "rimraf dist",
32
+ "prepublishOnly": "npm run clean && npm run build",
33
+ "docs": "typedoc --options typedoc.json",
34
+ "docs:clean": "rimraf docs/api",
35
+ "validate": "concurrently \"yarn lint\" \"yarn test\""
36
+ },
37
+ "keywords": [
38
+ "buildx",
39
+ "low-code",
40
+ "api",
41
+ "sdk",
42
+ "typescript",
43
+ "javascript"
44
+ ],
45
+ "author": "Buildx Team",
46
+ "license": "MIT",
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "https://github.com/mekku/buildx.git"
50
+ },
51
+ "bugs": {
52
+ "url": "https://github.com/mekku/buildx/issues"
53
+ },
54
+ "homepage": "https://github.com/mekku/buildx/tree/main/packages/buildx-sdk#readme",
55
+ "devDependencies": {
56
+ "@rollup/plugin-commonjs": "^25.0.0",
57
+ "@rollup/plugin-node-resolve": "^15.0.0",
58
+ "@rollup/plugin-typescript": "^11.0.0",
59
+ "@types/jest": "^29.0.0",
60
+ "@types/lodash": "^4.14.0",
61
+ "@typescript-eslint/eslint-plugin": "^8.34.1",
62
+ "@typescript-eslint/parser": "^8.34.1",
63
+ "clean-jsdoc-theme": "^4.2.9",
64
+ "concurrently": "^9.1.2",
65
+ "esbuild": "^0.25.5",
66
+ "eslint": "^9.29.0",
67
+ "eslint-import-resolver-typescript": "^4.4.3",
68
+ "eslint-plugin-import": "^2.31.0",
69
+ "eslint-plugin-vitest-globals": "^1.5.0",
70
+ "jest": "^29.0.0",
71
+ "rimraf": "^6.0.1",
72
+ "rollup": "^4.44.0",
73
+ "rollup-plugin-dts": "^6.2.1",
74
+ "rollup-plugin-esbuild": "^6.2.1",
75
+ "rollup-plugin-terser": "^7.0.0",
76
+ "ts-jest": "^29.0.0",
77
+ "typedoc": "^0.28.5",
78
+ "typedoc-github-theme": "^0.3.0",
79
+ "typedoc-plugin-markdown": "^4.0.0",
80
+ "typescript": "5.3.3"
81
+ },
82
+ "dependencies": {
83
+ "axios": "^1.10.0",
84
+ "buildx-common": "^0.1.66",
85
+ "lodash": "^4.17.0",
86
+ "tslib": "^2.8.1",
87
+ "typedoc-plugin-jekyll": "^0.1.0"
88
+ },
89
+ "engines": {
90
+ "node": ">=14.0.0"
91
+ }
92
+ }