@bluecopa/core 0.1.2

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.
Files changed (47) hide show
  1. package/README.md +312 -0
  2. package/dist/api/client.d.ts +2 -0
  3. package/dist/api/dataset/getData.d.ts +5 -0
  4. package/dist/api/dataset/getSampleData.d.ts +8 -0
  5. package/dist/api/dataset/index.d.ts +2 -0
  6. package/dist/api/definition/index.d.ts +3 -0
  7. package/dist/api/definition/runDefinition.d.ts +9 -0
  8. package/dist/api/definition/runPublishedDefinition.d.ts +11 -0
  9. package/dist/api/definition/runSampleDefinition.d.ts +6 -0
  10. package/dist/api/file/getFileUrlByFileId.d.ts +18 -0
  11. package/dist/api/file/index.d.ts +1 -0
  12. package/dist/api/index.d.ts +8 -0
  13. package/dist/api/inputTable/getData.d.ts +11 -0
  14. package/dist/api/inputTable/getTableById.d.ts +2 -0
  15. package/dist/api/inputTable/index.d.ts +2 -0
  16. package/dist/api/metric/getData.d.ts +10 -0
  17. package/dist/api/metric/index.d.ts +1 -0
  18. package/dist/api/user/getLoggedInUserDetails.d.ts +25 -0
  19. package/dist/api/user/index.d.ts +1 -0
  20. package/dist/api/workbook/getPublishedWorkbookById.d.ts +5 -0
  21. package/dist/api/workbook/index.d.ts +0 -0
  22. package/dist/api/workflow/index.d.ts +2 -0
  23. package/dist/api/workflow/triggerHttpWorkflow.d.ts +20 -0
  24. package/dist/api/workflow/triggerWorkflow.d.ts +23 -0
  25. package/dist/api/worksheet/getWorksheets.d.ts +2 -0
  26. package/dist/api/worksheet/index.d.ts +1 -0
  27. package/dist/config.d.ts +18 -0
  28. package/dist/index.d.ts +4 -0
  29. package/dist/index.es.js +2321 -0
  30. package/dist/index.es.js.map +1 -0
  31. package/dist/tailwind/bluecopa.config.d.ts +164 -0
  32. package/dist/types/workbook.d.ts +13 -0
  33. package/dist/utils/date.d.ts +1 -0
  34. package/dist/utils/file/downloadFile.d.ts +1 -0
  35. package/dist/utils/index.d.ts +3 -0
  36. package/dist/utils/inputTable/index.d.ts +1 -0
  37. package/dist/utils/inputTable/inputTableDefinition.d.ts +35 -0
  38. package/dist/utils/metric/analysisMethods.d.ts +424 -0
  39. package/dist/utils/metric/buildVariable.d.ts +19 -0
  40. package/dist/utils/metric/displayNamesUtil.d.ts +7 -0
  41. package/dist/utils/metric/filterUtils.d.ts +22 -0
  42. package/dist/utils/metric/getMetricDefinition.d.ts +28 -0
  43. package/dist/utils/metric/hydrateWorksheet.d.ts +2 -0
  44. package/dist/utils/metric/inputNameUtil.d.ts +1 -0
  45. package/dist/utils/metric/mergeFilterService.d.ts +34 -0
  46. package/dist/utils/metric/variableUtils.d.ts +5 -0
  47. package/package.json +39 -0
