@copera.ai/sdk 1.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Copera.ai
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,505 @@
1
+ # Copera.ai Node.js SDK
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@copera.ai/sdk.svg)](https://www.npmjs.com/package/@copera.ai/sdk)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+ [![Node.js Version](https://img.shields.io/node/v/@copera.ai/sdk.svg)](https://nodejs.org)
6
+
7
+ Official Node.js SDK for [Copera.ai](https://copera.ai) - The ultimate platform for workflow automation and data management.
8
+
9
+ > **๐Ÿ“– Full Documentation**: For complete guides, tutorials, and API reference, visit [developers.copera.ai](https://developers.copera.ai)
10
+
11
+ ## Features
12
+
13
+ - โœจ **Full TypeScript Support** - Complete type definitions for all API endpoints
14
+ - ๐Ÿ”„ **Modern ESM & CJS** - Works with both ES modules and CommonJS
15
+ - ๐Ÿญ **Factory Pattern** - Clean dependency injection architecture
16
+ - ๐Ÿงช **Sandbox Mode** - Test against development environment
17
+ - ๐ŸŽฏ **Type-Safe** - Full IntelliSense support in your IDE
18
+ - ๐Ÿ“ฆ **Zero Dependencies** - Uses native Fetch API
19
+ - โœ… **Fully Tested** - Comprehensive test coverage
20
+
21
+ ## Installation
22
+
23
+ ```bash
24
+ # npm
25
+ npm install @copera.ai/sdk
26
+
27
+ # yarn
28
+ yarn add @copera.ai/sdk
29
+
30
+ # pnpm
31
+ pnpm add @copera.ai/sdk
32
+ ```
33
+
34
+ ## Requirements
35
+
36
+ - Node.js 18 or higher
37
+ - An API key from [Copera.ai](https://copera.ai)
38
+
39
+ ## Quick Start
40
+
41
+ ```typescript
42
+ import { CoperaAI } from '@copera.ai/sdk';
43
+
44
+ // Initialize the SDK
45
+ const copera = CoperaAI({
46
+ apiKey: 'your-api-key-here'
47
+ });
48
+
49
+ // List all boards
50
+ const boards = await copera.board.listBoards();
51
+ console.log(boards);
52
+
53
+ // Send a message to a channel
54
+ await copera.channel.sendMessage({
55
+ channelId: 'channel-id',
56
+ message: 'Hello from Copera.ai SDK!'
57
+ });
58
+ ```
59
+
60
+ ## Configuration
61
+
62
+ ### Basic Configuration
63
+
64
+ ```typescript
65
+ import { CoperaAI } from '@copera.ai/sdk';
66
+
67
+ const copera = CoperaAI({
68
+ apiKey: process.env.COPERA_API_KEY
69
+ });
70
+ ```
71
+
72
+ ### Sandbox Mode
73
+
74
+ Use sandbox mode to test against the development environment:
75
+
76
+ ```typescript
77
+ const copera = CoperaAI({
78
+ apiKey: process.env.COPERA_API_KEY,
79
+ sandbox: true // Use development environment
80
+ });
81
+ ```
82
+
83
+ ## API Reference
84
+
85
+ ### Board Methods
86
+
87
+ #### `listBoards()`
88
+
89
+ List all boards available in your workspace.
90
+
91
+ ```typescript
92
+ const boards = await copera.board.listBoards();
93
+ ```
94
+
95
+ **Returns:** `Promise<Board[]>`
96
+
97
+ #### `getBoardDetails(params)`
98
+
99
+ Get details of a specific board.
100
+
101
+ ```typescript
102
+ const board = await copera.board.getBoardDetails({
103
+ boardId: 'board-id'
104
+ });
105
+ ```
106
+
107
+ **Parameters:**
108
+ - `boardId` (string, required) - The board ID
109
+
110
+ **Returns:** `Promise<Board>`
111
+
112
+ #### `listBoardTables(params)`
113
+
114
+ List all tables in a specific board.
115
+
116
+ ```typescript
117
+ const tables = await copera.board.listBoardTables({
118
+ boardId: 'board-id'
119
+ });
120
+ ```
121
+
122
+ **Parameters:**
123
+ - `boardId` (string, required) - The board ID
124
+
125
+ **Returns:** `Promise<Table[]>`
126
+
127
+ #### `getBoardTable(params)`
128
+
129
+ Get details of a specific table.
130
+
131
+ ```typescript
132
+ const table = await copera.board.getBoardTable({
133
+ boardId: 'board-id',
134
+ tableId: 'table-id'
135
+ });
136
+ ```
137
+
138
+ **Parameters:**
139
+ - `boardId` (string, required) - The board ID
140
+ - `tableId` (string, required) - The table ID
141
+
142
+ **Returns:** `Promise<Table>`
143
+
144
+ #### `listTableRows(params)`
145
+
146
+ List all rows in a table.
147
+
148
+ ```typescript
149
+ const rows = await copera.board.listTableRows({
150
+ boardId: 'board-id',
151
+ tableId: 'table-id'
152
+ });
153
+ ```
154
+
155
+ **Parameters:**
156
+ - `boardId` (string, required) - The board ID
157
+ - `tableId` (string, required) - The table ID
158
+
159
+ **Returns:** `Promise<Row[]>`
160
+
161
+ #### `getTableRow(params)`
162
+
163
+ Get a specific row from a table.
164
+
165
+ ```typescript
166
+ const row = await copera.board.getTableRow({
167
+ boardId: 'board-id',
168
+ tableId: 'table-id',
169
+ rowId: 'row-id'
170
+ });
171
+ ```
172
+
173
+ **Parameters:**
174
+ - `boardId` (string, required) - The board ID
175
+ - `tableId` (string, required) - The table ID
176
+ - `rowId` (string, required) - The row ID
177
+
178
+ **Returns:** `Promise<Row>`
179
+
180
+ #### `createTableRow(params)`
181
+
182
+ Create a new row in a table.
183
+
184
+ ```typescript
185
+ const newRow = await copera.board.createTableRow({
186
+ boardId: 'board-id',
187
+ tableId: 'table-id',
188
+ description: 'Optional description',
189
+ columns: [
190
+ { columnId: 'column-1', value: 'Value 1' },
191
+ { columnId: 'column-2', value: 'Value 2' }
192
+ ]
193
+ });
194
+ ```
195
+
196
+ **Parameters:**
197
+ - `boardId` (string, required) - The board ID
198
+ - `tableId` (string, required) - The table ID
199
+ - `description` (string, optional) - Row description
200
+ - `columns` (ColumnValue[], required) - Array of column values
201
+
202
+ **Returns:** `Promise<Row>`
203
+
204
+ ### Channel Methods
205
+
206
+ #### `sendMessage(params)`
207
+
208
+ Send a message to a channel.
209
+
210
+ ```typescript
211
+ await copera.channel.sendMessage({
212
+ channelId: 'channel-id',
213
+ message: 'Your message here',
214
+ name: 'Optional sender name' // optional
215
+ });
216
+ ```
217
+
218
+ **Parameters:**
219
+ - `channelId` (string, required) - The channel ID
220
+ - `message` (string, required) - Message content (1-10000 characters)
221
+ - `name` (string, optional) - Name of the sender
222
+
223
+ **Returns:** `Promise<void>`
224
+
225
+ ## TypeScript Types
226
+
227
+ The SDK exports all TypeScript types for your convenience:
228
+
229
+ ```typescript
230
+ import {
231
+ Board,
232
+ Table,
233
+ Row,
234
+ Column,
235
+ ColumnValue,
236
+ SendMessageParams,
237
+ CoperaAIError
238
+ } from '@copera.ai/sdk';
239
+ ```
240
+
241
+ ### Type Definitions
242
+
243
+ ```typescript
244
+ interface Board {
245
+ _id: string;
246
+ name: string;
247
+ description?: string;
248
+ createdAt: string;
249
+ updatedAt: string;
250
+ }
251
+
252
+ interface Table {
253
+ _id: string;
254
+ name: string;
255
+ board: string;
256
+ columns: Column[];
257
+ createdAt: string;
258
+ updatedAt: string;
259
+ }
260
+
261
+ interface Row {
262
+ _id: string;
263
+ rowId: string;
264
+ owner: string;
265
+ table: string;
266
+ board: string;
267
+ columns: ColumnValue[];
268
+ createdAt: string;
269
+ updatedAt: string;
270
+ }
271
+
272
+ interface Column {
273
+ columnId: string;
274
+ label: string;
275
+ type: string;
276
+ order?: number;
277
+ }
278
+
279
+ interface ColumnValue {
280
+ columnId: string;
281
+ value: unknown;
282
+ }
283
+ ```
284
+
285
+ ## Error Handling
286
+
287
+ The SDK returns errors in a consistent format:
288
+
289
+ ```typescript
290
+ try {
291
+ const boards = await copera.board.listBoards();
292
+
293
+ if ('error' in boards) {
294
+ console.error('API Error:', boards.error);
295
+ return;
296
+ }
297
+
298
+ // Success - process boards
299
+ console.log(boards);
300
+ } catch (error) {
301
+ console.error('Network Error:', error);
302
+ }
303
+ ```
304
+
305
+ ## Usage with Different Module Systems
306
+
307
+ ### ESM (ES Modules)
308
+
309
+ ```typescript
310
+ import { CoperaAI } from '@copera.ai/sdk';
311
+
312
+ const copera = CoperaAI({ apiKey: 'your-api-key' });
313
+ ```
314
+
315
+ ### CommonJS
316
+
317
+ ```javascript
318
+ const { CoperaAI } = require('@copera.ai/sdk');
319
+
320
+ const copera = CoperaAI({ apiKey: 'your-api-key' });
321
+ ```
322
+
323
+ ### TypeScript with ESM
324
+
325
+ ```typescript
326
+ // tsconfig.json
327
+ {
328
+ "compilerOptions": {
329
+ "module": "ESNext",
330
+ "moduleResolution": "bundler"
331
+ }
332
+ }
333
+ ```
334
+
335
+ ## Examples
336
+
337
+ ### Complete Board Workflow
338
+
339
+ ```typescript
340
+ import { CoperaAI } from '@copera.ai/sdk';
341
+
342
+ const copera = CoperaAI({ apiKey: process.env.COPERA_API_KEY });
343
+
344
+ async function manageBoardData() {
345
+ // 1. Get all boards
346
+ const boards = await copera.board.listBoards();
347
+ const firstBoard = boards[0];
348
+
349
+ // 2. Get board details
350
+ const board = await copera.board.getBoardDetails({
351
+ boardId: firstBoard._id
352
+ });
353
+
354
+ // 3. Get all tables in the board
355
+ const tables = await copera.board.listBoardTables({
356
+ boardId: board._id
357
+ });
358
+
359
+ // 4. Get rows from first table
360
+ const rows = await copera.board.listTableRows({
361
+ boardId: board._id,
362
+ tableId: tables[0]._id
363
+ });
364
+
365
+ // 5. Create a new row
366
+ const newRow = await copera.board.createTableRow({
367
+ boardId: board._id,
368
+ tableId: tables[0]._id,
369
+ columns: [
370
+ { columnId: 'col-1', value: 'New Value' }
371
+ ]
372
+ });
373
+
374
+ console.log('Created row:', newRow);
375
+ }
376
+
377
+ manageBoardData().catch(console.error);
378
+ ```
379
+
380
+ ### Send Notifications
381
+
382
+ ```typescript
383
+ import { CoperaAI } from '@copera.ai/sdk';
384
+
385
+ const copera = CoperaAI({ apiKey: process.env.COPERA_API_KEY });
386
+
387
+ async function sendNotification() {
388
+ await copera.channel.sendMessage({
389
+ channelId: 'your-channel-id',
390
+ message: 'Task completed successfully!',
391
+ name: 'Automation Bot'
392
+ });
393
+ }
394
+
395
+ sendNotification().catch(console.error);
396
+ ```
397
+
398
+ ### Using with Environment Variables
399
+
400
+ ```typescript
401
+ // .env
402
+ COPERA_API_KEY=your-api-key-here
403
+ COPERA_CHANNEL_ID=your-channel-id
404
+
405
+ // app.ts
406
+ import { CoperaAI } from '@copera.ai/sdk';
407
+ import 'dotenv/config';
408
+
409
+ const copera = CoperaAI({
410
+ apiKey: process.env.COPERA_API_KEY!
411
+ });
412
+
413
+ await copera.channel.sendMessage({
414
+ channelId: process.env.COPERA_CHANNEL_ID!,
415
+ message: 'Hello from automation!'
416
+ });
417
+ ```
418
+
419
+ ## Best Practices
420
+
421
+ ### 1. Use Environment Variables
422
+
423
+ Never hardcode API keys in your source code:
424
+
425
+ ```typescript
426
+ // โŒ Bad
427
+ const copera = CoperaAI({ apiKey: 'sk_live_abc123...' });
428
+
429
+ // โœ… Good
430
+ const copera = CoperaAI({ apiKey: process.env.COPERA_API_KEY });
431
+ ```
432
+
433
+ ### 2. Error Handling
434
+
435
+ Always handle errors appropriately:
436
+
437
+ ```typescript
438
+ try {
439
+ const boards = await copera.board.listBoards();
440
+ if ('error' in boards) {
441
+ // Handle API error
442
+ logger.error('API Error:', boards.error);
443
+ return;
444
+ }
445
+ // Process successful response
446
+ } catch (error) {
447
+ // Handle network/unexpected errors
448
+ logger.error('Unexpected error:', error);
449
+ }
450
+ ```
451
+
452
+ ### 3. Use TypeScript
453
+
454
+ Take advantage of full type safety:
455
+
456
+ ```typescript
457
+ import { CoperaAI, type Board, type Row } from '@copera.ai/sdk';
458
+
459
+ const copera = CoperaAI({ apiKey: process.env.COPERA_API_KEY });
460
+
461
+ // TypeScript will provide full autocomplete and type checking
462
+ const boards: Board[] = await copera.board.listBoards();
463
+ ```
464
+
465
+ ### 4. Separate Development and Production Keys
466
+
467
+ Use different API keys for different environments:
468
+
469
+ ```typescript
470
+ const copera = CoperaAI({
471
+ apiKey: process.env.COPERA_API_KEY,
472
+ sandbox: process.env.NODE_ENV === 'development'
473
+ });
474
+ ```
475
+
476
+ ## Contributing
477
+
478
+ We welcome contributions! Please see our [Contributing Guide](./CONTRIBUTING.md) for details.
479
+
480
+ ## Security
481
+
482
+ If you discover a security vulnerability, please email security@copera.ai. Do not create public issues for security vulnerabilities.
483
+
484
+ See our [Security Policy](./SECURITY.md) for more details.
485
+
486
+ ## License
487
+
488
+ This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.
489
+
490
+ ## Support
491
+
492
+ - ๐Ÿ“ง Email: support@copera.ai
493
+ - ๐Ÿ› Issues: [GitHub Issues](https://github.com/Copera-ai/copera-nodejs-sdk/issues)
494
+ - ๐Ÿ“– Documentation: [developers.copera.ai](https://developers.copera.ai)
495
+
496
+ ## Links
497
+
498
+ - [Copera.ai Website](https://copera.ai)
499
+ - [API Documentation](https://developers.copera.ai)
500
+ - [GitHub Repository](https://github.com/Copera-ai/copera-nodejs-sdk)
501
+ - [npm Package](https://www.npmjs.com/package/@copera.ai/sdk)
502
+
503
+ ---
504
+
505
+ Made with โค๏ธ by the Copera.ai team
package/dist/index.cjs ADDED
@@ -0,0 +1,178 @@
1
+ Object.defineProperty(exports, '__esModule', { value: true });
2
+
3
+ //#region src/version.ts
4
+ const COPERA_SDK_VERSION = "1.1.0";
5
+
6
+ //#endregion
7
+ //#region src/constants.ts
8
+ const BASE_URL = "https://api.copera.ai/public/v1";
9
+ const BASE_URL_DEV = "https://api-dev.copera.ai/public/v1";
10
+ const COPERA_DOCS = "https://developers.copera.ai";
11
+ function getHeaders(apiKey) {
12
+ return {
13
+ Authorization: `Bearer ${apiKey}`,
14
+ "Content-Type": "application/json",
15
+ "User-Agent": `NodeJS SDK ${COPERA_SDK_VERSION}`
16
+ };
17
+ }
18
+
19
+ //#endregion
20
+ //#region src/exceptions.ts
21
+ /**
22
+ * Default class for CoperaAI exceptions and errors.
23
+ *
24
+ * It can be serialized to JSON through the `toJSON` method.
25
+ */
26
+ var CoperaAIError = class extends Error {
27
+ constructor(message) {
28
+ super(`CoperaAI SDK Error: ${message}\n\nPlease, refer to the documentation at: ${COPERA_DOCS}`);
29
+ this.name = "CoperaAIError";
30
+ }
31
+ toJSON() {
32
+ return {
33
+ name: this.name,
34
+ message: this.message
35
+ };
36
+ }
37
+ };
38
+
39
+ //#endregion
40
+ //#region src/requests.ts
41
+ function createRequest(apiKey, sandbox = false) {
42
+ const defaultHeaders = getHeaders(apiKey);
43
+ const baseUrl = sandbox ? BASE_URL_DEV : BASE_URL;
44
+ return async (path, options) => {
45
+ try {
46
+ const response = await fetch(`${baseUrl}${path}`, {
47
+ ...options,
48
+ headers: {
49
+ ...defaultHeaders,
50
+ ...options?.headers
51
+ }
52
+ });
53
+ const data = await response.json();
54
+ if (!response.ok) return { error: data.message };
55
+ return data;
56
+ } catch (error) {
57
+ return { error: error.message };
58
+ }
59
+ };
60
+ }
61
+
62
+ //#endregion
63
+ //#region src/services/board/create-table-row.ts
64
+ function createCreateTableRow(request) {
65
+ return async function createTableRow({ boardId, tableId, description, columns }) {
66
+ return request(`/board/${boardId}/table/${tableId}/row`, {
67
+ method: "POST",
68
+ body: JSON.stringify({
69
+ description,
70
+ columns
71
+ })
72
+ });
73
+ };
74
+ }
75
+
76
+ //#endregion
77
+ //#region src/services/board/get-board-details.ts
78
+ function createGetBoardDetails(request) {
79
+ return async function getBoardDetails({ boardId }) {
80
+ return request(`/board/${boardId}`, { method: "GET" });
81
+ };
82
+ }
83
+
84
+ //#endregion
85
+ //#region src/services/board/get-board-table.ts
86
+ function createGetBoardTable(request) {
87
+ return async function getBoardTable({ boardId, tableId }) {
88
+ return request(`/board/${boardId}/table/${tableId}`, { method: "GET" });
89
+ };
90
+ }
91
+
92
+ //#endregion
93
+ //#region src/services/board/get-table-row.ts
94
+ function createGetTableRow(request) {
95
+ return async function getTableRow({ boardId, tableId, rowId }) {
96
+ return request(`/board/${boardId}/table/${tableId}/row/${rowId}`, { method: "GET" });
97
+ };
98
+ }
99
+
100
+ //#endregion
101
+ //#region src/services/board/list-board-tables.ts
102
+ function createListBoardTables(request) {
103
+ return async function listBoardTables({ boardId }) {
104
+ return request(`/board/${boardId}/tables`, { method: "GET" });
105
+ };
106
+ }
107
+
108
+ //#endregion
109
+ //#region src/services/board/list-boards.ts
110
+ function createListBoards(request) {
111
+ return async function listBoards() {
112
+ return request("/board/list-boards", { method: "GET" });
113
+ };
114
+ }
115
+
116
+ //#endregion
117
+ //#region src/services/board/list-table-rows.ts
118
+ function createListTableRows(request) {
119
+ return async function listTableRows({ boardId, tableId }) {
120
+ return request(`/board/${boardId}/table/${tableId}/rows`, { method: "GET" });
121
+ };
122
+ }
123
+
124
+ //#endregion
125
+ //#region src/services/board/index.ts
126
+ function createBoardHandlers(request) {
127
+ return {
128
+ listBoards: createListBoards(request),
129
+ getBoardDetails: createGetBoardDetails(request),
130
+ listBoardTables: createListBoardTables(request),
131
+ getBoardTable: createGetBoardTable(request),
132
+ listTableRows: createListTableRows(request),
133
+ getTableRow: createGetTableRow(request),
134
+ createTableRow: createCreateTableRow(request)
135
+ };
136
+ }
137
+
138
+ //#endregion
139
+ //#region src/services/channel/send-message.ts
140
+ function createSendMessage(request) {
141
+ return async function sendMessage({ channelId, message, name }) {
142
+ return request(`/chat/channel/${channelId}/send-message`, {
143
+ method: "POST",
144
+ body: JSON.stringify({
145
+ message,
146
+ name
147
+ })
148
+ });
149
+ };
150
+ }
151
+
152
+ //#endregion
153
+ //#region src/services/channel/index.ts
154
+ function createChannelHandlers(request) {
155
+ return { sendMessage: createSendMessage(request) };
156
+ }
157
+
158
+ //#endregion
159
+ //#region src/services/index.ts
160
+ function getHandlers(request) {
161
+ return {
162
+ board: createBoardHandlers(request),
163
+ channel: createChannelHandlers(request)
164
+ };
165
+ }
166
+
167
+ //#endregion
168
+ //#region src/index.ts
169
+ function CoperaAI({ apiKey, sandbox = false }) {
170
+ if (!apiKey) throw new CoperaAIError("API key is required!");
171
+ return getHandlers(createRequest(apiKey, sandbox));
172
+ }
173
+ var src_default = CoperaAI;
174
+
175
+ //#endregion
176
+ exports.CoperaAI = CoperaAI;
177
+ exports.CoperaAIError = CoperaAIError;
178
+ exports.default = src_default;
@@ -0,0 +1,122 @@
1
+ //#region src/types.d.ts
2
+ interface Board {
3
+ _id: string;
4
+ name: string;
5
+ description?: string;
6
+ createdAt: string;
7
+ updatedAt: string;
8
+ }
9
+ interface Column {
10
+ columnId: string;
11
+ label: string;
12
+ type: string;
13
+ order?: number;
14
+ }
15
+ interface Table {
16
+ _id: string;
17
+ name: string;
18
+ board: string;
19
+ columns: Column[];
20
+ createdAt: string;
21
+ updatedAt: string;
22
+ }
23
+ interface ColumnValue {
24
+ columnId: string;
25
+ value: unknown;
26
+ }
27
+ interface Row {
28
+ _id: string;
29
+ rowId: string;
30
+ owner: string;
31
+ table: string;
32
+ board: string;
33
+ columns: ColumnValue[];
34
+ createdAt: string;
35
+ updatedAt: string;
36
+ }
37
+ interface SendMessageParams {
38
+ channelId: string;
39
+ message: string;
40
+ name?: string;
41
+ }
42
+ //#endregion
43
+ //#region src/exceptions.d.ts
44
+ /**
45
+ * Default class for CoperaAI exceptions and errors.
46
+ *
47
+ * It can be serialized to JSON through the `toJSON` method.
48
+ */
49
+ declare class CoperaAIError extends Error {
50
+ constructor(message: string);
51
+ toJSON(): {
52
+ name: string;
53
+ message: string;
54
+ };
55
+ }
56
+ //#endregion
57
+ //#region src/index.d.ts
58
+ interface CoperaAIOptions {
59
+ apiKey: string;
60
+ sandbox?: boolean;
61
+ }
62
+ declare function CoperaAI({
63
+ apiKey,
64
+ sandbox
65
+ }: CoperaAIOptions): {
66
+ board: {
67
+ listBoards: () => Promise<Board[]>;
68
+ getBoardDetails: ({
69
+ boardId
70
+ }: {
71
+ boardId: string;
72
+ }) => Promise<Board>;
73
+ listBoardTables: ({
74
+ boardId
75
+ }: {
76
+ boardId: string;
77
+ }) => Promise<Table[]>;
78
+ getBoardTable: ({
79
+ boardId,
80
+ tableId
81
+ }: {
82
+ boardId: string;
83
+ tableId: string;
84
+ }) => Promise<Table>;
85
+ listTableRows: ({
86
+ boardId,
87
+ tableId
88
+ }: {
89
+ boardId: string;
90
+ tableId: string;
91
+ }) => Promise<Row[]>;
92
+ getTableRow: ({
93
+ boardId,
94
+ tableId,
95
+ rowId
96
+ }: {
97
+ boardId: string;
98
+ tableId: string;
99
+ rowId: string;
100
+ }) => Promise<Row>;
101
+ createTableRow: ({
102
+ boardId,
103
+ tableId,
104
+ description,
105
+ columns
106
+ }: {
107
+ boardId: string;
108
+ tableId: string;
109
+ description?: string;
110
+ columns: ColumnValue[];
111
+ }) => Promise<Row>;
112
+ };
113
+ channel: {
114
+ sendMessage: ({
115
+ channelId,
116
+ message,
117
+ name
118
+ }: SendMessageParams) => Promise<void>;
119
+ };
120
+ };
121
+ //#endregion
122
+ export { CoperaAI, CoperaAI as default, CoperaAIError };
@@ -0,0 +1,122 @@
1
+ //#region src/types.d.ts
2
+ interface Board {
3
+ _id: string;
4
+ name: string;
5
+ description?: string;
6
+ createdAt: string;
7
+ updatedAt: string;
8
+ }
9
+ interface Column {
10
+ columnId: string;
11
+ label: string;
12
+ type: string;
13
+ order?: number;
14
+ }
15
+ interface Table {
16
+ _id: string;
17
+ name: string;
18
+ board: string;
19
+ columns: Column[];
20
+ createdAt: string;
21
+ updatedAt: string;
22
+ }
23
+ interface ColumnValue {
24
+ columnId: string;
25
+ value: unknown;
26
+ }
27
+ interface Row {
28
+ _id: string;
29
+ rowId: string;
30
+ owner: string;
31
+ table: string;
32
+ board: string;
33
+ columns: ColumnValue[];
34
+ createdAt: string;
35
+ updatedAt: string;
36
+ }
37
+ interface SendMessageParams {
38
+ channelId: string;
39
+ message: string;
40
+ name?: string;
41
+ }
42
+ //#endregion
43
+ //#region src/exceptions.d.ts
44
+ /**
45
+ * Default class for CoperaAI exceptions and errors.
46
+ *
47
+ * It can be serialized to JSON through the `toJSON` method.
48
+ */
49
+ declare class CoperaAIError extends Error {
50
+ constructor(message: string);
51
+ toJSON(): {
52
+ name: string;
53
+ message: string;
54
+ };
55
+ }
56
+ //#endregion
57
+ //#region src/index.d.ts
58
+ interface CoperaAIOptions {
59
+ apiKey: string;
60
+ sandbox?: boolean;
61
+ }
62
+ declare function CoperaAI({
63
+ apiKey,
64
+ sandbox
65
+ }: CoperaAIOptions): {
66
+ board: {
67
+ listBoards: () => Promise<Board[]>;
68
+ getBoardDetails: ({
69
+ boardId
70
+ }: {
71
+ boardId: string;
72
+ }) => Promise<Board>;
73
+ listBoardTables: ({
74
+ boardId
75
+ }: {
76
+ boardId: string;
77
+ }) => Promise<Table[]>;
78
+ getBoardTable: ({
79
+ boardId,
80
+ tableId
81
+ }: {
82
+ boardId: string;
83
+ tableId: string;
84
+ }) => Promise<Table>;
85
+ listTableRows: ({
86
+ boardId,
87
+ tableId
88
+ }: {
89
+ boardId: string;
90
+ tableId: string;
91
+ }) => Promise<Row[]>;
92
+ getTableRow: ({
93
+ boardId,
94
+ tableId,
95
+ rowId
96
+ }: {
97
+ boardId: string;
98
+ tableId: string;
99
+ rowId: string;
100
+ }) => Promise<Row>;
101
+ createTableRow: ({
102
+ boardId,
103
+ tableId,
104
+ description,
105
+ columns
106
+ }: {
107
+ boardId: string;
108
+ tableId: string;
109
+ description?: string;
110
+ columns: ColumnValue[];
111
+ }) => Promise<Row>;
112
+ };
113
+ channel: {
114
+ sendMessage: ({
115
+ channelId,
116
+ message,
117
+ name
118
+ }: SendMessageParams) => Promise<void>;
119
+ };
120
+ };
121
+ //#endregion
122
+ export { CoperaAI, CoperaAI as default, CoperaAIError };
package/dist/index.mjs ADDED
@@ -0,0 +1,174 @@
1
+ //#region src/version.ts
2
+ const COPERA_SDK_VERSION = "1.1.0";
3
+
4
+ //#endregion
5
+ //#region src/constants.ts
6
+ const BASE_URL = "https://api.copera.ai/public/v1";
7
+ const BASE_URL_DEV = "https://api-dev.copera.ai/public/v1";
8
+ const COPERA_DOCS = "https://developers.copera.ai";
9
+ function getHeaders(apiKey) {
10
+ return {
11
+ Authorization: `Bearer ${apiKey}`,
12
+ "Content-Type": "application/json",
13
+ "User-Agent": `NodeJS SDK ${COPERA_SDK_VERSION}`
14
+ };
15
+ }
16
+
17
+ //#endregion
18
+ //#region src/exceptions.ts
19
+ /**
20
+ * Default class for CoperaAI exceptions and errors.
21
+ *
22
+ * It can be serialized to JSON through the `toJSON` method.
23
+ */
24
+ var CoperaAIError = class extends Error {
25
+ constructor(message) {
26
+ super(`CoperaAI SDK Error: ${message}\n\nPlease, refer to the documentation at: ${COPERA_DOCS}`);
27
+ this.name = "CoperaAIError";
28
+ }
29
+ toJSON() {
30
+ return {
31
+ name: this.name,
32
+ message: this.message
33
+ };
34
+ }
35
+ };
36
+
37
+ //#endregion
38
+ //#region src/requests.ts
39
+ function createRequest(apiKey, sandbox = false) {
40
+ const defaultHeaders = getHeaders(apiKey);
41
+ const baseUrl = sandbox ? BASE_URL_DEV : BASE_URL;
42
+ return async (path, options) => {
43
+ try {
44
+ const response = await fetch(`${baseUrl}${path}`, {
45
+ ...options,
46
+ headers: {
47
+ ...defaultHeaders,
48
+ ...options?.headers
49
+ }
50
+ });
51
+ const data = await response.json();
52
+ if (!response.ok) return { error: data.message };
53
+ return data;
54
+ } catch (error) {
55
+ return { error: error.message };
56
+ }
57
+ };
58
+ }
59
+
60
+ //#endregion
61
+ //#region src/services/board/create-table-row.ts
62
+ function createCreateTableRow(request) {
63
+ return async function createTableRow({ boardId, tableId, description, columns }) {
64
+ return request(`/board/${boardId}/table/${tableId}/row`, {
65
+ method: "POST",
66
+ body: JSON.stringify({
67
+ description,
68
+ columns
69
+ })
70
+ });
71
+ };
72
+ }
73
+
74
+ //#endregion
75
+ //#region src/services/board/get-board-details.ts
76
+ function createGetBoardDetails(request) {
77
+ return async function getBoardDetails({ boardId }) {
78
+ return request(`/board/${boardId}`, { method: "GET" });
79
+ };
80
+ }
81
+
82
+ //#endregion
83
+ //#region src/services/board/get-board-table.ts
84
+ function createGetBoardTable(request) {
85
+ return async function getBoardTable({ boardId, tableId }) {
86
+ return request(`/board/${boardId}/table/${tableId}`, { method: "GET" });
87
+ };
88
+ }
89
+
90
+ //#endregion
91
+ //#region src/services/board/get-table-row.ts
92
+ function createGetTableRow(request) {
93
+ return async function getTableRow({ boardId, tableId, rowId }) {
94
+ return request(`/board/${boardId}/table/${tableId}/row/${rowId}`, { method: "GET" });
95
+ };
96
+ }
97
+
98
+ //#endregion
99
+ //#region src/services/board/list-board-tables.ts
100
+ function createListBoardTables(request) {
101
+ return async function listBoardTables({ boardId }) {
102
+ return request(`/board/${boardId}/tables`, { method: "GET" });
103
+ };
104
+ }
105
+
106
+ //#endregion
107
+ //#region src/services/board/list-boards.ts
108
+ function createListBoards(request) {
109
+ return async function listBoards() {
110
+ return request("/board/list-boards", { method: "GET" });
111
+ };
112
+ }
113
+
114
+ //#endregion
115
+ //#region src/services/board/list-table-rows.ts
116
+ function createListTableRows(request) {
117
+ return async function listTableRows({ boardId, tableId }) {
118
+ return request(`/board/${boardId}/table/${tableId}/rows`, { method: "GET" });
119
+ };
120
+ }
121
+
122
+ //#endregion
123
+ //#region src/services/board/index.ts
124
+ function createBoardHandlers(request) {
125
+ return {
126
+ listBoards: createListBoards(request),
127
+ getBoardDetails: createGetBoardDetails(request),
128
+ listBoardTables: createListBoardTables(request),
129
+ getBoardTable: createGetBoardTable(request),
130
+ listTableRows: createListTableRows(request),
131
+ getTableRow: createGetTableRow(request),
132
+ createTableRow: createCreateTableRow(request)
133
+ };
134
+ }
135
+
136
+ //#endregion
137
+ //#region src/services/channel/send-message.ts
138
+ function createSendMessage(request) {
139
+ return async function sendMessage({ channelId, message, name }) {
140
+ return request(`/chat/channel/${channelId}/send-message`, {
141
+ method: "POST",
142
+ body: JSON.stringify({
143
+ message,
144
+ name
145
+ })
146
+ });
147
+ };
148
+ }
149
+
150
+ //#endregion
151
+ //#region src/services/channel/index.ts
152
+ function createChannelHandlers(request) {
153
+ return { sendMessage: createSendMessage(request) };
154
+ }
155
+
156
+ //#endregion
157
+ //#region src/services/index.ts
158
+ function getHandlers(request) {
159
+ return {
160
+ board: createBoardHandlers(request),
161
+ channel: createChannelHandlers(request)
162
+ };
163
+ }
164
+
165
+ //#endregion
166
+ //#region src/index.ts
167
+ function CoperaAI({ apiKey, sandbox = false }) {
168
+ if (!apiKey) throw new CoperaAIError("API key is required!");
169
+ return getHandlers(createRequest(apiKey, sandbox));
170
+ }
171
+ var src_default = CoperaAI;
172
+
173
+ //#endregion
174
+ export { CoperaAI, CoperaAIError, src_default as default };
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@copera.ai/sdk",
3
+ "version": "1.1.0",
4
+ "description": "Copera.ai NodeJS SDK",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git@github.com:Copera-ai/copera-nodejs-sdk.git"
13
+ },
14
+ "keywords": [
15
+ "sdk",
16
+ "typescript",
17
+ "copera",
18
+ "nodejs",
19
+ "api-client"
20
+ ],
21
+ "author": "Christian Curi <c.christiancuri@gmail.com>",
22
+ "license": "MIT",
23
+ "files": [
24
+ "dist",
25
+ "README.md"
26
+ ],
27
+ "devDependencies": {
28
+ "@biomejs/biome": "^2.3.7",
29
+ "@changesets/cli": "^2.29.7",
30
+ "@commitlint/cli": "^17.4.4",
31
+ "@commitlint/config-conventional": "^17.4.4",
32
+ "husky": "^9.1.7",
33
+ "lint-staged": "^13.3.0",
34
+ "tsdown": "^0.16.7",
35
+ "typescript": "^5.8.3",
36
+ "vite-tsconfig-paths": "^5.1.4",
37
+ "vitest": "^v3.2.4"
38
+ },
39
+ "lint-staged": {
40
+ "*": [
41
+ "biome check --no-errors-on-unmatched --files-ignore-unknown=true"
42
+ ]
43
+ },
44
+ "engines": {
45
+ "node": ">=18"
46
+ },
47
+ "scripts": {
48
+ "prebuild": "node -p \"'/*This file is auto generated during build, DO NOT CHANGE OR MODIFY */\\n\\nexport const COPERA_SDK_VERSION = ' + JSON.stringify(require('./package.json').version) + ';'\" > src/version.ts",
49
+ "build": "tsdown",
50
+ "test": "vitest --watch false",
51
+ "test:watch": "vitest --watch",
52
+ "lint": "biome check .",
53
+ "typecheck": "tsc --noEmit",
54
+ "changeset": "changeset",
55
+ "version": "changeset version",
56
+ "release": "pnpm build && changeset publish"
57
+ }
58
+ }