@bluecopa/core 0.1.57 → 0.1.59

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
@@ -24,6 +24,7 @@ The core package provides essential API utilities and functions for data managem
24
24
  - [Quick Start](#quick-start)
25
25
  - [CRUD](#crud)
26
26
  - [Query Operators](#query-operators)
27
+ - [Aggregate Queries](#aggregate-queries)
27
28
  - [Framework Integration](#framework-integration)
28
29
  - [WebSocket Provider (optional)](#websocket-provider-optional)
29
30
  - [Cleanup](#cleanup)
@@ -248,6 +249,70 @@ const unsub = copaInputTableDb.collection("invoices").count((n) => console.log(n
248
249
  | `in` | in array |
249
250
  | `not-in` | not in array |
250
251
 
252
+ ### Aggregate Queries
253
+
254
+ Compute server-side aggregates (`sum`, `avg`, `count`, `min`, `max`) without fetching all rows. Combines with `where()`, `limit()`, and `skip()` filters.
255
+
256
+ ```typescript
257
+ // Column aggregates
258
+ const result = await copaInputTableDb
259
+ .collection("invoices")
260
+ .where("status", "==", "active")
261
+ .aggregate({ amount: ["sum", "avg"], price: ["min", "max"] });
262
+ // => { amount: { sum: 1234.56, avg: 123.45 }, price: { min: 10, max: 999 } }
263
+
264
+ // Row count
265
+ const result = await copaInputTableDb
266
+ .collection("invoices")
267
+ .aggregate({ _count: true });
268
+ // => { _count: 42 }
269
+
270
+ // Column count (non-null values) + row count
271
+ const result = await copaInputTableDb
272
+ .collection("invoices")
273
+ .aggregate({ name: ["count"], _count: true });
274
+ // => { name: { count: 38 }, _count: 42 }
275
+ ```
276
+
277
+ `.aggregate()` is a **terminal method** — it bypasses local RxDB and hits PostgREST directly. Errors throw `InputTableError`. An empty spec `{}` returns `{}` without calling the API.
278
+
279
+ ### Grouped Aggregates
280
+
281
+ Add a `{ groupBy: [...columns] }` second argument to get per-group breakdowns. Returns an array instead of a single object.
282
+
283
+ ```typescript
284
+ // Sum per status group
285
+ const rows = await copaInputTableDb
286
+ .collection("invoices")
287
+ .aggregate({ amount: ["sum"] }, { groupBy: ["status"] });
288
+ // => [{ status: "active", amount: { sum: 1234 } }, { status: "draft", amount: { sum: 100 } }]
289
+
290
+ // Multi-column groupBy with filters and ordering
291
+ const rows = await copaInputTableDb
292
+ .collection("invoices")
293
+ .where("year", "==", 2024)
294
+ .orderBy("order_date", "asc")
295
+ .aggregate({ amount: ["sum", "avg"] }, { groupBy: ["order_date", "status"] });
296
+
297
+ // Count per group
298
+ const rows = await copaInputTableDb
299
+ .collection("invoices")
300
+ .aggregate({ _count: true }, { groupBy: ["status"] });
301
+ // => [{ status: "active", _count: 10 }, { status: "draft", _count: 4 }]
302
+
303
+ // Distinct values (no aggregate functions)
304
+ const rows = await copaInputTableDb
305
+ .collection("invoices")
306
+ .aggregate({}, { groupBy: ["status"] });
307
+ // => [{ status: "active" }, { status: "draft" }]
308
+ ```
309
+
310
+ **Notes:**
311
+ - `orderBy()` is forwarded to PostgREST when `groupBy` is present (ignored otherwise)
312
+ - `limit()`/`skip()` apply to the number of _groups_, not input rows
313
+ - A column cannot appear in both the aggregate spec and `groupBy` — throws `InputTableError`
314
+ - Empty `groupBy: []` behaves like no groupBy — returns a single object
315
+
251
316
  ### Framework Integration
252
317
 
253
318
  **Svelte 5**
@@ -21,3 +21,4 @@ export * as permissions from './permissions';
21
21
  export * as clientIp from './clientIp';
22
22
  export * as emailEngine from './emailEngine';
23
23
  export * as tcn from './tcn';
24
+ export * as webcron from './webcron';
@@ -0,0 +1,4 @@
1
+ import { Execution, ListExecutionsParams } from './types';
2
+ export declare function listExecutions(params?: ListExecutionsParams): Promise<Execution[]>;
3
+ export declare function getExecution(id: string): Promise<Execution>;
4
+ export declare function retryExecution(id: string): Promise<Execution>;
@@ -0,0 +1,7 @@
1
+ export * from './types';
2
+ export * from './webhooks';
3
+ export * from './schedules';
4
+ export * from './executions';
5
+ export * from './tasks';
6
+ export * from './inspection';
7
+ export * from './trigger';
@@ -0,0 +1,7 @@
1
+ import { InspectionBin, CreateInspectionBinRequest, InspectionRequest, PaginationParams } from './types';
2
+ export declare function listBins(): Promise<InspectionBin[]>;
3
+ export declare function createBin(data: CreateInspectionBinRequest): Promise<InspectionBin>;
4
+ export declare function getBin(id: string): Promise<InspectionBin>;
5
+ export declare function deleteBin(id: string): Promise<void>;
6
+ export declare function getBinRequests(id: string, params?: PaginationParams): Promise<InspectionRequest[]>;
7
+ export declare function clearBinRequests(id: string): Promise<void>;
@@ -0,0 +1,9 @@
1
+ import { Schedule, UpdateScheduleRequest } from './types';
2
+ export declare function getSchedule(id: string): Promise<Schedule>;
3
+ export declare function updateSchedule(id: string, data: UpdateScheduleRequest): Promise<Schedule>;
4
+ export declare function deleteSchedule(id: string): Promise<void>;
5
+ export declare function pauseSchedule(id: string): Promise<Schedule>;
6
+ export declare function resumeSchedule(id: string): Promise<Schedule>;
7
+ export declare function triggerSchedule(id: string): Promise<{
8
+ executionId: string;
9
+ }>;
@@ -0,0 +1,10 @@
1
+ import { Task, CreateTaskRequest, TaskProgressRequest, TaskSignalRequest } from './types';
2
+ export declare function listTasks(): Promise<Task[]>;
3
+ export declare function createTask(data: CreateTaskRequest): Promise<Task>;
4
+ export declare function getTask(id: string): Promise<Task>;
5
+ export declare function cancelTask(id: string): Promise<Task>;
6
+ export declare function retryTask(id: string): Promise<{
7
+ taskId: string;
8
+ }>;
9
+ export declare function progressTask(id: string, data: TaskProgressRequest): Promise<void>;
10
+ export declare function signalTask(id: string, data: TaskSignalRequest, branchId?: string): Promise<Task>;
@@ -0,0 +1,15 @@
1
+ export interface TriggerWorkflowRequest {
2
+ triggerData?: Record<string, unknown>;
3
+ }
4
+ export interface TriggerWorkflowResponse {
5
+ workflow_id: string;
6
+ trigger_id: string;
7
+ workflow_instance_id: string;
8
+ }
9
+ /**
10
+ * Triggers a workflow execution by process sheet ID
11
+ * @param id - The workflow/process sheet ID
12
+ * @param data - Optional trigger data payload
13
+ * @returns Trigger response with workflow instance details
14
+ */
15
+ export declare function triggerWorkflowById(id: string, data?: TriggerWorkflowRequest): Promise<TriggerWorkflowResponse[]>;
@@ -0,0 +1,170 @@
1
+ export interface Webhook {
2
+ id: string;
3
+ name: string;
4
+ description?: string;
5
+ url: string;
6
+ method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
7
+ headers?: Record<string, string>;
8
+ body?: string;
9
+ maxRetries: number;
10
+ retryDelaySeconds: number;
11
+ timeoutSeconds: number;
12
+ authType?: ("hmac" | "basic" | "bearer")[];
13
+ notificationUrl?: string;
14
+ notifyOnSuccess: boolean;
15
+ notifyOnFailure: boolean;
16
+ isActive: boolean;
17
+ createdAt: string;
18
+ updatedAt: string;
19
+ }
20
+ export interface CreateWebhookRequest {
21
+ name: string;
22
+ description?: string;
23
+ url: string;
24
+ method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
25
+ headers?: Record<string, string>;
26
+ body?: string;
27
+ maxRetries?: number;
28
+ retryDelaySeconds?: number;
29
+ timeoutSeconds?: number;
30
+ authType?: ("hmac" | "basic" | "bearer")[];
31
+ signingSecret?: string;
32
+ basicAuthUsername?: string;
33
+ basicAuthPassword?: string;
34
+ bearerToken?: string;
35
+ notificationUrl?: string;
36
+ notifyOnSuccess?: boolean;
37
+ notifyOnFailure?: boolean;
38
+ isActive?: boolean;
39
+ }
40
+ export interface UpdateWebhookRequest extends Partial<CreateWebhookRequest> {
41
+ }
42
+ export interface Schedule {
43
+ id: string;
44
+ webhookId: string;
45
+ type: "one_time" | "recurring";
46
+ scheduledAt?: string;
47
+ cronExpression?: string;
48
+ timezone?: string;
49
+ status: "active" | "paused" | "completed" | "cancelled";
50
+ lastRunAt?: string;
51
+ nextRunAt?: string;
52
+ runCount: string;
53
+ createdAt: string;
54
+ updatedAt: string;
55
+ }
56
+ export interface CreateScheduleRequest {
57
+ type: "one_time" | "recurring";
58
+ scheduledAt?: string;
59
+ cronExpression?: string;
60
+ timezone?: string;
61
+ }
62
+ export interface UpdateScheduleRequest {
63
+ cronExpression?: string;
64
+ timezone?: string;
65
+ }
66
+ export interface Execution {
67
+ id: string;
68
+ webhookId: string;
69
+ scheduleId?: string;
70
+ status: "pending" | "running" | "success" | "failed" | "retrying";
71
+ attemptNumber: number;
72
+ maxAttempts: number;
73
+ requestUrl: string;
74
+ requestMethod: string;
75
+ requestHeaders?: Record<string, string>;
76
+ requestBody?: string;
77
+ responseStatus?: number;
78
+ responseHeaders?: Record<string, string>;
79
+ responseBody?: string;
80
+ startedAt?: string;
81
+ completedAt?: string;
82
+ durationMs?: number;
83
+ errorMessage?: string;
84
+ errorCode?: string;
85
+ createdAt: string;
86
+ updatedAt: string;
87
+ }
88
+ export interface ListExecutionsParams {
89
+ limit?: number;
90
+ offset?: number;
91
+ status?: string;
92
+ webhookId?: string;
93
+ from?: string;
94
+ to?: string;
95
+ }
96
+ export interface Task {
97
+ id: string;
98
+ status: "pending" | "running" | "waiting" | "sleeping" | "fan_out" | "complete" | "failed" | "cancelled";
99
+ webhookId: string;
100
+ initialInput?: Record<string, unknown>;
101
+ continuation?: Record<string, unknown>;
102
+ currentStep: number;
103
+ form?: Record<string, unknown>;
104
+ result?: Record<string, unknown>;
105
+ error?: string;
106
+ errorCode?: string;
107
+ parentTaskId?: string;
108
+ branchId?: string;
109
+ createdAt: string;
110
+ updatedAt: string;
111
+ completedAt?: string;
112
+ }
113
+ export interface CreateTaskRequest {
114
+ webhookId: string;
115
+ initialInput?: Record<string, unknown>;
116
+ maxSteps?: number;
117
+ stepTimeoutMs?: number;
118
+ }
119
+ export interface TaskProgressRequest {
120
+ message: string;
121
+ details?: Record<string, unknown>;
122
+ }
123
+ export interface TaskSignalRequest {
124
+ payload: Record<string, unknown>;
125
+ }
126
+ export interface InspectionBin {
127
+ id: string;
128
+ name: string;
129
+ slug: string;
130
+ responseStatusCode: number;
131
+ responseHeaders?: Record<string, string>;
132
+ responseBody?: string;
133
+ responseDelayMs: number;
134
+ maxRequests: number;
135
+ requestCount: number;
136
+ expiresAt?: string;
137
+ isActive: boolean;
138
+ createdAt: string;
139
+ updatedAt: string;
140
+ }
141
+ export interface CreateInspectionBinRequest {
142
+ name: string;
143
+ responseStatusCode?: number;
144
+ responseHeaders?: Record<string, string>;
145
+ responseBody?: string;
146
+ responseDelayMs?: number;
147
+ maxRequests?: number;
148
+ }
149
+ export interface InspectionRequest {
150
+ id: string;
151
+ binId: string;
152
+ method: string;
153
+ path: string;
154
+ queryString?: string;
155
+ headers: Record<string, string>;
156
+ body?: string;
157
+ contentType?: string;
158
+ clientIp?: string;
159
+ userAgent?: string;
160
+ receivedAt: string;
161
+ }
162
+ export interface PaginationParams {
163
+ limit?: number;
164
+ offset?: number;
165
+ }
166
+ export interface WebcronHealth {
167
+ status: string;
168
+ database: string;
169
+ timestamp: string;
170
+ }
@@ -0,0 +1,12 @@
1
+ import { Webhook, CreateWebhookRequest, UpdateWebhookRequest, Schedule, Execution, CreateScheduleRequest, PaginationParams } from './types';
2
+ export declare function listWebhooks(): Promise<Webhook[]>;
3
+ export declare function createWebhook(data: CreateWebhookRequest): Promise<Webhook>;
4
+ export declare function getWebhook(id: string): Promise<Webhook>;
5
+ export declare function updateWebhook(id: string, data: UpdateWebhookRequest): Promise<Webhook>;
6
+ export declare function deleteWebhook(id: string): Promise<void>;
7
+ export declare function testWebhook(id: string): Promise<{
8
+ executionId: string;
9
+ }>;
10
+ export declare function getWebhookExecutions(id: string, params?: PaginationParams): Promise<Execution[]>;
11
+ export declare function getWebhookSchedules(id: string): Promise<Schedule[]>;
12
+ export declare function createWebhookSchedule(webhookId: string, data: CreateScheduleRequest): Promise<Schedule>;
package/dist/config.d.ts CHANGED
@@ -6,6 +6,8 @@ export interface Config {
6
6
  workspaceId: string;
7
7
  userId: string;
8
8
  solutionId?: string;
9
+ solutionBranch?: string;
10
+ solutionBranchType?: string;
9
11
  websocketProvider?: IWebsocketProvider;
10
12
  }
11
13
  declare class ConfigSingleton {
package/dist/index.d.ts CHANGED
@@ -44,3 +44,5 @@ export type { TcnProcessDialData } from './api/tcn/processManualDial';
44
44
  export type { TcnConnectedParty } from './api/tcn/agentGetConnectedParty';
45
45
  export type { TcnCallData } from './api/tcn/getCallData';
46
46
  export type { FilterOnSenderId, EmailMessage, PageChunkEmailMessage, } from './api/emailEngine/getMessageBySenderId';
47
+ export type { Webhook, CreateWebhookRequest, UpdateWebhookRequest, Schedule, CreateScheduleRequest, UpdateScheduleRequest, Execution, ListExecutionsParams, Task, CreateTaskRequest, TaskProgressRequest, TaskSignalRequest, InspectionBin, CreateInspectionBinRequest, InspectionRequest, PaginationParams, WebcronHealth, } from './api/webcron/types';
48
+ export type { TriggerWorkflowRequest, TriggerWorkflowResponse, } from './api/webcron/trigger';