safetygates 0.1.1 → 0.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "safetygates",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Official SDK for SafetyGates content moderation API",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
package/src/index.d.ts CHANGED
@@ -5,29 +5,36 @@
5
5
  * Licensed under the MIT License
6
6
  */
7
7
 
8
+ export type StrictnessLevel = 'strict' | 'balanced' | 'permissive';
9
+
10
+ export interface ClassifyOptions {
11
+ /** Moderation strictness: 'strict', 'balanced' (default), or 'permissive'. Paid tiers only. */
12
+ strictness?: StrictnessLevel;
13
+ }
14
+
8
15
  export interface ClassifyResult {
16
+ request_id: string;
9
17
  safe: boolean;
10
18
  confidence: number;
11
- categories: {
12
- toxic: number;
13
- spam: number;
14
- hate: number;
15
- nsfw: number;
16
- harassment: number;
17
- };
19
+ categories: Record<string, number>;
20
+ lang: string | null;
21
+ strictness: StrictnessLevel;
18
22
  latency_us: number;
23
+ watermark: string | null;
24
+ }
25
+
26
+ export interface BatchItemResult {
27
+ safe: boolean;
28
+ categories: Record<string, number>;
29
+ lang: string | null;
19
30
  }
20
31
 
21
32
  export interface BatchClassifyResult {
22
- results: Array<{
23
- toxic: number;
24
- spam: number;
25
- hate: number;
26
- nsfw: number;
27
- harassment: number;
28
- }>;
33
+ request_id: string;
34
+ results: BatchItemResult[];
29
35
  total_latency_us: number;
30
36
  items_per_second: number;
37
+ watermark: string | null;
31
38
  }
32
39
 
33
40
  export interface HealthResult {
@@ -51,18 +58,24 @@ export declare class SafetyGates {
51
58
 
52
59
  /**
53
60
  * Classify text for safety
61
+ * @param text - Text to classify
62
+ * @param options - Classification options including strictness
54
63
  */
55
- classify(text: string): Promise<ClassifyResult>;
64
+ classify(text: string, options?: ClassifyOptions): Promise<ClassifyResult>;
56
65
 
57
66
  /**
58
67
  * Classify multiple texts in batch
68
+ * @param texts - Array of texts to classify (max 10,000)
69
+ * @param options - Classification options including strictness
59
70
  */
60
- classifyBatch(texts: string[]): Promise<BatchClassifyResult>;
71
+ classifyBatch(texts: string[], options?: ClassifyOptions): Promise<BatchClassifyResult>;
61
72
 
62
73
  /**
63
74
  * Check if text is safe (convenience method)
75
+ * @param text - Text to check
76
+ * @param options - Classification options including strictness
64
77
  */
65
- isSafe(text: string): Promise<boolean>;
78
+ isSafe(text: string, options?: ClassifyOptions): Promise<boolean>;
66
79
 
67
80
  /**
68
81
  * Health check
package/src/index.js CHANGED
@@ -64,7 +64,7 @@ class SafetyGates {
64
64
  headers: {
65
65
  'Content-Type': 'application/json',
66
66
  'X-API-Key': this.apiKey,
67
- 'User-Agent': 'safetygates-node/1.0.0',
67
+ 'User-Agent': 'safetygates-node/1.1.0',
68
68
  },
69
69
  timeout: this.timeout,
70
70
  };
@@ -109,24 +109,36 @@ class SafetyGates {
109
109
  /**
110
110
  * Classify a single text
111
111
  * @param {string} text - Text to classify
112
+ * @param {Object} options - Classification options
113
+ * @param {string} options.strictness - 'strict', 'balanced' (default), or 'permissive' (paid tiers only)
112
114
  * @returns {Promise<ClassifyResult>}
113
115
  *
114
116
  * @example
115
117
  * const result = await client.classify('you suck');
116
118
  * console.log(result.safe); // false
117
119
  * console.log(result.confidence); // 0.92
120
+ *
121
+ * // With strictness (paid tiers only)
122
+ * const strict = await client.classify('borderline content', { strictness: 'strict' });
118
123
  */
119
- async classify(text) {
124
+ async classify(text, options = {}) {
120
125
  if (!text || typeof text !== 'string') {
121
126
  throw new Error('Text must be a non-empty string');
122
127
  }
123
128
 
124
- return this._request('POST', '/v1/classify', { text });
129
+ const body = { text };
130
+ if (options.strictness) {
131
+ body.strictness = options.strictness;
132
+ }
133
+
134
+ return this._request('POST', '/v1/classify', body);
125
135
  }
126
136
 
127
137
  /**
128
138
  * Classify multiple texts in batch
129
139
  * @param {string[]} texts - Array of texts to classify (max 10,000)
140
+ * @param {Object} options - Classification options
141
+ * @param {string} options.strictness - 'strict', 'balanced' (default), or 'permissive' (paid tiers only)
130
142
  * @returns {Promise<BatchClassifyResult>}
131
143
  *
132
144
  * @example
@@ -134,8 +146,11 @@ class SafetyGates {
134
146
  * result.results.forEach((r, i) => {
135
147
  * console.log(`Text ${i}: safe=${r.safe}`);
136
148
  * });
149
+ *
150
+ * // With strictness (paid tiers only)
151
+ * const strict = await client.classifyBatch(texts, { strictness: 'strict' });
137
152
  */
138
- async classifyBatch(texts) {
153
+ async classifyBatch(texts, options = {}) {
139
154
  if (!Array.isArray(texts) || texts.length === 0) {
140
155
  throw new Error('Texts must be a non-empty array');
141
156
  }
@@ -143,21 +158,33 @@ class SafetyGates {
143
158
  throw new Error('Batch size cannot exceed 10,000');
144
159
  }
145
160
 
146
- return this._request('POST', '/v1/classify/batch', { texts });
161
+ const body = { texts };
162
+ if (options.strictness) {
163
+ body.strictness = options.strictness;
164
+ }
165
+
166
+ return this._request('POST', '/v1/classify/batch', body);
147
167
  }
148
168
 
149
169
  /**
150
170
  * Check if text is safe (convenience method)
151
171
  * @param {string} text - Text to check
172
+ * @param {Object} options - Classification options
173
+ * @param {string} options.strictness - 'strict', 'balanced' (default), or 'permissive' (paid tiers only)
152
174
  * @returns {Promise<boolean>}
153
175
  *
154
176
  * @example
155
177
  * if (await client.isSafe('hello world')) {
156
178
  * console.log('Content is safe');
157
179
  * }
180
+ *
181
+ * // With strict moderation
182
+ * if (await client.isSafe(userInput, { strictness: 'strict' })) {
183
+ * // Allow content
184
+ * }
158
185
  */
159
- async isSafe(text) {
160
- const result = await this.classify(text);
186
+ async isSafe(text, options = {}) {
187
+ const result = await this.classify(text, options);
161
188
  return result.safe;
162
189
  }
163
190