@calmlens/js-sdk 0.0.0 → 0.0.1

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 (2) hide show
  1. package/README.md +190 -22
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,37 +1,205 @@
1
- # [api-def](https://github.com/Censkh/api-def/) · [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Censkh/api-def/blob/master/LICENSE) [![npm version](https://img.shields.io/npm/v/api-def.svg?style=flat)](https://www.npmjs.com/package/api-def) [![build status](https://img.shields.io/github/actions/workflow/status/censkh/api-def/workflow.yml)](https://github.com/Censkh/api-def/actions)
1
+ # @calmlens/js-sdk
2
2
 
3
- Typed APIs with middleware support
3
+ Official JavaScript/TypeScript SDK for CalmLens API
4
4
 
5
- API def provides a unified way to type your endpoints allowing for compile time checking of query, body, response and even url parameters
5
+ CalmLens provides content moderation and classification services for images, videos, audio, documents, and websites. This SDK makes it easy to integrate CalmLens into your JavaScript/TypeScript applications.
6
+
7
+ ## Installation
6
8
 
7
9
  ```bash
8
- npm i api-def
10
+ npm install @calmlens/js-sdk
9
11
  ```
10
12
 
11
- - [Documentation](https://censkh.github.io/api-def/)
13
+ ## Quick Start
12
14
 
13
15
  ```typescript
14
- import { Api } from "api-def";
16
+ import CalmLensClient from "@calmlens/js-sdk";
15
17
 
16
- const api = new Api({
17
- baseUrl: "https://my-api/",
18
- name: "My API",
18
+ const client = new CalmLensClient({
19
+ apiKey: "your-api-key",
20
+ projectId: "your-project-id",
19
21
  });
20
22
 
21
- const fetchData = api
22
- .endpoint()
23
- .queryOf<{ includeAwesome: boolean }>()
24
- .responseOf<{ data: { awesome: boolean } }>()
25
- .build({
26
- id: "fetch_data",
27
- method: "get",
28
- path: "/data",
29
- });
23
+ // Submit an asset for processing
24
+ const asset = await client.submitAsset({
25
+ name: "my-image.jpg",
26
+ file: "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQ...", // base64 encoded file
27
+ fileType: "image/jpeg",
28
+ description: "User uploaded image",
29
+ visibility: "private"
30
+ });
31
+
32
+ console.log(asset.id); // Asset ID for future reference
33
+ console.log(asset.status); // "pending", "approved", "rejected", or "error"
34
+ ```
35
+
36
+ ## API Reference
37
+
38
+ ### CalmLensClient
39
+
40
+ The main client class for interacting with the CalmLens API.
41
+
42
+ #### Constructor
43
+
44
+ ```typescript
45
+ new CalmLensClient(options: CalmLensClientOptions)
46
+ ```
47
+
48
+ **Options:**
49
+ - `apiKey` (string, required): Your CalmLens API key
50
+ - `projectId` (string, required): Your CalmLens project ID
51
+ - `baseUrl` (string, optional): API base URL (defaults to "https://api.calmlens.com")
52
+
53
+ #### Methods
54
+
55
+ ##### submitAsset(options)
56
+
57
+ Submit an asset for processing and classification.
58
+
59
+ ```typescript
60
+ async submitAsset(options: SubmitAssetOptions): Promise<Asset>
61
+ ```
62
+
63
+ **Options:**
64
+ - `name` (string, required): Name of the asset
65
+ - `file` (string, optional): Base64 encoded file content or data URL
66
+ - `fileType` (string, optional): MIME type or file extension (required if using `file`)
67
+ - `url` (string, optional): External URL to the asset (alternative to `file`)
68
+ - `description` (string, optional): Description of the asset
69
+ - `keepAfterProcessing` (boolean, optional): Whether to keep the asset after processing
70
+ - `visibility` (string, optional): "public" or "private"
71
+
72
+ **Example:**
73
+ ```typescript
74
+ // Submit from file content
75
+ const asset = await client.submitAsset({
76
+ name: "document.pdf",
77
+ file: "data:application/pdf;base64,JVBERi0xLjQKJcfs...",
78
+ fileType: "application/pdf",
79
+ description: "Important document",
80
+ visibility: "private"
81
+ });
82
+
83
+ // Submit from URL
84
+ const asset = await client.submitAsset({
85
+ name: "website-content",
86
+ url: "https://example.com/page",
87
+ description: "Web page to analyze"
88
+ });
89
+ ```
90
+
91
+ ##### getAsset(assetId)
92
+
93
+ Retrieve details of a specific asset.
94
+
95
+ ```typescript
96
+ async getAsset(assetId: string): Promise<Asset>
97
+ ```
98
+
99
+ **Example:**
100
+ ```typescript
101
+ const asset = await client.getAsset("asset-uuid-here");
102
+ console.log(asset.status);
103
+ console.log(asset.report); // Classification results
104
+ ```
105
+
106
+ ##### listAssets(options)
107
+
108
+ List assets in your project with pagination.
30
109
 
31
- // calls GET https://my-api/data?includeAwesome=true
32
- const res = await fetchData.submit({
33
- query: { includeAwesome: true },
110
+ ```typescript
111
+ async listAssets(options?: {
112
+ pageIndex?: number;
113
+ pageSize?: number;
114
+ }): Promise<{
115
+ items: Asset[];
116
+ total: number;
117
+ pageIndex: number;
118
+ pageSize: number;
119
+ }>
120
+ ```
121
+
122
+ **Example:**
123
+ ```typescript
124
+ const result = await client.listAssets({
125
+ pageIndex: 0,
126
+ pageSize: 20
34
127
  });
35
128
 
36
- console.log(res.data); // { data: { awesome: true } }
129
+ console.log(`Found ${result.total} assets`);
130
+ result.items.forEach(asset => {
131
+ console.log(`${asset.name}: ${asset.status}`);
132
+ });
37
133
  ```
134
+
135
+ #### Static Methods
136
+
137
+ ##### verifyWebhookSignature(payload, signature, secret)
138
+
139
+ Verify webhook signatures to ensure authenticity.
140
+
141
+ ```typescript
142
+ static async verifyWebhookSignature(
143
+ payload: string | object,
144
+ signatureHex: string,
145
+ secret: string
146
+ ): Promise<boolean>
147
+ ```
148
+
149
+ **Example:**
150
+ ```typescript
151
+ // In your webhook handler
152
+ const signature = req.headers['x-calmlens-signature'];
153
+ const payload = req.body;
154
+ const isValid = await CalmLensClient.verifyWebhookSignature(
155
+ payload,
156
+ signature,
157
+ WEBHOOK_SECRET
158
+ );
159
+
160
+ if (!isValid) {
161
+ return res.status(401).send('Unauthorized');
162
+ }
163
+ ```
164
+
165
+ ## Asset Types
166
+
167
+ Assets can be of the following types:
168
+ - `image` - Images (JPEG, PNG, GIF, WebP, etc.)
169
+ - `video` - Video files (MP4, WebM, etc.)
170
+ - `audio` - Audio files (MP3, WAV, etc.)
171
+ - `document` - Documents (PDF, DOC, TXT, etc.)
172
+ - `website` - Web pages and URLs
173
+
174
+ ## Asset Status
175
+
176
+ Assets progress through these statuses:
177
+ - `pending` - Asset is being processed
178
+ - `approved` - Asset passed moderation
179
+ - `rejected` - Asset failed moderation
180
+ - `error` - Processing failed
181
+
182
+ ## Asset Visibility
183
+
184
+ - `public` - Asset is publicly accessible
185
+ - `private` - Asset is only accessible to your project
186
+
187
+ ## Error Handling
188
+
189
+ The SDK throws errors for common issues:
190
+
191
+ ```typescript
192
+ try {
193
+ const asset = await client.submitAsset({
194
+ name: "test.jpg"
195
+ // Missing required file or url
196
+ });
197
+ } catch (error) {
198
+ console.error(error.message); // "Either file content or URL is required"
199
+ }
200
+ ```
201
+
202
+ ## Webhooks
203
+
204
+ CalmLens can send webhooks when asset processing is complete. Use `verifyWebhookSignature` to verify the authenticity of incoming webhooks.
205
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@calmlens/js-sdk",
3
- "version": "0.0.0",
3
+ "version": "0.0.1",
4
4
  "main": "cjs/index.js",
5
5
  "types": "esm/index.d.ts",
6
6
  "module": "esm/index.js",