glin-profanity 3.2.0 → 3.2.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 (65) hide show
  1. package/dist/{types-Dj5vaoch.d.cts → Filter-BGcyIAvO.d.ts} +2 -162
  2. package/dist/{types-Dj5vaoch.d.ts → Filter-D34Wsmrj.d.cts} +2 -162
  3. package/dist/frameworks/index.cjs +5257 -0
  4. package/dist/frameworks/index.d.cts +2 -0
  5. package/dist/frameworks/index.d.ts +2 -0
  6. package/dist/frameworks/index.js +5252 -0
  7. package/dist/frameworks/nextjs.cjs +5257 -0
  8. package/dist/frameworks/nextjs.d.cts +173 -0
  9. package/dist/frameworks/nextjs.d.ts +173 -0
  10. package/dist/frameworks/nextjs.js +5252 -0
  11. package/dist/index.cjs +0 -28
  12. package/dist/index.d.cts +5 -29
  13. package/dist/index.d.ts +5 -29
  14. package/dist/index.js +1 -28
  15. package/dist/integrations/index.cjs +6110 -0
  16. package/dist/integrations/index.d.cts +5 -0
  17. package/dist/integrations/index.d.ts +5 -0
  18. package/dist/integrations/index.js +6082 -0
  19. package/dist/integrations/langchain.cjs +5252 -0
  20. package/dist/integrations/langchain.d.cts +231 -0
  21. package/dist/integrations/langchain.d.ts +231 -0
  22. package/dist/integrations/langchain.js +5239 -0
  23. package/dist/integrations/openai.cjs +5367 -0
  24. package/dist/integrations/openai.d.cts +167 -0
  25. package/dist/integrations/openai.d.ts +167 -0
  26. package/dist/integrations/openai.js +5362 -0
  27. package/dist/integrations/semantic.cjs +5314 -0
  28. package/dist/integrations/semantic.d.cts +268 -0
  29. package/dist/integrations/semantic.d.ts +268 -0
  30. package/dist/integrations/semantic.js +5309 -0
  31. package/dist/integrations/vercel-ai.cjs +5282 -0
  32. package/dist/integrations/vercel-ai.d.cts +224 -0
  33. package/dist/integrations/vercel-ai.d.ts +224 -0
  34. package/dist/integrations/vercel-ai.js +5273 -0
  35. package/dist/ml/index.cjs +207 -0
  36. package/dist/ml/index.d.cts +5 -2
  37. package/dist/ml/index.d.ts +5 -2
  38. package/dist/ml/index.js +203 -1
  39. package/dist/ml/transformers.cjs +5237 -0
  40. package/dist/ml/transformers.d.cts +232 -0
  41. package/dist/ml/transformers.d.ts +232 -0
  42. package/dist/ml/transformers.js +5231 -0
  43. package/dist/multimodal/audio.cjs +5269 -0
  44. package/dist/multimodal/audio.d.cts +255 -0
  45. package/dist/multimodal/audio.d.ts +255 -0
  46. package/dist/multimodal/audio.js +5264 -0
  47. package/dist/multimodal/index.cjs +5432 -0
  48. package/dist/multimodal/index.d.cts +4 -0
  49. package/dist/multimodal/index.d.ts +4 -0
  50. package/dist/multimodal/index.js +5422 -0
  51. package/dist/multimodal/ocr.cjs +5193 -0
  52. package/dist/multimodal/ocr.d.cts +157 -0
  53. package/dist/multimodal/ocr.d.ts +157 -0
  54. package/dist/multimodal/ocr.js +5187 -0
  55. package/dist/react.cjs +5133 -0
  56. package/dist/react.d.cts +13 -0
  57. package/dist/react.d.ts +13 -0
  58. package/dist/react.js +5131 -0
  59. package/dist/types-B9c_ik4k.d.cts +88 -0
  60. package/dist/types-B9c_ik4k.d.ts +88 -0
  61. package/dist/types-BuKh9tvV.d.ts +20 -0
  62. package/dist/types-Ct_ueYqw.d.cts +76 -0
  63. package/dist/types-Ct_ueYqw.d.ts +76 -0
  64. package/dist/types-DI8nzwWc.d.cts +20 -0
  65. package/package.json +170 -3