package/README.md ADDED
@@ -0,0 +1,312 @@
1
+ # @bluecopa/core
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
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @bluecopa/core
13
+ ```
14
+
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());
38
+
39
+ // Make API calls
40
+ const userData = await copaApi.user.getLoggedInUserDetails();
41
+ ```
42
+
43
+ ## API Reference
44
+
45
+ ### Configuration
46
+
47
+ #### `copaSetConfig(config: Partial<Config>)`
48
+
49
+ Sets the global configuration for the library.
50
+
51
+ ```typescript
52
+ import { copaSetConfig } from '@bluecopa/core';
53
+
54
+ copaSetConfig({
55
+ apiBaseUrl: 'https://api.bluecopa.com/api/v1',
56
+ accessToken: 'eyJ...',
57
+ workspaceId: 'workspace123'
58
+ });
59
+ ```
60
+
61
+ #### `copaGetConfig(): Config`
62
+
63
+ Retrieves the current configuration.
64
+
65
+ ```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();
81
+ ```
82
+
83
+ #### Metric API (`copaApi.metric`)
84
+
85
+ ```typescript
86
+ // Get metric data
87
+ const metricId = '0UbwCn75pym1N47D89uS';
88
+ const metricData = await copaApi.metric.getData(metricId);
89
+ ```
90
+
91
+ #### Dataset API (`copaApi.dataset`)
92
+
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
+ ```
101
+
102
+ #### Input Table API (`copaApi.inputTable`)
103
+
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
+ ```
115
+
116
+ #### Other Available APIs
117
+
118
+ - `copaApi.workflow` - Workflow operations
119
+ - `copaApi.files` - File operations
120
+ - `copaApi.definition` - Definition management
121
+
122
+ ### Utilities (`copaUtils`)
123
+
124
+ #### Date Utilities
125
+
126
+ ```typescript
127
+ import { copaUtils } from '@bluecopa/core';
128
+
129
+ // Format date to ISO string (YYYY-MM-DD)
130
+ const formatted = copaUtils.formatDate(new Date());
131
+ console.log(formatted); // "2023-12-25"
132
+ ```
133
+
134
+ #### Metric Utilities
135
+
136
+ ```typescript
137
+ // Get metric definition
138
+ const metricDefinition = copaUtils.getMetricDefinition(metricId);
139
+ ```
140
+
141
+ #### Input Table Utilities
142
+
143
+ ```typescript
144
+ // Input table definition utilities
145
+ const inputTableDef = copaUtils.inputTableUtils.getDefinition(tableId);
146
+ ```
147
+
148
+ ### Tailwind Configuration (`copaTailwindConfig`)
149
+
150
+ The library includes a pre-configured Tailwind CSS configuration optimized for BlueCopa applications:
151
+
152
+ ```typescript
153
+ import { copaTailwindConfig } from '@bluecopa/core';
154
+
155
+ // Use in your tailwind.config.js
156
+ module.exports = {
157
+ ...copaTailwindConfig,
158
+ // Your additional configurations
159
+ };
160
+ ```
161
+
162
+ ## Integration with TanStack Query
163
+
164
+ The library works seamlessly with TanStack Query for state management and caching:
165
+
166
+ ```typescript
167
+ import { createQuery } from '@tanstack/svelte-query';
168
+ import { copaApi } from '@bluecopa/core';
169
+
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:
258
+
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
+ }
266
+ ```
267
+
268
+ When using with TanStack Query, errors are automatically handled and exposed through the query state:
269
+
270
+ ```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
+ });
277
+
278
+ // Access error state
279
+ if (userQuery.isError) {
280
+ console.error('Query failed:', userQuery.error);
281
+ }
282
+ ```
283
+
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
+ ## Development
299
+
300
+ ### Building the Library
301
+
302
+ ```bash
303
+ npm run build
304
+ ```
305
+
306
+ ### Development Mode
307
+
308
+ ```bash
309
+ npm run dev
310
+ ```
311
+
312
+ This will build the library in watch mode, automatically rebuilding when files change.
@@ -0,0 +1,2 @@
1
+ import { AxiosInstance } from 'axios';
2
+ export declare const apiClient: AxiosInstance;
@@ -0,0 +1,5 @@
1
+ export declare const getData: (datasetId: string, options?: {
2
+ limit?: number;
3
+ }) => Promise<{
4
+ data: any;
5
+ }>;
@@ -0,0 +1,8 @@
1
+ export declare const getSampleData: ({ datasetId, dataFilter, duplicateColGroups, datasetType, }: {
2
+ datasetId: string;
3
+ dataFilter: "valid_data" | "invalid_data" | "all_data";
4
+ duplicateColGroups?: string[];
5
+ datasetType?: string;
6
+ }) => Promise<{
7
+ data: any;
8
+ }>;
@@ -0,0 +1,2 @@
1
+ export * from './getData';
2
+ export * from './getSampleData';
@@ -0,0 +1,3 @@
1
+ export * from './runPublishedDefinition';
2
+ export * from './runSampleDefinition';
3
+ export * from './runDefinition';
@@ -0,0 +1,9 @@
1
+ import { CancelTokenSource } from 'axios';
2
+ import { Definition, Inputs } from '../../../../models/src/lib/ui-models/definitionModel';
3
+ export declare const runDefinition: (props: {
4
+ inputs: Inputs;
5
+ definition: Definition;
6
+ variable: string;
7
+ source?: CancelTokenSource;
8
+ limit?: number;
9
+ }) => Promise<import('axios').AxiosResponse<any, any>>;
@@ -0,0 +1,11 @@
1
+ import { CancelTokenSource } from 'axios';
2
+ export declare const runPublishedDefinition: (props: {
3
+ describe: string;
4
+ sheet: {
5
+ id: string;
6
+ lastModifiedDate: string;
7
+ };
8
+ variable: string;
9
+ inputs: object;
10
+ source?: CancelTokenSource;
11
+ }) => Promise<import('axios').AxiosResponse<any, any>>;
@@ -0,0 +1,6 @@
1
+ export declare const runSampleDefinition: (props: {
2
+ datasetId: string;
3
+ dataFilter: "valid_data" | "invalid_data" | "all_data";
4
+ duplicateColGroups?: string[];
5
+ datasetType?: string;
6
+ }) => Promise<import('axios').AxiosResponse<any, any>>;
@@ -0,0 +1,18 @@
1
+ export interface GetFileUrlRequest {
2
+ key: string;
3
+ contentType: string;
4
+ method: 'GET' | 'PUT' | 'POST';
5
+ }
6
+ export interface GetFileUrlResponse {
7
+ url: string;
8
+ }
9
+ /**
10
+ * Gets a signed URL for a file by its key
11
+ * @param params - The file request parameters
12
+ * @param params.key - The file key/path in storage
13
+ * @param params.contentType - The content type of the file
14
+ * @param params.method - The HTTP method (GET, PUT, POST)
15
+ * @returns Promise<GetFileUrlResponse> The signed URL for the file
16
+ * @throws Error if the request fails
17
+ */
18
+ export declare function getFileUrlByFileId({ key, contentType, method, }: GetFileUrlRequest): Promise<GetFileUrlResponse>;
@@ -0,0 +1 @@
1
+ export * from './getFileUrlByFileId';
@@ -0,0 +1,8 @@
1
+ export { apiClient } from './client';
2
+ export * as user from './user';
3
+ export * as workflow from './workflow';
4
+ export * as files from './file';
5
+ export * as definition from './definition';
6
+ export * as metric from './metric';
7
+ export * as dataset from './dataset';
8
+ export * as inputTable from './inputTable';
@@ -0,0 +1,11 @@
1
+ import { LimitOptions, SortOptions } from '../../../../models/src/lib/ui-models/workbookModel';
2
+ export declare const getData: ({ inputTableId: inputTableWorkbookId, inputTableViewId, pageParams, limitParams, sortParams, offsetParam, }: {
3
+ inputTableId: string;
4
+ inputTableViewId: string;
5
+ pageParams?: any;
6
+ limitParams?: LimitOptions;
7
+ sortParams?: SortOptions;
8
+ offsetParam?: number;
9
+ }) => Promise<any[] | {
10
+ data: any;
11
+ }>;
@@ -0,0 +1,2 @@
1
+ import { Workbook } from '../../../../models/src/lib/gen/Api';
2
+ export declare const getTableById: (tableId: string) => Promise<Workbook>;
@@ -0,0 +1,2 @@
1
+ export * from './getData';
2
+ export * from './getTableById';
@@ -0,0 +1,10 @@
1
+ export declare const getData: (metricSheetId: string, options?: {
2
+ groupKeys?: string[];
3
+ isKPI?: boolean;
4
+ plotAsTrend?: boolean;
5
+ stringValue?: boolean;
6
+ }) => Promise<{
7
+ data?: undefined;
8
+ } | {
9
+ data: object[];
10
+ }>;
@@ -0,0 +1 @@
1
+ export * from './getData';
@@ -0,0 +1,25 @@
1
+ export interface UserDetails {
2
+ id: string;
3
+ email: string;
4
+ name: string;
5
+ role: string;
6
+ workspaceId: string;
7
+ avatar?: string;
8
+ preferences?: Record<string, any>;
9
+ lastLoginAt?: string;
10
+ createdAt: string;
11
+ updatedAt: string;
12
+ }
13
+ export interface ApiResponse<T> {
14
+ success: boolean;
15
+ data: T;
16
+ message?: string;
17
+ }
18
+ /**
19
+ * Fetches the logged-in user's details from the API
20
+ * @returns Promise<{ user: UserDetails }> The user's details
21
+ * @throws Error if the request fails or user is not authenticated
22
+ */
23
+ export declare function getLoggedInUserDetails(): Promise<{
24
+ user: UserDetails;
25
+ }>;
@@ -0,0 +1 @@
1
+ export { getLoggedInUserDetails, type UserDetails } from './getLoggedInUserDetails';
@@ -0,0 +1,5 @@
1
+ import { Workbook } from '../../../../models/src/lib/gen/Api';
2
+ export declare const getPublishedWorkbookById: ({ type, id, }: {
3
+ type: string;
4
+ id: string;
5
+ }) => Promise<Workbook>;
File without changes
@@ -0,0 +1,2 @@
1
+ export * from './triggerHttpWorkflow';
2
+ export * from './triggerWorkflow';
@@ -0,0 +1,20 @@
1
+ export interface TriggerHttpWorkflowRequest {
2
+ data: Record<string, any>;
3
+ triggerId: string;
4
+ }
5
+ export interface TriggeredWorkflow {
6
+ workflowId: string;
7
+ triggerId: string;
8
+ }
9
+ export interface TriggerHttpWorkflowResponse {
10
+ triggeredWorkflows: TriggeredWorkflow[];
11
+ }
12
+ /**
13
+ * Triggers an HTTP workflow with the provided data
14
+ * @param params - The trigger parameters
15
+ * @param params.triggerId - The ID of the HTTP trigger
16
+ * @param params.data - The data payload to send to the workflow
17
+ * @returns Promise<TriggerHttpWorkflowResponse> The triggered workflow details
18
+ * @throws Error if the request fails
19
+ */
20
+ export declare function triggerHttpWorkflow({ data, triggerId, }: TriggerHttpWorkflowRequest): Promise<TriggerHttpWorkflowResponse>;
@@ -0,0 +1,23 @@
1
+ export interface TriggerWorkflowRequest {
2
+ parentId: string;
3
+ triggerBy: string;
4
+ }
5
+ export interface TriggerWorkflowResponse {
6
+ workbookId: string;
7
+ triggerBy: string;
8
+ instanceId: string;
9
+ triggerId: string;
10
+ workflowId: string;
11
+ status: string;
12
+ triggeredAt: string;
13
+ message: string;
14
+ }
15
+ /**
16
+ * Triggers workflow
17
+ * @param params - The trigger parameters
18
+ * @param params.parentId - The ID of the workflow to be triggered
19
+ * @param params.triggerBy - The user who triggered the workflow
20
+ * @returns Promise<TriggerWorkflowResponse> The triggered workflow details
21
+ * @throws Error if the request fails
22
+ */
23
+ export declare function triggerWorkflow({ parentId, triggerBy, }: TriggerWorkflowRequest): Promise<TriggerWorkflowResponse>;
@@ -0,0 +1,2 @@
1
+ import { Worksheet } from '../../../../models/src/lib/gen/Api';
2
+ export declare const getWorksheets: (worksheetIds: string[]) => Promise<Worksheet[]>;
@@ -0,0 +1 @@
1
+ export * from './getWorksheets';
@@ -0,0 +1,18 @@
1
+ export interface Config {
2
+ apiBaseUrl: string;
3
+ accessToken: string;
4
+ workspaceId: string;
5
+ }
6
+ declare class ConfigSingleton {
7
+ private static instance;
8
+ private config;
9
+ private constructor();
10
+ static getInstance(): ConfigSingleton;
11
+ setConfig(newConfig: Partial<Config>): void;
12
+ getConfig(): Config;
13
+ resetConfig(): void;
14
+ }
15
+ export declare function setConfig(newConfig: Partial<Config>): void;
16
+ export declare function getConfig(): Config;
17
+ export declare function resetConfig(): void;
18
+ export { ConfigSingleton };
@@ -0,0 +1,4 @@
1
+ export { setConfig as copaSetConfig, getConfig as copaGetConfig } from './config';
2
+ export * as copaApi from './api';
3
+ export * as copaUtils from './utils';
4
+ export { default as copaTailwindConfig } from './tailwind/bluecopa.config';