@bluecopa/core 0.1.55 → 0.1.57

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 CHANGED
@@ -20,6 +20,13 @@ The core package provides essential API utilities and functions for data managem
20
20
  - [Workbook Module](#workbook-module)
21
21
  - [Workflow Module](#workflow-module)
22
22
  - [Worksheet Module](#worksheet-module)
23
+ - [InputTableDB — Reactive Database Client](#inputtabledb--reactive-database-client)
24
+ - [Quick Start](#quick-start)
25
+ - [CRUD](#crud)
26
+ - [Query Operators](#query-operators)
27
+ - [Framework Integration](#framework-integration)
28
+ - [WebSocket Provider (optional)](#websocket-provider-optional)
29
+ - [Cleanup](#cleanup)
23
30
  - [WebSocket Connection](#websocket-connection)
24
31
  - [WebSocket Factory](#websocket-factory)
25
32
  - [WebSocket Provider Interface](#websocket-provider-interface)
@@ -103,6 +110,8 @@ export interface Config {
103
110
  accessToken: string;
104
111
  workspaceId: string;
105
112
  userId: string;
113
+ solutionId?: string; // used by InputTableDB
114
+ websocketProvider?: IWebsocketProvider; // enables realtime sync
106
115
  }
107
116
  ```
108
117
 
@@ -174,6 +183,133 @@ See: [`workflow/triggerHttpWorkflowById.ts`](src/api/workflow/triggerHttpWorkflo
174
183
 
175
184
  See: [`worksheet/getWorksheets.ts`](src/api/worksheet/getWorksheets.ts:1), [`worksheet/getWorksheetsByType.ts`](src/api/worksheet/getWorksheetsByType.ts:1)
176
185
 
186
+ ## InputTableDB — Reactive Database Client
187
+
188
+ A Firebase-like client for querying and subscribing to Bluecopa Input Table V2 data. No init required — just import and use.
189
+
190
+ > **[Full SDK Guide](docs/input-table-db-guide.md)** — comprehensive documentation with architecture details, error handling, framework integration (Svelte/React), and all available features.
191
+
192
+ ### Quick Start
193
+
194
+ ```typescript
195
+ import { copaSetConfig, copaInputTableDb } from "@bluecopa/core";
196
+
197
+ // Configure once at app startup
198
+ copaSetConfig({
199
+ apiBaseUrl: "https://develop.bluecopa.com",
200
+ accessToken: "your-token",
201
+ workspaceId: "ws-123",
202
+ solutionId: "sol-abc", // optional — falls back to SOLUTION_ID cookie
203
+ websocketProvider: ws, // optional — enables realtime sync
204
+ });
205
+
206
+ // Subscribe (reactive — fires on every change)
207
+ const unsub = copaInputTableDb.collection("invoices")
208
+ .where("status", "==", "pending")
209
+ .orderBy("updated_at", "desc")
210
+ .limit(50)
211
+ .subscribe((rows) => console.log(rows));
212
+
213
+ // Cleanup
214
+ unsub();
215
+ ```
216
+
217
+ ### CRUD
218
+
219
+ ```typescript
220
+ // One-time fetch
221
+ const rows = await copaInputTableDb.collection("invoices").get();
222
+ const inv = await copaInputTableDb.collection("invoices").doc(id).get();
223
+
224
+ // Write
225
+ const newId = await copaInputTableDb.collection("invoices").add({ vendor: "Acme", amount: 100 });
226
+ await copaInputTableDb.collection("invoices").doc(id).update({ status: "approved" });
227
+ await copaInputTableDb.collection("invoices").doc(id).delete();
228
+
229
+ // Listen to a single doc
230
+ const unsub = copaInputTableDb.collection("invoices").doc(id).onSnapshot((doc) => {
231
+ console.log(doc);
232
+ });
233
+
234
+ // Reactive count
235
+ const unsub = copaInputTableDb.collection("invoices").count((n) => console.log(n));
236
+ ```
237
+
238
+ ### Query Operators
239
+
240
+ | Operator | Meaning |
241
+ |-----------|-----------------|
242
+ | `==` | equals |
243
+ | `!=` | not equals |
244
+ | `<` | less than |
245
+ | `<=` | less than or eq |
246
+ | `>` | greater than |
247
+ | `>=` | gte |
248
+ | `in` | in array |
249
+ | `not-in` | not in array |
250
+
251
+ ### Framework Integration
252
+
253
+ **Svelte 5**
254
+ ```svelte
255
+ <script>
256
+ import { copaInputTableDb } from "@bluecopa/core";
257
+ let rows = $state([]);
258
+
259
+ $effect(() =>
260
+ copaInputTableDb.collection("invoices")
261
+ .where("status", "==", "pending")
262
+ .subscribe((r) => { rows = r; })
263
+ );
264
+ </script>
265
+ ```
266
+
267
+ **React**
268
+ ```tsx
269
+ useEffect(() => {
270
+ return copaInputTableDb.collection("invoices")
271
+ .where("status", "==", "pending")
272
+ .subscribe(setRows);
273
+ }, []);
274
+ ```
275
+
276
+ **Vanilla JS**
277
+ ```ts
278
+ const unsub = copaInputTableDb.collection("invoices").subscribe(setRows);
279
+ // later:
280
+ unsub();
281
+ ```
282
+
283
+ ### WebSocket Provider (optional)
284
+
285
+ Enables realtime sync via push instead of polling:
286
+
287
+ ```typescript
288
+ import { copaSetConfig, copaInputTableDb, copaUtils } from "@bluecopa/core";
289
+
290
+ const ws = copaUtils.websocketUtils.WebsocketContextFactory.create("centrifugo", {
291
+ connectionUrl: "wss://...",
292
+ token: "jwt",
293
+ userId: "user-123",
294
+ });
295
+
296
+ // Option A: via config
297
+ copaSetConfig({ websocketProvider: ws });
298
+
299
+ // Option B: set directly
300
+ copaInputTableDb.setWebsocketProvider(ws);
301
+ ```
302
+
303
+ If no provider is set, the SDK still works via HTTP pull replication and logs a console warning.
304
+
305
+ ### Cleanup
306
+
307
+ ```typescript
308
+ await copaInputTableDb.destroy(); // closes all collections + WebSocket
309
+ ```
310
+
311
+ ---
312
+
177
313
  ## WebSocket Connection
178
314
 
179
315
  The core package provides WebSocket utilities for real-time communication using Centrifugo.
package/dist/config.d.ts CHANGED
@@ -1,8 +1,12 @@
1
+ import { IWebsocketProvider } from './utils/websockets/websocketProviderFactory';
2
+ export type { IWebsocketProvider } from './utils/websockets/websocketProviderFactory';
1
3
  export interface Config {
2
4
  apiBaseUrl: string;
3
5
  accessToken: string;
4
6
  workspaceId: string;
5
7
  userId: string;
8
+ solutionId?: string;
9
+ websocketProvider?: IWebsocketProvider;
6
10
  }
7
11
  declare class ConfigSingleton {
8
12
  private static instance;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  export { setConfig as copaSetConfig, getConfig as copaGetConfig, } from './config';
2
+ export type { Config, IWebsocketProvider } from './config';
2
3
  export * as copaApi from './api';
3
4
  export * as copaUtils from './utils';
5
+ export { copaInputTableDb, InputTableColumnType, InputTableError } from './input-table-db';
6
+ export type { Row, WhereOp, QueryBuilder, DocRef, CollectionRef, InputTableDB, InputTableDefinition, InputTableColumn, } from './input-table-db';
4
7
  export { default as copaTailwindConfig } from './tailwind/bluecopa.config';
5
8
  export type { GetAuditLogsRequest, AuditLogResponse, } from './api/audit/getAuditLogs';
6
9
  export type { AuditRecord, CreateAuditLogRequest, } from './api/audit/createAuditLog';