@@ -0,0 +1,173 @@
1
+ import { F as FilterConfig, C as CheckProfanityResult } from '../types-B9c_ik4k.cjs';
2
+ export { L as Language } from '../types-B9c_ik4k.cjs';
3
+
4
+ /**
5
+ * Next.js Middleware and Utilities for glin-profanity
6
+ *
7
+ * Provides middleware, API route helpers, and React components
8
+ * for integrating profanity detection in Next.js applications.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * // middleware.ts
13
+ * import { createProfanityMiddleware } from 'glin-profanity/nextjs';
14
+ *
15
+ * export const middleware = createProfanityMiddleware({
16
+ * paths: ['/api/chat', '/api/comments'],
17
+ * blockProfanity: true,
18
+ * });
19
+ *
20
+ * // API Route
21
+ * import { withProfanityCheck } from 'glin-profanity/nextjs';
22
+ *
23
+ * export const POST = withProfanityCheck(async (req, profanityResult) => {
24
+ * if (profanityResult.blocked) {
25
+ * return Response.json({ error: profanityResult.reason }, { status: 400 });
26
+ * }
27
+ * // Continue processing...
28
+ * });
29
+ * ```
30
+ *
31
+ * @packageDocumentation
32
+ * @module glin-profanity/nextjs
33
+ */
34
+
35
+ /**
36
+ * Middleware configuration
37
+ */
38
+ interface ProfanityMiddlewareConfig {
39
+ /** Paths to check (glob patterns supported) */
40
+ paths?: string[];
41
+ /** Paths to exclude */
42
+ excludePaths?: string[];
43
+ /** Block requests with profanity (return 400) */
44
+ blockProfanity?: boolean;
45
+ /** Add profanity result to request headers */
46
+ addHeaders?: boolean;
47
+ /** Custom response for blocked requests */
48
+ blockedResponse?: {
49
+ status?: number;
50
+ message?: string;
51
+ };
52
+ /** Fields in request body to check */
53
+ checkFields?: string[];
54
+ /** Filter configuration */
55
+ filterConfig?: Partial<FilterConfig>;
56
+ }
57
+ /**
58
+ * Profanity check result for middleware
59
+ */
60
+ interface MiddlewareProfanityResult {
61
+ /** Whether the request was blocked */
62
+ blocked: boolean;
63
+ /** Reason for blocking (if blocked) */
64
+ reason?: string;
65
+ /** Profane words found */
66
+ profaneWords: string[];
67
+ /** Fields that contained profanity */
68
+ flaggedFields: string[];
69
+ /** Full check result */
70
+ checkResult?: CheckProfanityResult;
71
+ }
72
+ /**
73
+ * Creates Next.js middleware for profanity detection
74
+ *
75
+ * @example
76
+ * ```typescript
77
+ * // middleware.ts
78
+ * import { createProfanityMiddleware } from 'glin-profanity/nextjs';
79
+ *
80
+ * export const middleware = createProfanityMiddleware({
81
+ * paths: ['/api/chat', '/api/comments/*'],
82
+ * blockProfanity: true,
83
+ * checkFields: ['message', 'content', 'text'],
84
+ * });
85
+ *
86
+ * export const config = {
87
+ * matcher: ['/api/:path*'],
88
+ * };
89
+ * ```
90
+ */
91
+ declare function createProfanityMiddleware(config?: ProfanityMiddlewareConfig): (request: Request) => Promise<Response>;
92
+ /**
93
+ * Higher-order function to wrap API route handlers with profanity checking
94
+ *
95
+ * @example
96
+ * ```typescript
97
+ * // app/api/chat/route.ts
98
+ * import { withProfanityCheck } from 'glin-profanity/nextjs';
99
+ *
100
+ * export const POST = withProfanityCheck(
101
+ * async (req, profanityResult) => {
102
+ * if (profanityResult.blocked) {
103
+ * return Response.json({ error: profanityResult.reason }, { status: 400 });
104
+ * }
105
+ *
106
+ * const { message } = await req.json();
107
+ * // Process message...
108
+ * return Response.json({ success: true });
109
+ * },
110
+ * {
111
+ * checkFields: ['message'],
112
+ * blockProfanity: false, // Handle manually
113
+ * }
114
+ * );
115
+ * ```
116
+ */
117
+ declare function withProfanityCheck<T>(handler: (request: Request, profanityResult: MiddlewareProfanityResult) => Promise<T>, config?: {
118
+ checkFields?: string[];
119
+ blockProfanity?: boolean;
120
+ filterConfig?: Partial<FilterConfig>;
121
+ }): (request: Request) => Promise<T | Response>;
122
+ /**
123
+ * Server action wrapper for profanity checking
124
+ *
125
+ * @example
126
+ * ```typescript
127
+ * // actions.ts
128
+ * 'use server';
129
+ * import { createServerAction } from 'glin-profanity/nextjs';
130
+ *
131
+ * export const submitComment = createServerAction(
132
+ * async (data: { comment: string }) => {
133
+ * // Save to database
134
+ * await db.comments.create({ data });
135
+ * return { success: true };
136
+ * },
137
+ * {
138
+ * checkFields: ['comment'],
139
+ * onProfanity: (result) => {
140
+ * return { error: 'Please remove inappropriate language' };
141
+ * },
142
+ * }
143
+ * );
144
+ * ```
145
+ */
146
+ declare function createServerAction<TInput extends Record<string, unknown>, TOutput>(action: (data: TInput) => Promise<TOutput>, config?: {
147
+ checkFields?: string[];
148
+ filterConfig?: Partial<FilterConfig>;
149
+ onProfanity?: (result: MiddlewareProfanityResult) => TOutput;
150
+ }): (data: TInput) => Promise<TOutput>;
151
+ /**
152
+ * Utility functions for use in API routes
153
+ */
154
+ declare const profanityUtils: {
155
+ /**
156
+ * Quick check for profanity in a single string
157
+ */
158
+ check(text: string, config?: Partial<FilterConfig>): CheckProfanityResult;
159
+ /**
160
+ * Check and optionally censor text
161
+ */
162
+ censor(text: string, replacement?: string, config?: Partial<FilterConfig>): string;
163
+ /**
164
+ * Check multiple fields in an object
165
+ */
166
+ checkObject(obj: Record<string, unknown>, fields: string[], config?: Partial<FilterConfig>): {
167
+ containsProfanity: boolean;
168
+ flaggedFields: string[];
169
+ profaneWords: string[];
170
+ };
171
+ };
172
+
173
+ export { CheckProfanityResult, FilterConfig, type MiddlewareProfanityResult, type ProfanityMiddlewareConfig, createProfanityMiddleware, createServerAction, profanityUtils, withProfanityCheck };
@@ -0,0 +1,173 @@
1
+ import { F as FilterConfig, C as CheckProfanityResult } from '../types-B9c_ik4k.js';
2
+ export { L as Language } from '../types-B9c_ik4k.js';
3
+
4
+ /**
5
+ * Next.js Middleware and Utilities for glin-profanity
6
+ *
7
+ * Provides middleware, API route helpers, and React components
8
+ * for integrating profanity detection in Next.js applications.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * // middleware.ts
13
+ * import { createProfanityMiddleware } from 'glin-profanity/nextjs';
14
+ *
15
+ * export const middleware = createProfanityMiddleware({
16
+ * paths: ['/api/chat', '/api/comments'],
17
+ * blockProfanity: true,
18
+ * });
19
+ *
20
+ * // API Route
21
+ * import { withProfanityCheck } from 'glin-profanity/nextjs';
22
+ *
23
+ * export const POST = withProfanityCheck(async (req, profanityResult) => {
24
+ * if (profanityResult.blocked) {
25
+ * return Response.json({ error: profanityResult.reason }, { status: 400 });
26
+ * }
27
+ * // Continue processing...
28
+ * });
29
+ * ```
30
+ *
31
+ * @packageDocumentation
32
+ * @module glin-profanity/nextjs
33
+ */
34
+
35
+ /**
36
+ * Middleware configuration
37
+ */
38
+ interface ProfanityMiddlewareConfig {
39
+ /** Paths to check (glob patterns supported) */
40
+ paths?: string[];
41
+ /** Paths to exclude */
42
+ excludePaths?: string[];
43
+ /** Block requests with profanity (return 400) */
44
+ blockProfanity?: boolean;
45
+ /** Add profanity result to request headers */
46
+ addHeaders?: boolean;
47
+ /** Custom response for blocked requests */
48
+ blockedResponse?: {
49
+ status?: number;
50
+ message?: string;
51
+ };
52
+ /** Fields in request body to check */
53
+ checkFields?: string[];
54
+ /** Filter configuration */
55
+ filterConfig?: Partial<FilterConfig>;
56
+ }
57
+ /**
58
+ * Profanity check result for middleware
59
+ */
60
+ interface MiddlewareProfanityResult {
61
+ /** Whether the request was blocked */
62
+ blocked: boolean;
63
+ /** Reason for blocking (if blocked) */
64
+ reason?: string;
65
+ /** Profane words found */
66
+ profaneWords: string[];
67
+ /** Fields that contained profanity */
68
+ flaggedFields: string[];
69
+ /** Full check result */
70
+ checkResult?: CheckProfanityResult;
71
+ }
72
+ /**
73
+ * Creates Next.js middleware for profanity detection
74
+ *
75
+ * @example
76
+ * ```typescript
77
+ * // middleware.ts
78
+ * import { createProfanityMiddleware } from 'glin-profanity/nextjs';
79
+ *
80
+ * export const middleware = createProfanityMiddleware({
81
+ * paths: ['/api/chat', '/api/comments/*'],
82
+ * blockProfanity: true,
83
+ * checkFields: ['message', 'content', 'text'],
84
+ * });
85
+ *
86
+ * export const config = {
87
+ * matcher: ['/api/:path*'],
88
+ * };
89
+ * ```
90
+ */
91
+ declare function createProfanityMiddleware(config?: ProfanityMiddlewareConfig): (request: Request) => Promise<Response>;
92
+ /**
93
+ * Higher-order function to wrap API route handlers with profanity checking
94
+ *
95
+ * @example
96
+ * ```typescript
97
+ * // app/api/chat/route.ts
98
+ * import { withProfanityCheck } from 'glin-profanity/nextjs';
99
+ *
100
+ * export const POST = withProfanityCheck(
101
+ * async (req, profanityResult) => {
102
+ * if (profanityResult.blocked) {
103
+ * return Response.json({ error: profanityResult.reason }, { status: 400 });
104
+ * }
105
+ *
106
+ * const { message } = await req.json();
107
+ * // Process message...
108
+ * return Response.json({ success: true });
109
+ * },
110
+ * {
111
+ * checkFields: ['message'],
112
+ * blockProfanity: false, // Handle manually
113
+ * }
114
+ * );
115
+ * ```
116
+ */
117
+ declare function withProfanityCheck<T>(handler: (request: Request, profanityResult: MiddlewareProfanityResult) => Promise<T>, config?: {
118
+ checkFields?: string[];
119
+ blockProfanity?: boolean;
120
+ filterConfig?: Partial<FilterConfig>;
121
+ }): (request: Request) => Promise<T | Response>;
122
+ /**
123
+ * Server action wrapper for profanity checking
124
+ *
125
+ * @example
126
+ * ```typescript
127
+ * // actions.ts
128
+ * 'use server';
129
+ * import { createServerAction } from 'glin-profanity/nextjs';
130
+ *
131
+ * export const submitComment = createServerAction(
132
+ * async (data: { comment: string }) => {
133
+ * // Save to database
134
+ * await db.comments.create({ data });
135
+ * return { success: true };
136
+ * },
137
+ * {
138
+ * checkFields: ['comment'],
139
+ * onProfanity: (result) => {
140
+ * return { error: 'Please remove inappropriate language' };
141
+ * },
142
+ * }
143
+ * );
144
+ * ```
145
+ */
146
+ declare function createServerAction<TInput extends Record<string, unknown>, TOutput>(action: (data: TInput) => Promise<TOutput>, config?: {
147
+ checkFields?: string[];
148
+ filterConfig?: Partial<FilterConfig>;
149
+ onProfanity?: (result: MiddlewareProfanityResult) => TOutput;
150
+ }): (data: TInput) => Promise<TOutput>;
151
+ /**
152
+ * Utility functions for use in API routes
153
+ */
154
+ declare const profanityUtils: {
155
+ /**
156
+ * Quick check for profanity in a single string
157
+ */
158
+ check(text: string, config?: Partial<FilterConfig>): CheckProfanityResult;
159
+ /**
160
+ * Check and optionally censor text
161
+ */
162
+ censor(text: string, replacement?: string, config?: Partial<FilterConfig>): string;
163
+ /**
164
+ * Check multiple fields in an object
165
+ */
166
+ checkObject(obj: Record<string, unknown>, fields: string[], config?: Partial<FilterConfig>): {
167
+ containsProfanity: boolean;
168
+ flaggedFields: string[];
169
+ profaneWords: string[];
170
+ };
171
+ };
172
+
173
+ export { CheckProfanityResult, FilterConfig, type MiddlewareProfanityResult, type ProfanityMiddlewareConfig, createProfanityMiddleware, createServerAction, profanityUtils, withProfanityCheck };