@bluecopa/core 0.1.4 → 0.1.5

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
@@ -1,10 +1,29 @@
1
1
  # @bluecopa/core
2
2
 
3
- A comprehensive TypeScript library for interacting with the BlueCopa platform, providing utilities, API clients, and configuration management.
4
-
5
- **Current Version:** 0.1.2
6
- **Node.js:** >=18.0.0
7
- **Dependencies:** axios, lodash
3
+ The core package provides essential API utilities and functions for data management, workbook handling, dataset operations, and definition execution in the Bluecopa platform.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Version](#version)
8
+ - [Installation](#installation)
9
+ - [Requirements](#requirements)
10
+ - [Configuration](#configuration)
11
+ - [API Reference](#api-reference)
12
+ - [Dataset Module](#dataset-module)
13
+ - [Definition Module](#definition-module)
14
+ - [File Module](#file-module)
15
+ - [InputTable Module](#inputtable-module)
16
+ - [Metric Module](#metric-module)
17
+ - [User Module](#user-module)
18
+ - [Workbook Module](#workbook-module)
19
+ - [Workflow Module](#workflow-module)
20
+ - [Worksheet Module](#worksheet-module)
21
+ - [Development](#development)
22
+ - [Related Packages](#related-packages)
23
+
24
+ ## Version
25
+
26
+ Current version: 0.1.4
8
27
 
9
28
  ## Installation
10
29
 
@@ -12,301 +31,141 @@ A comprehensive TypeScript library for interacting with the BlueCopa platform, p
12
31
  npm install @bluecopa/core
13
32
  ```
14
33
 
15
- ## Quick Start
16
-
17
- ### 1. Configuration
18
-
19
- Before using any API functions, you need to configure the library with your credentials:
20
-
21
- ```typescript
22
- import { copaSetConfig } from '@bluecopa/core';
23
-
24
- copaSetConfig({
25
- apiBaseUrl: 'https://your-api-base-url.com/api/v1',
26
- accessToken: 'your-access-token',
27
- workspaceId: 'your-workspace-id'
28
- });
29
- ```
30
-
31
- ### 2. Basic Usage
32
-
33
- ```typescript
34
- import { copaApi, copaUtils, copaTailwindConfig } from '@bluecopa/core';
35
-
36
- // Use utility functions
37
- const formattedDate = copaUtils.formatDate(new Date());
34
+ ## Requirements
38
35
 
39
- // Make API calls
40
- const userData = await copaApi.user.getLoggedInUserDetails();
41
- ```
36
+ - Node.js >= 18.0.0
37
+ - Dependencies:
38
+ - axios (1.11.0) - For HTTP requests
39
+ - lodash (4.17.21) - For utility functions
42
40
 
43
- ## API Reference
44
41
 
45
- ### Configuration
42
+ ## Configuration
46
43
 
47
- #### `copaSetConfig(config: Partial<Config>)`
44
+ The package uses a singleton-based configuration system to manage API settings. Configure it before making API calls.
48
45
 
49
- Sets the global configuration for the library.
46
+ Import and set the config:
50
47
 
51
48
  ```typescript
52
49
  import { copaSetConfig } from '@bluecopa/core';
53
50
 
54
51
  copaSetConfig({
55
- apiBaseUrl: 'https://api.bluecopa.com/api/v1',
56
- accessToken: 'eyJ...',
57
- workspaceId: 'workspace123'
52
+ apiBaseUrl: 'https://api.bluecopa.com', // Base URL for API endpoints
53
+ accessToken: 'your-access-token', // Authentication token
54
+ workspaceId: 'your-workspace-id' // Current workspace identifier
58
55
  });
59
56
  ```
60
57
 
61
- #### `copaGetConfig(): Config`
58
+ - `copaSetConfig(partialConfig: Partial<Config>)`: Updates the configuration.
59
+ - `copaGetConfig()`: Retrieves the current configuration.
60
+ - `resetConfig()`: Resets to default empty values.
62
61
 
63
- Retrieves the current configuration.
62
+ The Config interface:
64
63
 
65
64
  ```typescript
66
- import { copaGetConfig } from '@bluecopa/core';
67
-
68
- const config = copaGetConfig();
69
- console.log(config.apiBaseUrl);
70
- ```
71
-
72
- ### API Client (`copaApi`)
73
-
74
- The library provides a comprehensive API client with the following modules:
75
-
76
- #### User API (`copaApi.user`)
77
-
78
- ```typescript
79
- // Get logged-in user details
80
- const userDetails = await copaApi.user.getLoggedInUserDetails();
65
+ export interface Config {
66
+ apiBaseUrl: string;
67
+ accessToken: string;
68
+ workspaceId: string;
69
+ }
81
70
  ```
82
71
 
83
- #### Metric API (`copaApi.metric`)
72
+ ## API Reference
84
73
 
85
- ```typescript
86
- // Get metric data
87
- const metricId = '0UbwCn75pym1N47D89uS';
88
- const metricData = await copaApi.metric.getData(metricId);
89
- ```
74
+ All API functions are asynchronous and use the shared `apiClient` for HTTP requests. They handle errors by throwing objects with `message` and `status`. Access via `copaApi.moduleName.functionName()`.
90
75
 
91
- #### Dataset API (`copaApi.dataset`)
76
+ ### Dataset Module
77
+ - `copaApi.dataset.getData()`: Retrieves specific dataset data by ID or parameters
78
+ - `copaApi.dataset.getDatasets()`: Fetches a list of datasets
79
+ - `copaApi.dataset.getSampleData()`: Gets sample data for datasets
92
80
 
93
- ```typescript
94
- // Get dataset sample data
95
- const datasetId = '0UvoE3CHwqYqzrbGdgs1_large_transaction_dataset_csv';
96
- const datasetData = await copaApi.dataset.getSampleData({
97
- datasetId,
98
- dataFilter: 'all_data'
99
- });
100
- ```
81
+ See: [`dataset/getData.ts`](src/api/dataset/getData.ts:1), [`dataset/getSampleData.ts`](src/api/dataset/getSampleData.ts:1), [`dataset/getDatasets.ts`](src/api/dataset/getDatasets.ts:1)
101
82
 
102
- #### Input Table API (`copaApi.inputTable`)
83
+ ### Definition Module
84
+ - `copaApi.definition.runDefinition()`: Executes a custom definition
85
+ - `copaApi.definition.runPublishedDefinition()`: Runs a published definition
86
+ - `copaApi.definition.runSampleDefinition()`: Executes a sample definition for testing
103
87
 
104
- ```typescript
105
- // Get input table data
106
- const inputTableData = await copaApi.inputTable.getData({
107
- inputTableId: '0Ub41b684ku2i4vftSg4',
108
- inputTableViewId: '0Ub41b58wvLgQecoRWww',
109
- limitParams: {
110
- limit: 2000,
111
- limitFrom: 'top'
112
- }
113
- });
114
- ```
88
+ See: [`definition/runPublishedDefinition.ts`](src/api/definition/runPublishedDefinition.ts:1), [`definition/runSampleDefinition.ts`](src/api/definition/runSampleDefinition.ts:1), [`definition/runDefinition.ts`](src/api/definition/runDefinition.ts:1)
115
89
 
116
- #### Other Available APIs
90
+ ### File Module
91
+ - `copaApi.files.getFileUrlByFileId(fileId: string)`: Generates a URL for a file by its ID
117
92
 
118
- - `copaApi.workflow` - Workflow operations
119
- - `copaApi.files` - File operations
120
- - `copaApi.definition` - Definition management
93
+ See: [`file/getFileUrlByFileId.ts`](src/api/file/getFileUrlByFileId.ts:1)
121
94
 
122
- ### Utilities (`copaUtils`)
95
+ ### InputTable Module
96
+ - `copaApi.inputTable.getData()`: Retrieves data from an input table
97
+ - `copaApi.inputTable.getInputTables()`: Fetches all input tables
98
+ - `copaApi.inputTable.getTableById(id: string)`: Gets a specific input table by ID
123
99
 
124
- #### Date Utilities
100
+ See: [`inputTable/getData.ts`](src/api/inputTable/getData.ts:1), [`inputTable/getInputTables.ts`](src/api/inputTable/getInputTables.ts:1), [`inputTable/getTableById.ts`](src/api/inputTable/getTableById.ts:1)
125
101
 
126
- ```typescript
127
- import { copaUtils } from '@bluecopa/core';
102
+ ### Metric Module
103
+ - `copaApi.metric.getData()`: Fetches metric data
128
104
 
129
- // Format date to ISO string (YYYY-MM-DD)
130
- const formatted = copaUtils.formatDate(new Date());
131
- console.log(formatted); // "2023-12-25"
132
- ```
105
+ See: [`metric/getData.ts`](src/api/metric/getData.ts:1)
133
106
 
134
- #### Metric Utilities
107
+ ### User Module
108
+ - `copaApi.user.getLoggedInUserDetails()`: Retrieves details of the currently logged-in user
135
109
 
136
- ```typescript
137
- // Get metric definition
138
- const metricDefinition = copaUtils.getMetricDefinition(metricId);
139
- ```
110
+ See: [`user/getLoggedInUserDetails.ts`](src/api/user/getLoggedInUserDetails.ts:1)
140
111
 
141
- #### Input Table Utilities
112
+ ### Workbook Module
113
+ - `copaApi.workbook.getPublishedWorkbookById(id: string)`: Fetches a published workbook by ID
114
+ - `copaApi.workbook.getWorkbooksByType(type: string)`: Retrieves workbooks filtered by type
142
115
 
143
- ```typescript
144
- // Input table definition utilities
145
- const inputTableDef = copaUtils.inputTableUtils.getDefinition(tableId);
146
- ```
116
+ See: [`workbook/getPublishedWorkbookById.ts`](src/api/workbook/getPublishedWorkbookById.ts:1), [`workbook/getWorkbooksByType.ts`](src/api/workbook/getWorkbooksByType.ts:1)
147
117
 
148
- ### Tailwind Configuration (`copaTailwindConfig`)
118
+ ### Workflow Module
119
+ - `copaApi.workflow.getWorkflowInstanceStatusById(id: string)`: Checks the status of a workflow instance
120
+ - `copaApi.workflow.triggerHttpWorkflowById(id: string)`: Triggers an HTTP-based workflow
121
+ - `copaApi.workflow.triggerWorkflowById(id: string)`: Triggers a workflow by ID
149
122
 
150
- The library includes a pre-configured Tailwind CSS configuration optimized for BlueCopa applications:
123
+ See: [`workflow/triggerHttpWorkflowById.ts`](src/api/workflow/triggerHttpWorkflowById.ts:1), [`workflow/triggerWorkflowById.ts`](src/api/workflow/triggerWorkflowById.ts:1), [`workflow/getWorkflowInstanceStatusById.ts`](src/api/workflow/getWorkflowInstanceStatusById.ts:1)
151
124
 
152
- ```typescript
153
- import { copaTailwindConfig } from '@bluecopa/core';
125
+ ### Worksheet Module
126
+ - `copaApi.worksheet.getWorksheets()`: Fetches all worksheets
127
+ - `copaApi.worksheet.getWorksheetsByType(type: string)`: Retrieves worksheets by type
154
128
 
155
- // Use in your tailwind.config.js
156
- module.exports = {
157
- ...copaTailwindConfig,
158
- // Your additional configurations
159
- };
160
- ```
129
+ See: [`worksheet/getWorksheets.ts`](src/api/worksheet/getWorksheets.ts:1), [`worksheet/getWorksheetsByType.ts`](src/api/worksheet/getWorksheetsByType.ts:1)
161
130
 
162
- ## Integration with TanStack Query
131
+ ## Examples
163
132
 
164
- The library works seamlessly with TanStack Query for state management and caching:
133
+ ### 1. Get Input Tables
134
+ Fetches all input tables from the API.
165
135
 
166
136
  ```typescript
167
- import { createQuery } from '@tanstack/svelte-query';
168
137
  import { copaApi } from '@bluecopa/core';
169
138
 
170
- // Create a query for user data
171
- export const createUserDetailsQuery = (enabled = true) => {
172
- return createQuery({
173
- queryKey: ['user'],
174
- queryFn: async () => {
175
- return await copaApi.user.getLoggedInUserDetails();
176
- },
177
- enabled,
178
- staleTime: 1000 * 60 * 5, // 5 minutes
179
- retry: 2
180
- });
181
- };
182
-
183
- // Create a query for metric data
184
- export const createMetricDataQuery = (metricId: string, enabled = true) => {
185
- return createQuery({
186
- queryKey: ['metricData', metricId],
187
- queryFn: async () => {
188
- return await copaApi.metric.getData(metricId);
189
- },
190
- enabled,
191
- staleTime: 1000 * 60 * 5, // 5 minutes
192
- retry: 2
193
- });
194
- };
195
- ```
196
-
197
- ## Complete Example
198
-
199
- Here's a complete example of using the library in a Svelte component:
200
-
201
- ```svelte
202
- <script lang="ts">
203
- import { onMount } from 'svelte';
204
- import {
205
- copaSetConfig,
206
- copaApi,
207
- copaUtils
208
- } from '@bluecopa/core';
209
- import { createQuery } from '@tanstack/svelte-query';
210
-
211
- let isConfigured = false;
212
- let formattedDate = '';
213
-
214
- onMount(async () => {
215
- // Configure the library
216
- copaSetConfig({
217
- apiBaseUrl: `${window.location.origin}/api/v1`,
218
- accessToken: 'your-access-token',
219
- workspaceId: 'your-workspace-id'
220
- });
221
-
222
- isConfigured = true;
223
- formattedDate = copaUtils.formatDate(new Date());
224
- });
225
-
226
- // Create reactive queries
227
- $: userQuery = isConfigured ? createQuery({
228
- queryKey: ['user'],
229
- queryFn: () => copaApi.user.getLoggedInUserDetails()
230
- }) : null;
231
-
232
- $: metricQuery = isConfigured ? createQuery({
233
- queryKey: ['metric', 'metricId123'],
234
- queryFn: () => copaApi.metric.getData('metricId123')
235
- }) : null;
236
- </script>
237
-
238
- <main>
239
- <h1>BlueCopa Dashboard</h1>
240
-
241
- <p>Today's date: {formattedDate}</p>
242
-
243
- {#if userQuery}
244
- {#if $userQuery.isLoading}
245
- <p>Loading user data...</p>
246
- {:else if $userQuery.isError}
247
- <p>Error: {$userQuery.error.message}</p>
248
- {:else if $userQuery.isSuccess}
249
- <p>Welcome, {$userQuery.data.name}!</p>
250
- {/if}
251
- {/if}
252
- </main>
253
- ```
254
-
255
- ## Error Handling
256
-
257
- The library includes built-in error handling. API calls will throw errors that can be caught and handled:
139
+ // Configure first
140
+ copaSetConfig({ apiBaseUrl: 'https://api.example.com', accessToken: 'token', workspaceId: 'ws1' });
258
141
 
259
- ```typescript
260
- try {
261
- const userData = await copaApi.user.getLoggedInUserDetails();
262
- console.log(userData);
263
- } catch (error) {
264
- console.error('Failed to fetch user data:', error);
265
- }
142
+ // Use API
143
+ const { getInputTables } = copaApi.inputTable;
144
+ const { getWorkbooksByType } = copaApi.workbook;
266
145
  ```
267
146
 
268
- When using with TanStack Query, errors are automatically handled and exposed through the query state:
147
+ ### 2. Get Workbooks by Type
148
+ Retrieves workbooks filtered by a specific type.
269
149
 
270
150
  ```typescript
271
- const userQuery = createQuery({
272
- queryKey: ['user'],
273
- queryFn: () => copaApi.user.getLoggedInUserDetails(),
274
- retry: 2,
275
- retryDelay: (attemptIndex) => Math.min(1000 * 2 ** attemptIndex, 30000)
276
- });
151
+ import { copaApi } from '@bluecopa/core';
152
+ import type { Worksheet } from "$models/gen/Api";
277
153
 
278
- // Access error state
279
- if (userQuery.isError) {
280
- console.error('Query failed:', userQuery.error);
154
+ try {
155
+ const workbooks = await copaApi.workbook.getWorkbooksByType('dashboard' as Worksheet["type"]);
156
+ console.log(workbooks); // Array of Worksheet
157
+ } catch (error: any) {
158
+ console.error(error.message, error.status);
281
159
  }
282
160
  ```
283
161
 
284
- ## TypeScript Support
285
-
286
- The library is written in TypeScript and includes full type definitions:
287
-
288
- ```typescript
289
- import type { Config } from '@bluecopa/core';
290
-
291
- const config: Config = {
292
- apiBaseUrl: 'https://api.example.com',
293
- accessToken: 'token',
294
- workspaceId: 'workspace'
295
- };
296
- ```
297
-
298
162
  ## Development
299
163
 
300
- ### Building the Library
301
-
302
- ```bash
303
- npm run build
304
- ```
305
-
306
- ### Development Mode
164
+ - Run the build: `npm run build` (in the root or package-specific script)
165
+ - TypeScript configuration: See [tsconfig.json](tsconfig.json)
166
+ - Vite configuration: See [vite.config.ts](vite.config.ts)
307
167
 
308
- ```bash
309
- npm run dev
310
- ```
168
+ ## Related Packages
311
169
 
312
- This will build the library in watch mode, automatically rebuilding when files change.
170
+ - [@bluecopa/react](packages/react): React hooks that utilize core APIs
171
+ - [@bluecopa/boilerplate](packages/boilerplate/react): React boilerplate templates for Bluecopa applications
@@ -0,0 +1,2 @@
1
+ import { Worksheet } from '../../../../models/src/lib/gen/Api';
2
+ export declare const getAllDatasets: () => Promise<Worksheet[]>;
@@ -1,2 +1,3 @@
1
1
  export * from './getData';
2
2
  export * from './getSampleData';
3
+ export * from './getDatasets';
@@ -6,3 +6,5 @@ export * as definition from './definition';
6
6
  export * as metric from './metric';
7
7
  export * as dataset from './dataset';
8
8
  export * as inputTable from './inputTable';
9
+ export * as workbook from './workbook';
10
+ export * as worksheet from './worksheet';
@@ -0,0 +1,2 @@
1
+ import { InputTable } from '../../../../models/src/lib/gen/Api';
2
+ export declare const getInputTables: () => Promise<InputTable[]>;
@@ -1,2 +1,3 @@
1
1
  export * from './getData';
2
2
  export * from './getTableById';
3
+ export * from './getInputTables';
@@ -0,0 +1,2 @@
1
+ import { Worksheet } from '../../../../models/src/lib/gen/Api';
2
+ export declare const getWorkbooksByType: (type: Worksheet["type"]) => Promise<Worksheet[]>;
@@ -0,0 +1,2 @@
1
+ export * from './getWorkbooksByType';
2
+ export * from './getPublishedWorkbookById';
@@ -0,0 +1,31 @@
1
+ export type WorkflowStatusRequest = ReadonlyArray<{
2
+ instanceId: string;
3
+ parentId: string;
4
+ }>;
5
+ export declare enum WorkflowStatus {
6
+ Succeeded = "Succeeded",
7
+ Failed = "Failed",
8
+ Running = "Running",
9
+ NotFound = "NotFound"
10
+ }
11
+ export type StepInfo = {
12
+ stepId: string;
13
+ name: string;
14
+ stepOutput: Record<string, any>;
15
+ };
16
+ export type WorkflowStatusResponse = {
17
+ instanceId: string;
18
+ processName: string;
19
+ parentId: string;
20
+ status: WorkflowStatus;
21
+ message: string;
22
+ data: {
23
+ completed: StepInfo[];
24
+ running: StepInfo[];
25
+ failed?: StepInfo[];
26
+ };
27
+ completedAt: string;
28
+ error?: string;
29
+ };
30
+ export type WorkflowStatusResponses = ReadonlyArray<WorkflowStatusResponse>;
31
+ export declare const getWorkflowInstanceStatusById: (request: WorkflowStatusRequest) => Promise<WorkflowStatusResponses>;
@@ -1,2 +1,3 @@
1
- export * from './triggerHttpWorkflow';
2
- export * from './triggerWorkflow';
1
+ export * from './triggerHttpWorkflowById';
2
+ export * from './triggerWorkflowById';
3
+ export * from './getWorkflowInstanceStatusById';
@@ -17,4 +17,4 @@ export interface TriggerHttpWorkflowResponse {
17
17
  * @returns Promise<TriggerHttpWorkflowResponse> The triggered workflow details
18
18
  * @throws Error if the request fails
19
19
  */
20
- export declare function triggerHttpWorkflow({ data, triggerId, }: TriggerHttpWorkflowRequest): Promise<TriggerHttpWorkflowResponse>;
20
+ export declare function triggerHttpWorkflowById({ data, triggerId, }: TriggerHttpWorkflowRequest): Promise<TriggerHttpWorkflowResponse>;
@@ -20,4 +20,4 @@ export interface TriggerWorkflowResponse {
20
20
  * @returns Promise<TriggerWorkflowResponse> The triggered workflow details
21
21
  * @throws Error if the request fails
22
22
  */
23
- export declare function triggerWorkflow({ parentId, triggerBy, }: TriggerWorkflowRequest): Promise<TriggerWorkflowResponse>;
23
+ export declare function triggerWorkflowById({ parentId, triggerBy, }: TriggerWorkflowRequest): Promise<TriggerWorkflowResponse>;
@@ -0,0 +1,2 @@
1
+ import { Worksheet } from '../../../../models/src/lib/gen/Api';
2
+ export declare const getWorksheetsByType: (type: Worksheet["type"]) => Promise<Worksheet[]>;
@@ -1 +1,2 @@
1
1
  export * from './getWorksheets';
2
+ export * from './getWorksheetsByType';