@bluecopa/core 0.1.4 → 0.1.6

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,34 @@
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
+ - [@bluecopa/core](#bluecopacore)
8
+ - [Table of Contents](#table-of-contents)
9
+ - [Version](#version)
10
+ - [Installation](#installation)
11
+ - [Requirements](#requirements)
12
+ - [Configuration](#configuration)
13
+ - [API Reference](#api-reference)
14
+ - [Dataset Module](#dataset-module)
15
+ - [Definition Module](#definition-module)
16
+ - [File Module](#file-module)
17
+ - [InputTable Module](#inputtable-module)
18
+ - [Metric Module](#metric-module)
19
+ - [User Module](#user-module)
20
+ - [Workbook Module](#workbook-module)
21
+ - [Workflow Module](#workflow-module)
22
+ - [Worksheet Module](#worksheet-module)
23
+ - [Examples](#examples)
24
+ - [1. Get Input Tables](#1-get-input-tables)
25
+ - [2. Get Workbooks by Type](#2-get-workbooks-by-type)
26
+ - [Development](#development)
27
+ - [Related Packages](#related-packages)
28
+
29
+ ## Version
30
+
31
+ Current version: 0.1.4
8
32
 
9
33
  ## Installation
10
34
 
@@ -12,301 +36,141 @@ A comprehensive TypeScript library for interacting with the BlueCopa platform, p
12
36
  npm install @bluecopa/core
13
37
  ```
14
38
 
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());
39
+ ## Requirements
38
40
 
39
- // Make API calls
40
- const userData = await copaApi.user.getLoggedInUserDetails();
41
- ```
41
+ - Node.js >= 18.0.0
42
+ - Dependencies:
43
+ - axios (1.12.0) - For HTTP requests
44
+ - lodash (4.17.21) - For utility functions
42
45
 
43
- ## API Reference
44
46
 
45
- ### Configuration
47
+ ## Configuration
46
48
 
47
- #### `copaSetConfig(config: Partial<Config>)`
49
+ The package uses a singleton-based configuration system to manage API settings. Configure it before making API calls.
48
50
 
49
- Sets the global configuration for the library.
51
+ Import and set the config:
50
52
 
51
53
  ```typescript
52
54
  import { copaSetConfig } from '@bluecopa/core';
53
55
 
54
56
  copaSetConfig({
55
- apiBaseUrl: 'https://api.bluecopa.com/api/v1',
56
- accessToken: 'eyJ...',
57
- workspaceId: 'workspace123'
57
+ apiBaseUrl: 'https://develop.bluecopa.com', // Base URL for API endpoints
58
+ accessToken: 'your-access-token', // Authentication token
59
+ workspaceId: 'your-workspace-id' // Current workspace identifier
58
60
  });
59
61
  ```
60
62
 
61
- #### `copaGetConfig(): Config`
63
+ - `copaSetConfig(partialConfig: Partial<Config>)`: Updates the configuration.
64
+ - `copaGetConfig()`: Retrieves the current configuration.
65
+ - `resetConfig()`: Resets to default empty values.
62
66
 
63
- Retrieves the current configuration.
67
+ The Config interface:
64
68
 
65
69
  ```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();
70
+ export interface Config {
71
+ apiBaseUrl: string;
72
+ accessToken: string;
73
+ workspaceId: string;
74
+ }
81
75
  ```
82
76
 
83
- #### Metric API (`copaApi.metric`)
77
+ ## API Reference
84
78
 
85
- ```typescript
86
- // Get metric data
87
- const metricId = '0UbwCn75pym1N47D89uS';
88
- const metricData = await copaApi.metric.getData(metricId);
89
- ```
79
+ 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
80
 
91
- #### Dataset API (`copaApi.dataset`)
81
+ ### Dataset Module
82
+ - `copaApi.dataset.getData()`: Retrieves specific dataset data by ID or parameters
83
+ - `copaApi.dataset.getDatasets()`: Fetches a list of datasets
84
+ - `copaApi.dataset.getSampleData()`: Gets sample data for datasets
92
85
 
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
- ```
86
+ 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
87
 
102
- #### Input Table API (`copaApi.inputTable`)
88
+ ### Definition Module
89
+ - `copaApi.definition.runDefinition()`: Executes a custom definition
90
+ - `copaApi.definition.runPublishedDefinition()`: Runs a published definition
91
+ - `copaApi.definition.runSampleDefinition()`: Executes a sample definition for testing
103
92
 
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
- ```
93
+ 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
94
 
116
- #### Other Available APIs
95
+ ### File Module
96
+ - `copaApi.files.getFileUrlByFileId(fileId: string)`: Generates a URL for a file by its ID
117
97
 
118
- - `copaApi.workflow` - Workflow operations
119
- - `copaApi.files` - File operations
120
- - `copaApi.definition` - Definition management
98
+ See: [`file/getFileUrlByFileId.ts`](src/api/file/getFileUrlByFileId.ts:1)
121
99
 
122
- ### Utilities (`copaUtils`)
100
+ ### InputTable Module
101
+ - `copaApi.inputTable.getData()`: Retrieves data from an input table
102
+ - `copaApi.inputTable.getInputTables()`: Fetches all input tables
103
+ - `copaApi.inputTable.getTableById(id: string)`: Gets a specific input table by ID
123
104
 
124
- #### Date Utilities
105
+ 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
106
 
126
- ```typescript
127
- import { copaUtils } from '@bluecopa/core';
107
+ ### Metric Module
108
+ - `copaApi.metric.getData()`: Fetches metric data
128
109
 
129
- // Format date to ISO string (YYYY-MM-DD)
130
- const formatted = copaUtils.formatDate(new Date());
131
- console.log(formatted); // "2023-12-25"
132
- ```
110
+ See: [`metric/getData.ts`](src/api/metric/getData.ts:1)
133
111
 
134
- #### Metric Utilities
112
+ ### User Module
113
+ - `copaApi.user.getLoggedInUserDetails()`: Retrieves details of the currently logged-in user
135
114
 
136
- ```typescript
137
- // Get metric definition
138
- const metricDefinition = copaUtils.getMetricDefinition(metricId);
139
- ```
115
+ See: [`user/getLoggedInUserDetails.ts`](src/api/user/getLoggedInUserDetails.ts:1)
140
116
 
141
- #### Input Table Utilities
117
+ ### Workbook Module
118
+ - `copaApi.workbook.getPublishedWorkbookById(id: string)`: Fetches a published workbook by ID
119
+ - `copaApi.workbook.getWorkbooksByType(type: string)`: Retrieves workbooks filtered by type
142
120
 
143
- ```typescript
144
- // Input table definition utilities
145
- const inputTableDef = copaUtils.inputTableUtils.getDefinition(tableId);
146
- ```
121
+ See: [`workbook/getPublishedWorkbookById.ts`](src/api/workbook/getPublishedWorkbookById.ts:1), [`workbook/getWorkbooksByType.ts`](src/api/workbook/getWorkbooksByType.ts:1)
147
122
 
148
- ### Tailwind Configuration (`copaTailwindConfig`)
123
+ ### Workflow Module
124
+ - `copaApi.workflow.getWorkflowInstanceStatusById(id: string)`: Checks the status of a workflow instance
125
+ - `copaApi.workflow.triggerHttpWorkflowById(id: string)`: Triggers an HTTP-based workflow
126
+ - `copaApi.workflow.triggerWorkflowById(id: string)`: Triggers a workflow by ID
149
127
 
150
- The library includes a pre-configured Tailwind CSS configuration optimized for BlueCopa applications:
128
+ 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
129
 
152
- ```typescript
153
- import { copaTailwindConfig } from '@bluecopa/core';
130
+ ### Worksheet Module
131
+ - `copaApi.worksheet.getWorksheets()`: Fetches all worksheets
132
+ - `copaApi.worksheet.getWorksheetsByType(type: string)`: Retrieves worksheets by type
154
133
 
155
- // Use in your tailwind.config.js
156
- module.exports = {
157
- ...copaTailwindConfig,
158
- // Your additional configurations
159
- };
160
- ```
134
+ See: [`worksheet/getWorksheets.ts`](src/api/worksheet/getWorksheets.ts:1), [`worksheet/getWorksheetsByType.ts`](src/api/worksheet/getWorksheetsByType.ts:1)
161
135
 
162
- ## Integration with TanStack Query
136
+ ## Examples
163
137
 
164
- The library works seamlessly with TanStack Query for state management and caching:
138
+ ### 1. Get Input Tables
139
+ Fetches all input tables from the API.
165
140
 
166
141
  ```typescript
167
- import { createQuery } from '@tanstack/svelte-query';
168
142
  import { copaApi } from '@bluecopa/core';
169
143
 
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:
144
+ // Configure first
145
+ copaSetConfig({ apiBaseUrl: 'https://api.example.com', accessToken: 'token', workspaceId: 'ws1' });
258
146
 
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
- }
147
+ // Use API
148
+ const { getInputTables } = copaApi.inputTable;
149
+ const { getWorkbooksByType } = copaApi.workbook;
266
150
  ```
267
151
 
268
- When using with TanStack Query, errors are automatically handled and exposed through the query state:
152
+ ### 2. Get Workbooks by Type
153
+ Retrieves workbooks filtered by a specific type.
269
154
 
270
155
  ```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
- });
156
+ import { copaApi } from '@bluecopa/core';
157
+ import type { Worksheet } from "$models/gen/Api";
277
158
 
278
- // Access error state
279
- if (userQuery.isError) {
280
- console.error('Query failed:', userQuery.error);
159
+ try {
160
+ const workbooks = await copaApi.workbook.getWorkbooksByType('dashboard' as Worksheet["type"]);
161
+ console.log(workbooks); // Array of Worksheet
162
+ } catch (error: any) {
163
+ console.error(error.message, error.status);
281
164
  }
282
165
  ```
283
166
 
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
167
  ## Development
299
168
 
300
- ### Building the Library
301
-
302
- ```bash
303
- npm run build
304
- ```
305
-
306
- ### Development Mode
169
+ - Run the build: `npm run build` (in the root or package-specific script)
170
+ - TypeScript configuration: See [tsconfig.json](tsconfig.json)
171
+ - Vite configuration: See [vite.config.ts](vite.config.ts)
307
172
 
308
- ```bash
309
- npm run dev
310
- ```
173
+ ## Related Packages
311
174
 
312
- This will build the library in watch mode, automatically rebuilding when files change.
175
+ - [@bluecopa/react](packages/react): React hooks that utilize core APIs
176
+ - [@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,4 +6,4 @@ export declare const runDefinition: (props: {
6
6
  variable: string;
7
7
  source?: CancelTokenSource;
8
8
  limit?: number;
9
- }) => Promise<import('axios').AxiosResponse<any, any>>;
9
+ }) => Promise<import('axios').AxiosResponse<any, any, {}>>;
@@ -8,4 +8,4 @@ export declare const runPublishedDefinition: (props: {
8
8
  variable: string;
9
9
  inputs: object;
10
10
  source?: CancelTokenSource;
11
- }) => Promise<import('axios').AxiosResponse<any, any>>;
11
+ }) => Promise<import('axios').AxiosResponse<any, any, {}>>;
@@ -3,4 +3,4 @@ export declare const runSampleDefinition: (props: {
3
3
  dataFilter: "valid_data" | "invalid_data" | "all_data";
4
4
  duplicateColGroups?: string[];
5
5
  datasetType?: string;
6
- }) => Promise<import('axios').AxiosResponse<any, any>>;
6
+ }) => Promise<import('axios').AxiosResponse<any, any, {}>>;
@@ -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';