@bluecopa/core 0.1.23 → 0.1.24

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.
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Delete one or more rows from an input table
3
+ * Row ID can be provided as a string (single ID) or array (multiple IDs)
4
+ *
5
+ * @param tableId - The ID of the input table
6
+ * @param rowId - Row ID(s) to delete (string for single, array for multiple)
7
+ * @param idField - Optional: Field name to use ('copa_id' or '_copa_id'), defaults to '_copa_id'
8
+ * @returns Promise<any> The delete response
9
+ * @throws Error if the request fails
10
+ *
11
+ * @example
12
+ * // Delete single row
13
+ * await deleteRow('table-123', 'row-123');
14
+ *
15
+ * @example
16
+ * // Delete multiple rows
17
+ * await deleteRow('table-123', ['row-123', 'row-456']);
18
+ *
19
+ * @example
20
+ * // Using copa_id field
21
+ * await deleteRow('table-123', 'row-123', 'copa_id');
22
+ */
23
+ export declare const deleteRow: (tableId: string, rowId: string | string[], idField?: "copa_id" | "_copa_id") => Promise<any>;
@@ -0,0 +1,38 @@
1
+ export interface GetRowsOptions {
2
+ limit?: number;
3
+ offset?: number;
4
+ order?: string;
5
+ order_by?: string;
6
+ [key: string]: any;
7
+ }
8
+ export interface GetRowsResponse {
9
+ data: any[];
10
+ count: number;
11
+ total_count: number;
12
+ }
13
+ /**
14
+ * Get rows from an input table with optional filtering and pagination
15
+ * Supports Supabase-style filtering via query parameters
16
+ *
17
+ * @param tableId - The ID of the input table
18
+ * @param options - Query options including filters, pagination, and sorting
19
+ * @returns Promise<GetRowsResponse> The rows data with count information
20
+ * @throws Error if the request fails
21
+ *
22
+ * @example
23
+ * // Get all rows
24
+ * await getRows('table-123');
25
+ *
26
+ * @example
27
+ * // Filter by equality
28
+ * await getRows('table-123', { status: 'active' });
29
+ *
30
+ * @example
31
+ * // Filter with operators
32
+ * await getRows('table-123', { price: 'gte.100', status: 'in.(active,pending)' });
33
+ *
34
+ * @example
35
+ * // Pagination
36
+ * await getRows('table-123', { limit: 10, offset: 0 });
37
+ */
38
+ export declare const getRows: (tableId: string, options?: GetRowsOptions) => Promise<GetRowsResponse>;
@@ -1,3 +1,7 @@
1
1
  export * from './getData';
2
2
  export * from './getTableById';
3
3
  export * from './getInputTables';
4
+ export * from './getRows';
5
+ export * from './insertRow';
6
+ export * from './updateRow';
7
+ export * from './deleteRow';
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Insert a new row into an input table
3
+ *
4
+ * @param tableId - The ID of the input table
5
+ * @param rowData - The row data object (column names as keys)
6
+ * @returns Promise<any> The inserted row data
7
+ * @throws Error if the request fails
8
+ *
9
+ * @example
10
+ * await insertRow('table-123', {
11
+ * name: 'Item 1',
12
+ * status: 'active',
13
+ * price: 100
14
+ * });
15
+ */
16
+ export declare const insertRow: (tableId: string, rowData: Record<string, any>) => Promise<any>;
@@ -0,0 +1,24 @@
1
+ export interface UpdateRowOptions {
2
+ copa_id?: string;
3
+ _copa_id?: string;
4
+ [key: string]: any;
5
+ }
6
+ /**
7
+ * Update a row in an input table
8
+ * Row ID can be provided via copa_id/_copa_id in the updateData or as a separate parameter
9
+ *
10
+ * @param tableId - The ID of the input table
11
+ * @param updateData - The fields to update (may include copa_id or _copa_id)
12
+ * @param rowId - Optional: Row ID to update (alternative to including in updateData)
13
+ * @returns Promise<any> The updated row data
14
+ * @throws Error if the request fails
15
+ *
16
+ * @example
17
+ * // Using rowId parameter
18
+ * await updateRow('table-123', { status: 'completed' }, 'row-123');
19
+ *
20
+ * @example
21
+ * // Using copa_id in updateData
22
+ * await updateRow('table-123', { _copa_id: 'row-123', status: 'completed' });
23
+ */
24
+ export declare const updateRow: (tableId: string, updateData: UpdateRowOptions, rowId?: string) => Promise<any>;
package/dist/index.d.ts CHANGED
@@ -18,3 +18,5 @@ export type { FileDownloadRequest } from './api/file/fileDownload';
18
18
  export type { GetFileUrlRequest, GetFileUrlResponse } from './api/file/getFileUrlByFileId';
19
19
  export type { User } from './api/user/getAllUsers';
20
20
  export type { HttpTrigger } from './api/workflow/getAllHttpTriggers';
21
+ export type { GetRowsOptions, GetRowsResponse } from './api/inputTable/getRows';
22
+ export type { UpdateRowOptions } from './api/inputTable/updateRow';
package/dist/index.es.js CHANGED
@@ -6226,11 +6226,147 @@ const getInputTables = async () => {
6226
6226
  throw { message, status };
6227
6227
  }
6228
6228
  };
