@calmlens/js-sdk 0.0.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.
@@ -0,0 +1,154 @@
1
+ import * as zod from "zod/v4";
2
+ export declare const CLASSIFICATION_CATEGORIES: readonly ["sexual", "violence", "gore", "self-harm", "harassment", "hate", "illicit", "child-exploitation"];
3
+ export declare const CLASSIFICATION_CATEGORY_SCHEMA: zod.ZodEnum<{
4
+ sexual: "sexual";
5
+ violence: "violence";
6
+ gore: "gore";
7
+ "self-harm": "self-harm";
8
+ harassment: "harassment";
9
+ hate: "hate";
10
+ illicit: "illicit";
11
+ "child-exploitation": "child-exploitation";
12
+ }>;
13
+ export type ClassificationCategory = zod.infer<typeof CLASSIFICATION_CATEGORY_SCHEMA>;
14
+ export declare const CLASSIFICATION_CATEGORY_INFO_SCHEMA: zod.ZodObject<{
15
+ category: zod.ZodEnum<{
16
+ sexual: "sexual";
17
+ violence: "violence";
18
+ gore: "gore";
19
+ "self-harm": "self-harm";
20
+ harassment: "harassment";
21
+ hate: "hate";
22
+ illicit: "illicit";
23
+ "child-exploitation": "child-exploitation";
24
+ }>;
25
+ displayName: zod.ZodPipe<zod.ZodString, zod.ZodTransform<string, string>>;
26
+ description: zod.ZodPipe<zod.ZodString, zod.ZodTransform<string, string>>;
27
+ textOnly: zod.ZodBoolean;
28
+ supportsImages: zod.ZodBoolean;
29
+ }, zod.z.core.$strip>;
30
+ export type ClassificationCategoryInfo = zod.infer<typeof CLASSIFICATION_CATEGORY_INFO_SCHEMA>;
31
+ export declare const CLASSIFICATION_CATEGORY_INFO: Record<ClassificationCategory, ClassificationCategoryInfo>;
32
+ export declare const getCategoryInfo: (category: ClassificationCategory) => ClassificationCategoryInfo;
33
+ export declare const LIKELIHOOD_SCHEMA: zod.ZodEnum<{
34
+ VERY_UNLIKELY: "VERY_UNLIKELY";
35
+ UNLIKELY: "UNLIKELY";
36
+ POSSIBLE: "POSSIBLE";
37
+ LIKELY: "LIKELY";
38
+ VERY_LIKELY: "VERY_LIKELY";
39
+ }>;
40
+ export type Likelihood = zod.infer<typeof LIKELIHOOD_SCHEMA>;
41
+ export declare const CLASSIFICATION_CATEGORY_REPORT_SCHEMA: zod.ZodObject<{
42
+ category: zod.ZodEnum<{
43
+ sexual: "sexual";
44
+ violence: "violence";
45
+ gore: "gore";
46
+ "self-harm": "self-harm";
47
+ harassment: "harassment";
48
+ hate: "hate";
49
+ illicit: "illicit";
50
+ "child-exploitation": "child-exploitation";
51
+ }>;
52
+ likelihood: zod.ZodEnum<{
53
+ VERY_UNLIKELY: "VERY_UNLIKELY";
54
+ UNLIKELY: "UNLIKELY";
55
+ POSSIBLE: "POSSIBLE";
56
+ LIKELY: "LIKELY";
57
+ VERY_LIKELY: "VERY_LIKELY";
58
+ }>;
59
+ score: zod.ZodNumber;
60
+ }, zod.z.core.$strip>;
61
+ export type ClassificationCategoryReport = zod.infer<typeof CLASSIFICATION_CATEGORY_REPORT_SCHEMA>;
62
+ export declare const CATEGORIES_SCHEMA: zod.ZodRecord<zod.ZodEnum<{
63
+ sexual: "sexual";
64
+ violence: "violence";
65
+ gore: "gore";
66
+ "self-harm": "self-harm";
67
+ harassment: "harassment";
68
+ hate: "hate";
69
+ illicit: "illicit";
70
+ "child-exploitation": "child-exploitation";
71
+ }> & zod.z.core.$partial, zod.ZodObject<{
72
+ category: zod.ZodEnum<{
73
+ sexual: "sexual";
74
+ violence: "violence";
75
+ gore: "gore";
76
+ "self-harm": "self-harm";
77
+ harassment: "harassment";
78
+ hate: "hate";
79
+ illicit: "illicit";
80
+ "child-exploitation": "child-exploitation";
81
+ }>;
82
+ likelihood: zod.ZodEnum<{
83
+ VERY_UNLIKELY: "VERY_UNLIKELY";
84
+ UNLIKELY: "UNLIKELY";
85
+ POSSIBLE: "POSSIBLE";
86
+ LIKELY: "LIKELY";
87
+ VERY_LIKELY: "VERY_LIKELY";
88
+ }>;
89
+ score: zod.ZodNumber;
90
+ }, zod.z.core.$strip>>;
91
+ export type ClassificationCategories = zod.infer<typeof CATEGORIES_SCHEMA>;
92
+ export declare const CLASSIFICATION_LABEL_SCHEMA: zod.ZodObject<{
93
+ description: zod.ZodPipe<zod.ZodString, zod.ZodTransform<string, string>>;
94
+ score: zod.ZodNumber;
95
+ topicalityScore: zod.ZodOptional<zod.ZodNullable<zod.ZodNumber>>;
96
+ likelihood: zod.ZodEnum<{
97
+ VERY_UNLIKELY: "VERY_UNLIKELY";
98
+ UNLIKELY: "UNLIKELY";
99
+ POSSIBLE: "POSSIBLE";
100
+ LIKELY: "LIKELY";
101
+ VERY_LIKELY: "VERY_LIKELY";
102
+ }>;
103
+ knowledgeBaseId: zod.ZodOptional<zod.ZodNullable<zod.ZodPipe<zod.ZodString, zod.ZodTransform<string, string>>>>;
104
+ }, zod.z.core.$strip>;
105
+ export type ClassificationLabel = zod.infer<typeof CLASSIFICATION_LABEL_SCHEMA>;
106
+ export declare const CLASSIFICATION_REPORT_SCHEMA: zod.ZodObject<{
107
+ processedAt: zod.ZodNumber;
108
+ categories: zod.ZodRecord<zod.ZodEnum<{
109
+ sexual: "sexual";
110
+ violence: "violence";
111
+ gore: "gore";
112
+ "self-harm": "self-harm";
113
+ harassment: "harassment";
114
+ hate: "hate";
115
+ illicit: "illicit";
116
+ "child-exploitation": "child-exploitation";
117
+ }> & zod.z.core.$partial, zod.ZodObject<{
118
+ category: zod.ZodEnum<{
119
+ sexual: "sexual";
120
+ violence: "violence";
121
+ gore: "gore";
122
+ "self-harm": "self-harm";
123
+ harassment: "harassment";
124
+ hate: "hate";
125
+ illicit: "illicit";
126
+ "child-exploitation": "child-exploitation";
127
+ }>;
128
+ likelihood: zod.ZodEnum<{
129
+ VERY_UNLIKELY: "VERY_UNLIKELY";
130
+ UNLIKELY: "UNLIKELY";
131
+ POSSIBLE: "POSSIBLE";
132
+ LIKELY: "LIKELY";
133
+ VERY_LIKELY: "VERY_LIKELY";
134
+ }>;
135
+ score: zod.ZodNumber;
136
+ }, zod.z.core.$strip>>;
137
+ flagged: zod.ZodBoolean;
138
+ score: zod.ZodNumber;
139
+ notes: zod.ZodOptional<zod.ZodNullable<zod.ZodPipe<zod.ZodString, zod.ZodTransform<string, string>>>>;
140
+ labels: zod.ZodOptional<zod.ZodNullable<zod.ZodArray<zod.ZodObject<{
141
+ description: zod.ZodPipe<zod.ZodString, zod.ZodTransform<string, string>>;
142
+ score: zod.ZodNumber;
143
+ topicalityScore: zod.ZodOptional<zod.ZodNullable<zod.ZodNumber>>;
144
+ likelihood: zod.ZodEnum<{
145
+ VERY_UNLIKELY: "VERY_UNLIKELY";
146
+ UNLIKELY: "UNLIKELY";
147
+ POSSIBLE: "POSSIBLE";
148
+ LIKELY: "LIKELY";
149
+ VERY_LIKELY: "VERY_LIKELY";
150
+ }>;
151
+ knowledgeBaseId: zod.ZodOptional<zod.ZodNullable<zod.ZodPipe<zod.ZodString, zod.ZodTransform<string, string>>>>;
152
+ }, zod.z.core.$strip>>>>;
153
+ }, zod.z.core.$strip>;
154
+ export type ClassificationReport = zod.infer<typeof CLASSIFICATION_REPORT_SCHEMA>;
@@ -0,0 +1,113 @@
1
+ import * as zod from "zod/v4";
2
+ import { saneStringField } from "./SchemaUtils";
3
+ // OpenAI Content Moderation Categories (Merged subcategories)
4
+ export const CLASSIFICATION_CATEGORIES = [
5
+ "sexual",
6
+ "violence",
7
+ "gore",
8
+ "self-harm",
9
+ "harassment",
10
+ "hate",
11
+ "illicit",
12
+ "child-exploitation",
13
+ ];
14
+ export const CLASSIFICATION_CATEGORY_SCHEMA = zod.enum(CLASSIFICATION_CATEGORIES);
15
+ // Type to define category information including whether it's text-only
16
+ export const CLASSIFICATION_CATEGORY_INFO_SCHEMA = zod.object({
17
+ category: CLASSIFICATION_CATEGORY_SCHEMA,
18
+ displayName: saneStringField(),
19
+ description: saneStringField(),
20
+ textOnly: zod.boolean(),
21
+ supportsImages: zod.boolean(),
22
+ });
23
+ // Category information mapping
24
+ export const CLASSIFICATION_CATEGORY_INFO = {
25
+ sexual: {
26
+ category: "sexual",
27
+ displayName: "Sexual Content",
28
+ description: "Content meant to arouse sexual excitement, such as the description of sexual activity, or that promotes sexual services.",
29
+ textOnly: false,
30
+ supportsImages: true,
31
+ },
32
+ violence: {
33
+ category: "violence",
34
+ displayName: "Violence",
35
+ description: "Content that depicts death, violence, or physical injury.",
36
+ textOnly: false,
37
+ supportsImages: true,
38
+ },
39
+ gore: {
40
+ category: "gore",
41
+ displayName: "Gore",
42
+ description: "Content that depicts death, violence, or physical injury in graphic, explicit detail.",
43
+ textOnly: false,
44
+ supportsImages: true,
45
+ },
46
+ "self-harm": {
47
+ category: "self-harm",
48
+ displayName: "Self-Harm",
49
+ description: "Content that promotes, encourages, or depicts acts of self-harm, including intent and instructions for self-harm activities.",
50
+ textOnly: false,
51
+ supportsImages: true,
52
+ },
53
+ harassment: {
54
+ category: "harassment",
55
+ displayName: "Harassment",
56
+ description: "Content that expresses, incites, or promotes harassing language towards any target, including threatening harassment.",
57
+ textOnly: true,
58
+ supportsImages: false,
59
+ },
60
+ hate: {
61
+ category: "hate",
62
+ displayName: "Hate Speech",
63
+ description: "Content that expresses, incites, or promotes hate based on race, gender, ethnicity, religion, nationality, sexual orientation, disability status, or caste, including threatening hate speech.",
64
+ textOnly: true,
65
+ supportsImages: false,
66
+ },
67
+ illicit: {
68
+ category: "illicit",
69
+ displayName: "Illicit Content",
70
+ description: "Content that gives advice or instruction on how to commit illicit acts, including violent illegal activities.",
71
+ textOnly: true,
72
+ supportsImages: false,
73
+ },
74
+ "child-exploitation": {
75
+ category: "child-exploitation",
76
+ displayName: "Child Exploitation",
77
+ description: "Content that sexualizes, grooms, abuses, or otherwise exploits children under 18 years old.",
78
+ textOnly: true,
79
+ supportsImages: false,
80
+ },
81
+ };
82
+ // Helper function to get category info
83
+ export const getCategoryInfo = (category) => {
84
+ return CLASSIFICATION_CATEGORY_INFO[category];
85
+ };
86
+ export const LIKELIHOOD_SCHEMA = zod.enum([
87
+ "VERY_UNLIKELY",
88
+ "UNLIKELY",
89
+ "POSSIBLE",
90
+ "LIKELY",
91
+ "VERY_LIKELY",
92
+ ]);
93
+ export const CLASSIFICATION_CATEGORY_REPORT_SCHEMA = zod.object({
94
+ category: CLASSIFICATION_CATEGORY_SCHEMA,
95
+ likelihood: LIKELIHOOD_SCHEMA,
96
+ score: zod.number(),
97
+ });
98
+ export const CATEGORIES_SCHEMA = zod.partialRecord(CLASSIFICATION_CATEGORY_SCHEMA, CLASSIFICATION_CATEGORY_REPORT_SCHEMA);
99
+ export const CLASSIFICATION_LABEL_SCHEMA = zod.object({
100
+ description: saneStringField(),
101
+ score: zod.number(),
102
+ topicalityScore: zod.number().nullish(),
103
+ likelihood: LIKELIHOOD_SCHEMA,
104
+ knowledgeBaseId: saneStringField().nullish(),
105
+ });
106
+ export const CLASSIFICATION_REPORT_SCHEMA = zod.object({
107
+ processedAt: zod.number(),
108
+ categories: CATEGORIES_SCHEMA,
109
+ flagged: zod.boolean(),
110
+ score: zod.number(),
111
+ notes: saneStringField().nullish(),
112
+ labels: zod.array(CLASSIFICATION_LABEL_SCHEMA).nullish(),
113
+ });
@@ -0,0 +1,11 @@
1
+ import * as zod from "zod/v4";
2
+ export declare const primaryUuidField: () => zod.ZodString;
3
+ export declare const uuidField: () => zod.ZodString;
4
+ export declare const createdAtField: () => zod.ZodNumber;
5
+ export declare const updatedAtField: () => zod.ZodOptional<zod.ZodNumber>;
6
+ export interface SaneStringOptions {
7
+ type?: "small" | "medium" | "large";
8
+ minWidth?: number;
9
+ }
10
+ export declare const saneStringField: (options?: SaneStringOptions) => zod.ZodPipe<zod.ZodString, zod.ZodTransform<string, string>>;
11
+ export declare const urlField: () => zod.ZodPipe<zod.ZodString, zod.ZodTransform<string, string>>;
@@ -0,0 +1,46 @@
1
+ import * as zod from "zod/v4";
2
+ import { meta, primaryKey, updatedAt } from "zodbase";
3
+ import { validateUrl } from "./ValidationUtils";
4
+ export const primaryUuidField = () => zod
5
+ .string()
6
+ .uuid({
7
+ version: "v4",
8
+ })
9
+ .meta(meta([primaryKey()]));
10
+ export const uuidField = () => zod.string().uuid({
11
+ version: "v4",
12
+ });
13
+ export const createdAtField = () => zod.number().int();
14
+ export const updatedAtField = () => zod
15
+ .number()
16
+ .int()
17
+ .optional()
18
+ .meta(meta([updatedAt()]));
19
+ const SIZE_LIMITS = {
20
+ small: 64,
21
+ medium: 200,
22
+ large: 1500,
23
+ };
24
+ export const saneStringField = (options) => {
25
+ return zod
26
+ .string()
27
+ .transform((value) => value.trim())
28
+ .refine((value) => {
29
+ if ((options === null || options === void 0 ? void 0 : options.minWidth) && value.length < options.minWidth) {
30
+ return false;
31
+ }
32
+ return true;
33
+ }, "Not long enough")
34
+ .refine((value) => {
35
+ var _a;
36
+ const sizeLimit = SIZE_LIMITS[(_a = options === null || options === void 0 ? void 0 : options.type) !== null && _a !== void 0 ? _a : "medium"];
37
+ return typeof value === "string" && value.length < sizeLimit;
38
+ }, "Too long");
39
+ };
40
+ export const urlField = () => saneStringField().refine((value) => {
41
+ /*if (encodeURI(value) !== value) {
42
+ return false;
43
+ }*/
44
+ const parsedUrl = validateUrl(value);
45
+ return Boolean(parsedUrl);
46
+ }, "Invalid link");
@@ -0,0 +1,13 @@
1
+ import type { AssetVisibility } from "./Asset";
2
+ export type SubmitAssetOptions = ({
3
+ file: string;
4
+ fileType: string;
5
+ url?: string;
6
+ } | {
7
+ url: string;
8
+ }) & {
9
+ name: string;
10
+ description?: string;
11
+ keepAfterProcessing?: boolean;
12
+ visibility?: AssetVisibility;
13
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export declare const validateUrl: (url: string) => URL | undefined;
@@ -0,0 +1,29 @@
1
+ const VALID_PREFIXES = ["http://", "https://", "mailto:", "tel:", "sms:"];
2
+ const EMAIL_REGEX = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
3
+ const PHONE_REGEX = /^\+?[0-9]+$/;
4
+ export const validateUrl = (url) => {
5
+ if (!url) {
6
+ return undefined;
7
+ }
8
+ let parsedUrl = url;
9
+ if (!VALID_PREFIXES.some((prefix) => parsedUrl.startsWith(prefix))) {
10
+ if (EMAIL_REGEX.test(parsedUrl)) {
11
+ parsedUrl = `mailto:${parsedUrl}`;
12
+ }
13
+ else if (PHONE_REGEX.test(parsedUrl)) {
14
+ parsedUrl = `tel:${parsedUrl}`;
15
+ }
16
+ else {
17
+ parsedUrl = `https://${parsedUrl}`;
18
+ }
19
+ }
20
+ try {
21
+ const url = new URL(parsedUrl);
22
+ if (url.protocol.includes("http") && !url.host.includes(".")) {
23
+ return undefined;
24
+ }
25
+ return url;
26
+ }
27
+ catch (error) { }
28
+ return undefined;
29
+ };
package/esm/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export { default as CalmLensClient } from "./CalmLensClient";
2
+ export type { CalmLensClientOptions } from "./CalmLensTypes";
3
+ export { verifyWebhookSignature } from "./CalmLensUtils";
package/esm/index.js ADDED
@@ -0,0 +1,3 @@
1
+ /// <reference types="typescript" />
2
+ export { default as CalmLensClient } from "./CalmLensClient";
3
+ export { verifyWebhookSignature } from "./CalmLensUtils";
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "@calmlens/js-sdk",
3
+ "version": "0.0.0",
4
+ "main": "cjs/index.js",
5
+ "types": "esm/index.d.ts",
6
+ "module": "esm/index.js",
7
+ "sideEffects": false,
8
+ "scripts": {
9
+ "generate:fixtures": "bun scripts/generateFixtures.ts",
10
+ "prepublishOnly": "npm run check:fix && npm run test && npm run build",
11
+ "test": "echo 'Tests pass'",
12
+ "example:start": "cd example && npm run start",
13
+ "check:fix": "tsc --noEmit --project tsconfig.json && npx @biomejs/biome check --write",
14
+ "check": "tsc --noEmit --project tsconfig.json && npx @biomejs/biome check",
15
+ "cleanup": "rimraf esm && rimraf cjs",
16
+ "build": "npm run cleanup && npm run build:esm && npm run build:cjs",
17
+ "build:esm": "tsc --module es2015 --target es2016 --outDir esm --preserveWatchOutput && rm -rf esm/tests && node scripts/post-build.js esm",
18
+ "build:cjs": "tsc --module commonjs --target es5 --outDir cjs --preserveWatchOutput && rm -rf cjs/tests && node scripts/post-build.js cjs",
19
+ "website:dev": "cd website && npm run start",
20
+ "website:deploy": "cd website && npm run deploy"
21
+ },
22
+ "keywords": [
23
+ "typescript",
24
+ "javascript",
25
+ "node",
26
+ "web",
27
+ "api",
28
+ "typed",
29
+ "cache",
30
+ "fetch",
31
+ "retry",
32
+ "middleware"
33
+ ],
34
+ "files": [
35
+ "LICENSE",
36
+ "README.md",
37
+ "esm/",
38
+ "cjs/",
39
+ "bin/"
40
+ ],
41
+ "jest": {
42
+ "transform": {
43
+ "^.+\\.(t|j)sx?$": [
44
+ "@swc/jest",
45
+ {
46
+ "env": {}
47
+ }
48
+ ]
49
+ }
50
+ },
51
+ "devDependencies": {
52
+ "@biomejs/biome": "^2.2.5",
53
+ "@swc/core": "^1.13.5",
54
+ "@swc/jest": "^0.2.39",
55
+ "@types/bun": "^1.2.22",
56
+ "@types/jest": "^30.0.0",
57
+ "@types/lodash": "^4.17.20",
58
+ "@types/node": "24.6.2",
59
+ "chalk": "4.1.2",
60
+ "cross-env": "10.1.0",
61
+ "esbuild": "^0.25.10",
62
+ "jest": "30.2.0",
63
+ "npm-run-all": "4.1.5",
64
+ "rimraf": "6.0.1",
65
+ "typescript": "^5.9.3",
66
+ "zod": "4.1.3"
67
+ },
68
+ "dependencies": {
69
+ "api-def": "^0.12.0-alpha.55"
70
+ }
71
+ }