6229
+ const getRows = async (tableId, options) => {
6230
+ var _a, _b, _c;
6231
+ try {
6232
+ if (!tableId) {
6233
+ throw { message: "Table ID is required", status: 400 };
6234
+ }
6235
+ const params = {};
6236
+ if (options) {
6237
+ Object.keys(options).forEach((key) => {
6238
+ if (options[key] !== void 0 && options[key] !== null) {
6239
+ params[key] = options[key];
6240
+ }
6241
+ });
6242
+ }
6243
+ const response = await apiClient.get(
6244
+ `/api/v1/input-table/${tableId}/rows`,
6245
+ { params }
6246
+ );
6247
+ if (!response.data) {
6248
+ throw { message: "Failed to fetch rows", status: 500 };
6249
+ }
6250
+ return response.data;
6251
+ } catch (error) {
6252
+ const message = ((_b = (_a = error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message || "An unexpected error occurred while fetching rows";
6253
+ const status = ((_c = error.response) == null ? void 0 : _c.status) || 500;
6254
+ throw { message, status };
6255
+ }
6256
+ };
6257
+ const insertRow = async (tableId, rowData) => {
6258
+ var _a, _b, _c;
6259
+ try {
6260
+ if (!tableId) {
6261
+ throw { message: "Table ID is required", status: 400 };
6262
+ }
6263
+ if (!rowData || typeof rowData !== "object" || Array.isArray(rowData)) {
6264
+ throw { message: "Row data must be an object", status: 400 };
6265
+ }
6266
+ const response = await apiClient.post(
6267
+ `/api/v1/input-table/${tableId}/rows`,
6268
+ rowData
6269
+ );
6270
+ if (!response.data) {
6271
+ throw { message: "Failed to insert row", status: 500 };
6272
+ }
6273
+ return response.data;
6274
+ } catch (error) {
6275
+ const message = ((_b = (_a = error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message || "An unexpected error occurred while inserting row";
6276
+ const status = ((_c = error.response) == null ? void 0 : _c.status) || 500;
6277
+ throw { message, status };
6278
+ }
6279
+ };
6280
+ const updateRow = async (tableId, updateData, rowId) => {
6281
+ var _a, _b, _c;
6282
+ try {
6283
+ if (!tableId) {
6284
+ throw { message: "Table ID is required", status: 400 };
6285
+ }
6286
+ if (!updateData || typeof updateData !== "object" || Array.isArray(updateData)) {
6287
+ throw { message: "Update data must be an object", status: 400 };
6288
+ }
6289
+ const body = { ...updateData };
6290
+ const params = {};
6291
+ if (rowId) {
6292
+ params._copa_id = rowId;
6293
+ delete body.copa_id;
6294
+ delete body._copa_id;
6295
+ }
6296
+ const fieldsToUpdate = Object.keys(body).filter(
6297
+ (key) => key !== "copa_id" && key !== "_copa_id"
6298
+ );
6299
+ if (fieldsToUpdate.length === 0 && !rowId) {
6300
+ throw {
6301
+ message: "At least one field to update must be provided",
6302
+ status: 400
6303
+ };
6304
+ }
6305
+ const response = await apiClient.patch(
6306
+ `/api/v1/input-table/${tableId}/rows`,
6307
+ body,
6308
+ { params }
6309
+ );
6310
+ if (!response.data) {
6311
+ throw { message: "Failed to update row", status: 500 };
6312
+ }
6313
+ return response.data;
6314
+ } catch (error) {
6315
+ const message = ((_b = (_a = error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message || "An unexpected error occurred while updating row";
6316
+ const status = ((_c = error.response) == null ? void 0 : _c.status) || 500;
6317
+ throw { message, status };
6318
+ }
6319
+ };
6320
+ const deleteRow = async (tableId, rowId, idField = "_copa_id") => {
6321
+ var _a, _b, _c;
6322
+ try {
6323
+ if (!tableId) {
6324
+ throw { message: "Table ID is required", status: 400 };
6325
+ }
6326
+ if (!rowId) {
6327
+ throw { message: "Row ID is required", status: 400 };
6328
+ }
6329
+ const isMultiple = Array.isArray(rowId);
6330
+ const params = {};
6331
+ let body;
6332
+ if (isMultiple && rowId.length === 0) {
6333
+ throw { message: "At least one row ID must be provided", status: 400 };
6334
+ }
6335
+ if (isMultiple) {
6336
+ body = { [idField]: rowId };
6337
+ } else {
6338
+ params[idField] = rowId;
6339
+ }
6340
+ const config = {
6341
+ url: `/api/v1/input-table/${tableId}/rows`,
6342
+ method: "delete"
6343
+ };
6344
+ if (Object.keys(params).length > 0) {
6345
+ config.params = params;
6346
+ }
6347
+ if (body) {
6348
+ config.data = body;
6349
+ }
6350
+ const response = await apiClient.request(config);
6351
+ if (!response.data) {
6352
+ throw { message: "Failed to delete row(s)", status: 500 };
6353
+ }
6354
+ return response.data;
6355
+ } catch (error) {
6356
+ const message = ((_b = (_a = error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message || "An unexpected error occurred while deleting row(s)";
6357
+ const status = ((_c = error.response) == null ? void 0 : _c.status) || 500;
6358
+ throw { message, status };
6359
+ }
6360
+ };
6229
6361
  const index$9 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
6230
6362
  __proto__: null,
6363
+ deleteRow,
6231
6364
  getData: getData$1,
6232
6365
  getInputTables,
6233
- getTableById
6366
+ getRows,
6367
+ getTableById,
6368
+ insertRow,
6369
+ updateRow
6234
6370
  }, Symbol.toStringTag, { value: "Module" }));
6235
6371
  const getWorkbooksByType = async (type) => {
6236
6372
  var _a, _b, _c;