@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.
- package/README.md +37 -0
- package/cjs/Asset.d.ts +109 -0
- package/cjs/Asset.js +39 -0
- package/cjs/CalmLensClient.d.ts +41 -0
- package/cjs/CalmLensClient.js +199 -0
- package/cjs/CalmLensTypes.d.ts +5 -0
- package/cjs/CalmLensTypes.js +2 -0
- package/cjs/CalmLensUtils.d.ts +1 -0
- package/cjs/CalmLensUtils.js +68 -0
- package/cjs/Classification.d.ts +154 -0
- package/cjs/Classification.js +117 -0
- package/cjs/SchemaUtils.d.ts +11 -0
- package/cjs/SchemaUtils.js +63 -0
- package/cjs/SharedTypes.d.ts +13 -0
- package/cjs/SharedTypes.js +2 -0
- package/cjs/ValidationUtils.d.ts +1 -0
- package/cjs/ValidationUtils.js +33 -0
- package/cjs/index.d.ts +3 -0
- package/cjs/index.js +8 -0
- package/esm/Asset.d.ts +109 -0
- package/esm/Asset.js +36 -0
- package/esm/CalmLensClient.d.ts +41 -0
- package/esm/CalmLensClient.js +142 -0
- package/esm/CalmLensTypes.d.ts +5 -0
- package/esm/CalmLensTypes.js +1 -0
- package/esm/CalmLensUtils.d.ts +1 -0
- package/esm/CalmLensUtils.js +28 -0
- package/esm/Classification.d.ts +154 -0
- package/esm/Classification.js +113 -0
- package/esm/SchemaUtils.d.ts +11 -0
- package/esm/SchemaUtils.js +46 -0
- package/esm/SharedTypes.d.ts +13 -0
- package/esm/SharedTypes.js +1 -0
- package/esm/ValidationUtils.d.ts +1 -0
- package/esm/ValidationUtils.js +29 -0
- package/esm/index.d.ts +3 -0
- package/esm/index.js +3 -0
- package/package.json +71 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CLASSIFICATION_REPORT_SCHEMA = exports.CLASSIFICATION_LABEL_SCHEMA = exports.CATEGORIES_SCHEMA = exports.CLASSIFICATION_CATEGORY_REPORT_SCHEMA = exports.LIKELIHOOD_SCHEMA = exports.getCategoryInfo = exports.CLASSIFICATION_CATEGORY_INFO = exports.CLASSIFICATION_CATEGORY_INFO_SCHEMA = exports.CLASSIFICATION_CATEGORY_SCHEMA = exports.CLASSIFICATION_CATEGORIES = void 0;
|
|
4
|
+
var zod = require("zod/v4");
|
|
5
|
+
var SchemaUtils_1 = require("./SchemaUtils");
|
|
6
|
+
// OpenAI Content Moderation Categories (Merged subcategories)
|
|
7
|
+
exports.CLASSIFICATION_CATEGORIES = [
|
|
8
|
+
"sexual",
|
|
9
|
+
"violence",
|
|
10
|
+
"gore",
|
|
11
|
+
"self-harm",
|
|
12
|
+
"harassment",
|
|
13
|
+
"hate",
|
|
14
|
+
"illicit",
|
|
15
|
+
"child-exploitation",
|
|
16
|
+
];
|
|
17
|
+
exports.CLASSIFICATION_CATEGORY_SCHEMA = zod.enum(exports.CLASSIFICATION_CATEGORIES);
|
|
18
|
+
// Type to define category information including whether it's text-only
|
|
19
|
+
exports.CLASSIFICATION_CATEGORY_INFO_SCHEMA = zod.object({
|
|
20
|
+
category: exports.CLASSIFICATION_CATEGORY_SCHEMA,
|
|
21
|
+
displayName: (0, SchemaUtils_1.saneStringField)(),
|
|
22
|
+
description: (0, SchemaUtils_1.saneStringField)(),
|
|
23
|
+
textOnly: zod.boolean(),
|
|
24
|
+
supportsImages: zod.boolean(),
|
|
25
|
+
});
|
|
26
|
+
// Category information mapping
|
|
27
|
+
exports.CLASSIFICATION_CATEGORY_INFO = {
|
|
28
|
+
sexual: {
|
|
29
|
+
category: "sexual",
|
|
30
|
+
displayName: "Sexual Content",
|
|
31
|
+
description: "Content meant to arouse sexual excitement, such as the description of sexual activity, or that promotes sexual services.",
|
|
32
|
+
textOnly: false,
|
|
33
|
+
supportsImages: true,
|
|
34
|
+
},
|
|
35
|
+
violence: {
|
|
36
|
+
category: "violence",
|
|
37
|
+
displayName: "Violence",
|
|
38
|
+
description: "Content that depicts death, violence, or physical injury.",
|
|
39
|
+
textOnly: false,
|
|
40
|
+
supportsImages: true,
|
|
41
|
+
},
|
|
42
|
+
gore: {
|
|
43
|
+
category: "gore",
|
|
44
|
+
displayName: "Gore",
|
|
45
|
+
description: "Content that depicts death, violence, or physical injury in graphic, explicit detail.",
|
|
46
|
+
textOnly: false,
|
|
47
|
+
supportsImages: true,
|
|
48
|
+
},
|
|
49
|
+
"self-harm": {
|
|
50
|
+
category: "self-harm",
|
|
51
|
+
displayName: "Self-Harm",
|
|
52
|
+
description: "Content that promotes, encourages, or depicts acts of self-harm, including intent and instructions for self-harm activities.",
|
|
53
|
+
textOnly: false,
|
|
54
|
+
supportsImages: true,
|
|
55
|
+
},
|
|
56
|
+
harassment: {
|
|
57
|
+
category: "harassment",
|
|
58
|
+
displayName: "Harassment",
|
|
59
|
+
description: "Content that expresses, incites, or promotes harassing language towards any target, including threatening harassment.",
|
|
60
|
+
textOnly: true,
|
|
61
|
+
supportsImages: false,
|
|
62
|
+
},
|
|
63
|
+
hate: {
|
|
64
|
+
category: "hate",
|
|
65
|
+
displayName: "Hate Speech",
|
|
66
|
+
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.",
|
|
67
|
+
textOnly: true,
|
|
68
|
+
supportsImages: false,
|
|
69
|
+
},
|
|
70
|
+
illicit: {
|
|
71
|
+
category: "illicit",
|
|
72
|
+
displayName: "Illicit Content",
|
|
73
|
+
description: "Content that gives advice or instruction on how to commit illicit acts, including violent illegal activities.",
|
|
74
|
+
textOnly: true,
|
|
75
|
+
supportsImages: false,
|
|
76
|
+
},
|
|
77
|
+
"child-exploitation": {
|
|
78
|
+
category: "child-exploitation",
|
|
79
|
+
displayName: "Child Exploitation",
|
|
80
|
+
description: "Content that sexualizes, grooms, abuses, or otherwise exploits children under 18 years old.",
|
|
81
|
+
textOnly: true,
|
|
82
|
+
supportsImages: false,
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
// Helper function to get category info
|
|
86
|
+
var getCategoryInfo = function (category) {
|
|
87
|
+
return exports.CLASSIFICATION_CATEGORY_INFO[category];
|
|
88
|
+
};
|
|
89
|
+
exports.getCategoryInfo = getCategoryInfo;
|
|
90
|
+
exports.LIKELIHOOD_SCHEMA = zod.enum([
|
|
91
|
+
"VERY_UNLIKELY",
|
|
92
|
+
"UNLIKELY",
|
|
93
|
+
"POSSIBLE",
|
|
94
|
+
"LIKELY",
|
|
95
|
+
"VERY_LIKELY",
|
|
96
|
+
]);
|
|
97
|
+
exports.CLASSIFICATION_CATEGORY_REPORT_SCHEMA = zod.object({
|
|
98
|
+
category: exports.CLASSIFICATION_CATEGORY_SCHEMA,
|
|
99
|
+
likelihood: exports.LIKELIHOOD_SCHEMA,
|
|
100
|
+
score: zod.number(),
|
|
101
|
+
});
|
|
102
|
+
exports.CATEGORIES_SCHEMA = zod.partialRecord(exports.CLASSIFICATION_CATEGORY_SCHEMA, exports.CLASSIFICATION_CATEGORY_REPORT_SCHEMA);
|
|
103
|
+
exports.CLASSIFICATION_LABEL_SCHEMA = zod.object({
|
|
104
|
+
description: (0, SchemaUtils_1.saneStringField)(),
|
|
105
|
+
score: zod.number(),
|
|
106
|
+
topicalityScore: zod.number().nullish(),
|
|
107
|
+
likelihood: exports.LIKELIHOOD_SCHEMA,
|
|
108
|
+
knowledgeBaseId: (0, SchemaUtils_1.saneStringField)().nullish(),
|
|
109
|
+
});
|
|
110
|
+
exports.CLASSIFICATION_REPORT_SCHEMA = zod.object({
|
|
111
|
+
processedAt: zod.number(),
|
|
112
|
+
categories: exports.CATEGORIES_SCHEMA,
|
|
113
|
+
flagged: zod.boolean(),
|
|
114
|
+
score: zod.number(),
|
|
115
|
+
notes: (0, SchemaUtils_1.saneStringField)().nullish(),
|
|
116
|
+
labels: zod.array(exports.CLASSIFICATION_LABEL_SCHEMA).nullish(),
|
|
117
|
+
});
|
|
@@ -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,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.urlField = exports.saneStringField = exports.updatedAtField = exports.createdAtField = exports.uuidField = exports.primaryUuidField = void 0;
|
|
4
|
+
var zod = require("zod/v4");
|
|
5
|
+
var zodbase_1 = require("zodbase");
|
|
6
|
+
var ValidationUtils_1 = require("./ValidationUtils");
|
|
7
|
+
var primaryUuidField = function () {
|
|
8
|
+
return zod
|
|
9
|
+
.string()
|
|
10
|
+
.uuid({
|
|
11
|
+
version: "v4",
|
|
12
|
+
})
|
|
13
|
+
.meta((0, zodbase_1.meta)([(0, zodbase_1.primaryKey)()]));
|
|
14
|
+
};
|
|
15
|
+
exports.primaryUuidField = primaryUuidField;
|
|
16
|
+
var uuidField = function () {
|
|
17
|
+
return zod.string().uuid({
|
|
18
|
+
version: "v4",
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
exports.uuidField = uuidField;
|
|
22
|
+
var createdAtField = function () { return zod.number().int(); };
|
|
23
|
+
exports.createdAtField = createdAtField;
|
|
24
|
+
var updatedAtField = function () {
|
|
25
|
+
return zod
|
|
26
|
+
.number()
|
|
27
|
+
.int()
|
|
28
|
+
.optional()
|
|
29
|
+
.meta((0, zodbase_1.meta)([(0, zodbase_1.updatedAt)()]));
|
|
30
|
+
};
|
|
31
|
+
exports.updatedAtField = updatedAtField;
|
|
32
|
+
var SIZE_LIMITS = {
|
|
33
|
+
small: 64,
|
|
34
|
+
medium: 200,
|
|
35
|
+
large: 1500,
|
|
36
|
+
};
|
|
37
|
+
var saneStringField = function (options) {
|
|
38
|
+
return zod
|
|
39
|
+
.string()
|
|
40
|
+
.transform(function (value) { return value.trim(); })
|
|
41
|
+
.refine(function (value) {
|
|
42
|
+
if ((options === null || options === void 0 ? void 0 : options.minWidth) && value.length < options.minWidth) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
return true;
|
|
46
|
+
}, "Not long enough")
|
|
47
|
+
.refine(function (value) {
|
|
48
|
+
var _a;
|
|
49
|
+
var sizeLimit = SIZE_LIMITS[(_a = options === null || options === void 0 ? void 0 : options.type) !== null && _a !== void 0 ? _a : "medium"];
|
|
50
|
+
return typeof value === "string" && value.length < sizeLimit;
|
|
51
|
+
}, "Too long");
|
|
52
|
+
};
|
|
53
|
+
exports.saneStringField = saneStringField;
|
|
54
|
+
var urlField = function () {
|
|
55
|
+
return (0, exports.saneStringField)().refine(function (value) {
|
|
56
|
+
/*if (encodeURI(value) !== value) {
|
|
57
|
+
return false;
|
|
58
|
+
}*/
|
|
59
|
+
var parsedUrl = (0, ValidationUtils_1.validateUrl)(value);
|
|
60
|
+
return Boolean(parsedUrl);
|
|
61
|
+
}, "Invalid link");
|
|
62
|
+
};
|
|
63
|
+
exports.urlField = urlField;
|
|
@@ -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 declare const validateUrl: (url: string) => URL | undefined;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateUrl = void 0;
|
|
4
|
+
var VALID_PREFIXES = ["http://", "https://", "mailto:", "tel:", "sms:"];
|
|
5
|
+
var EMAIL_REGEX = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
|
|
6
|
+
var PHONE_REGEX = /^\+?[0-9]+$/;
|
|
7
|
+
var validateUrl = function (url) {
|
|
8
|
+
if (!url) {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
var parsedUrl = url;
|
|
12
|
+
if (!VALID_PREFIXES.some(function (prefix) { return parsedUrl.startsWith(prefix); })) {
|
|
13
|
+
if (EMAIL_REGEX.test(parsedUrl)) {
|
|
14
|
+
parsedUrl = "mailto:".concat(parsedUrl);
|
|
15
|
+
}
|
|
16
|
+
else if (PHONE_REGEX.test(parsedUrl)) {
|
|
17
|
+
parsedUrl = "tel:".concat(parsedUrl);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
parsedUrl = "https://".concat(parsedUrl);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
var url_1 = new URL(parsedUrl);
|
|
25
|
+
if (url_1.protocol.includes("http") && !url_1.host.includes(".")) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
return url_1;
|
|
29
|
+
}
|
|
30
|
+
catch (error) { }
|
|
31
|
+
return undefined;
|
|
32
|
+
};
|
|
33
|
+
exports.validateUrl = validateUrl;
|
package/cjs/index.d.ts
ADDED
package/cjs/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/// <reference types="typescript" />
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.verifyWebhookSignature = exports.CalmLensClient = void 0;
|
|
5
|
+
var CalmLensClient_1 = require("./CalmLensClient");
|
|
6
|
+
Object.defineProperty(exports, "CalmLensClient", { enumerable: true, get: function () { return CalmLensClient_1.default; } });
|
|
7
|
+
var CalmLensUtils_1 = require("./CalmLensUtils");
|
|
8
|
+
Object.defineProperty(exports, "verifyWebhookSignature", { enumerable: true, get: function () { return CalmLensUtils_1.verifyWebhookSignature; } });
|
package/esm/Asset.d.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import * as zod from "zod/v4";
|
|
2
|
+
export declare const ASSET_STATUS_SCHEMA: zod.ZodEnum<{
|
|
3
|
+
error: "error";
|
|
4
|
+
pending: "pending";
|
|
5
|
+
approved: "approved";
|
|
6
|
+
rejected: "rejected";
|
|
7
|
+
}>;
|
|
8
|
+
export type AssetStatus = zod.infer<typeof ASSET_STATUS_SCHEMA>;
|
|
9
|
+
export declare const ASSET_TYPE_SCHEMA: zod.ZodEnum<{
|
|
10
|
+
image: "image";
|
|
11
|
+
video: "video";
|
|
12
|
+
audio: "audio";
|
|
13
|
+
document: "document";
|
|
14
|
+
website: "website";
|
|
15
|
+
}>;
|
|
16
|
+
export type AssetType = zod.infer<typeof ASSET_TYPE_SCHEMA>;
|
|
17
|
+
export declare const ASSET_VISIBILITY_SCHEMA: zod.ZodEnum<{
|
|
18
|
+
public: "public";
|
|
19
|
+
private: "private";
|
|
20
|
+
}>;
|
|
21
|
+
export type AssetVisibility = zod.infer<typeof ASSET_VISIBILITY_SCHEMA>;
|
|
22
|
+
export declare const ASSET_SCHEMA: zod.ZodObject<{
|
|
23
|
+
id: zod.ZodString;
|
|
24
|
+
projectId: zod.ZodString;
|
|
25
|
+
sizeInBytes: zod.ZodOptional<zod.ZodNullable<zod.ZodNumber>>;
|
|
26
|
+
userId: zod.ZodOptional<zod.ZodNullable<zod.ZodPipe<zod.ZodString, zod.ZodTransform<string, string>>>>;
|
|
27
|
+
parentId: zod.ZodOptional<zod.ZodNullable<zod.ZodString>>;
|
|
28
|
+
createdAt: zod.ZodNumber;
|
|
29
|
+
updatedAt: zod.ZodOptional<zod.ZodNumber>;
|
|
30
|
+
name: zod.ZodPipe<zod.ZodString, zod.ZodTransform<string, string>>;
|
|
31
|
+
fileFormat: zod.ZodOptional<zod.ZodNullable<zod.ZodPipe<zod.ZodString, zod.ZodTransform<string, string>>>>;
|
|
32
|
+
fileExtension: zod.ZodOptional<zod.ZodNullable<zod.ZodPipe<zod.ZodString, zod.ZodTransform<string, string>>>>;
|
|
33
|
+
description: zod.ZodOptional<zod.ZodNullable<zod.ZodPipe<zod.ZodString, zod.ZodTransform<string, string>>>>;
|
|
34
|
+
externalId: zod.ZodOptional<zod.ZodNullable<zod.ZodPipe<zod.ZodString, zod.ZodTransform<string, string>>>>;
|
|
35
|
+
externalUrl: zod.ZodOptional<zod.ZodNullable<zod.ZodString>>;
|
|
36
|
+
previewImageId: zod.ZodOptional<zod.ZodNullable<zod.ZodPipe<zod.ZodString, zod.ZodTransform<string, string>>>>;
|
|
37
|
+
storageId: zod.ZodOptional<zod.ZodNullable<zod.ZodPipe<zod.ZodString, zod.ZodTransform<string, string>>>>;
|
|
38
|
+
averageColor: zod.ZodOptional<zod.ZodNullable<zod.ZodPipe<zod.ZodString, zod.ZodTransform<string, string>>>>;
|
|
39
|
+
type: zod.ZodEnum<{
|
|
40
|
+
image: "image";
|
|
41
|
+
video: "video";
|
|
42
|
+
audio: "audio";
|
|
43
|
+
document: "document";
|
|
44
|
+
website: "website";
|
|
45
|
+
}>;
|
|
46
|
+
previewHash: zod.ZodOptional<zod.ZodNullable<zod.ZodPipe<zod.ZodString, zod.ZodTransform<string, string>>>>;
|
|
47
|
+
metadata: zod.ZodOptional<zod.ZodNullable<zod.ZodAny>>;
|
|
48
|
+
tags: zod.ZodOptional<zod.ZodNullable<zod.ZodArray<zod.ZodPipe<zod.ZodString, zod.ZodTransform<string, string>>>>>;
|
|
49
|
+
report: zod.ZodOptional<zod.ZodNullable<zod.ZodObject<{
|
|
50
|
+
processedAt: zod.ZodNumber;
|
|
51
|
+
categories: zod.ZodRecord<zod.ZodEnum<{
|
|
52
|
+
sexual: "sexual";
|
|
53
|
+
violence: "violence";
|
|
54
|
+
gore: "gore";
|
|
55
|
+
"self-harm": "self-harm";
|
|
56
|
+
harassment: "harassment";
|
|
57
|
+
hate: "hate";
|
|
58
|
+
illicit: "illicit";
|
|
59
|
+
"child-exploitation": "child-exploitation";
|
|
60
|
+
}> & zod.z.core.$partial, zod.ZodObject<{
|
|
61
|
+
category: zod.ZodEnum<{
|
|
62
|
+
sexual: "sexual";
|
|
63
|
+
violence: "violence";
|
|
64
|
+
gore: "gore";
|
|
65
|
+
"self-harm": "self-harm";
|
|
66
|
+
harassment: "harassment";
|
|
67
|
+
hate: "hate";
|
|
68
|
+
illicit: "illicit";
|
|
69
|
+
"child-exploitation": "child-exploitation";
|
|
70
|
+
}>;
|
|
71
|
+
likelihood: zod.ZodEnum<{
|
|
72
|
+
VERY_UNLIKELY: "VERY_UNLIKELY";
|
|
73
|
+
UNLIKELY: "UNLIKELY";
|
|
74
|
+
POSSIBLE: "POSSIBLE";
|
|
75
|
+
LIKELY: "LIKELY";
|
|
76
|
+
VERY_LIKELY: "VERY_LIKELY";
|
|
77
|
+
}>;
|
|
78
|
+
score: zod.ZodNumber;
|
|
79
|
+
}, zod.z.core.$strip>>;
|
|
80
|
+
flagged: zod.ZodBoolean;
|
|
81
|
+
score: zod.ZodNumber;
|
|
82
|
+
notes: zod.ZodOptional<zod.ZodNullable<zod.ZodPipe<zod.ZodString, zod.ZodTransform<string, string>>>>;
|
|
83
|
+
labels: zod.ZodOptional<zod.ZodNullable<zod.ZodArray<zod.ZodObject<{
|
|
84
|
+
description: zod.ZodPipe<zod.ZodString, zod.ZodTransform<string, string>>;
|
|
85
|
+
score: zod.ZodNumber;
|
|
86
|
+
topicalityScore: zod.ZodOptional<zod.ZodNullable<zod.ZodNumber>>;
|
|
87
|
+
likelihood: zod.ZodEnum<{
|
|
88
|
+
VERY_UNLIKELY: "VERY_UNLIKELY";
|
|
89
|
+
UNLIKELY: "UNLIKELY";
|
|
90
|
+
POSSIBLE: "POSSIBLE";
|
|
91
|
+
LIKELY: "LIKELY";
|
|
92
|
+
VERY_LIKELY: "VERY_LIKELY";
|
|
93
|
+
}>;
|
|
94
|
+
knowledgeBaseId: zod.ZodOptional<zod.ZodNullable<zod.ZodPipe<zod.ZodString, zod.ZodTransform<string, string>>>>;
|
|
95
|
+
}, zod.z.core.$strip>>>>;
|
|
96
|
+
}, zod.z.core.$strip>>>;
|
|
97
|
+
status: zod.ZodEnum<{
|
|
98
|
+
error: "error";
|
|
99
|
+
pending: "pending";
|
|
100
|
+
approved: "approved";
|
|
101
|
+
rejected: "rejected";
|
|
102
|
+
}>;
|
|
103
|
+
keepAfterProcessing: zod.ZodOptional<zod.ZodNullable<zod.ZodBoolean>>;
|
|
104
|
+
visibility: zod.ZodOptional<zod.ZodNullable<zod.ZodEnum<{
|
|
105
|
+
public: "public";
|
|
106
|
+
private: "private";
|
|
107
|
+
}>>>;
|
|
108
|
+
}, zod.z.core.$strip>;
|
|
109
|
+
export type Asset = zod.infer<typeof ASSET_SCHEMA>;
|
package/esm/Asset.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as zod from "zod/v4";
|
|
2
|
+
import { CLASSIFICATION_REPORT_SCHEMA } from "./Classification";
|
|
3
|
+
import { createdAtField, primaryUuidField, saneStringField, updatedAtField, uuidField, } from "./SchemaUtils";
|
|
4
|
+
export const ASSET_STATUS_SCHEMA = zod.enum(["pending", "approved", "rejected", "error"]);
|
|
5
|
+
export const ASSET_TYPE_SCHEMA = zod.enum(["image", "video", "audio", "document", "website"]);
|
|
6
|
+
export const ASSET_VISIBILITY_SCHEMA = zod.enum(["public", "private"]);
|
|
7
|
+
export const ASSET_SCHEMA = zod.object({
|
|
8
|
+
id: primaryUuidField(),
|
|
9
|
+
projectId: uuidField(),
|
|
10
|
+
sizeInBytes: zod.number().nullish(),
|
|
11
|
+
userId: saneStringField().nullish(),
|
|
12
|
+
parentId: uuidField().nullish(),
|
|
13
|
+
createdAt: createdAtField(),
|
|
14
|
+
updatedAt: updatedAtField(),
|
|
15
|
+
name: saneStringField({
|
|
16
|
+
type: "large",
|
|
17
|
+
}),
|
|
18
|
+
fileFormat: saneStringField().nullish(),
|
|
19
|
+
fileExtension: saneStringField().nullish(),
|
|
20
|
+
description: saneStringField({
|
|
21
|
+
type: "large",
|
|
22
|
+
}).nullish(),
|
|
23
|
+
externalId: saneStringField().nullish(),
|
|
24
|
+
externalUrl: zod.string().url().nullish(),
|
|
25
|
+
previewImageId: saneStringField().nullish(),
|
|
26
|
+
storageId: saneStringField().nullish(),
|
|
27
|
+
averageColor: saneStringField().nullish(),
|
|
28
|
+
type: ASSET_TYPE_SCHEMA,
|
|
29
|
+
previewHash: saneStringField().nullish(),
|
|
30
|
+
metadata: zod.any().nullish(),
|
|
31
|
+
tags: zod.array(saneStringField()).nullish(),
|
|
32
|
+
report: CLASSIFICATION_REPORT_SCHEMA.nullish(),
|
|
33
|
+
status: ASSET_STATUS_SCHEMA,
|
|
34
|
+
keepAfterProcessing: zod.boolean().nullish(),
|
|
35
|
+
visibility: ASSET_VISIBILITY_SCHEMA.nullish(),
|
|
36
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Asset } from "./Asset";
|
|
2
|
+
import type { SubmitAssetOptions } from "./SharedTypes";
|
|
3
|
+
import type { CalmLensClientOptions } from "./CalmLensTypes";
|
|
4
|
+
export default class CalmLensClient {
|
|
5
|
+
private options;
|
|
6
|
+
private readonly api;
|
|
7
|
+
private readonly endpoints;
|
|
8
|
+
/**
|
|
9
|
+
* Validates a webhook signature to ensure the webhook payload is authentic.
|
|
10
|
+
*
|
|
11
|
+
* @param payload - The webhook payload (string or object)
|
|
12
|
+
* @param signatureHex - The signature from the 'x-calmlens-signature' header
|
|
13
|
+
* @param secret - The webhook secret used to sign the payload
|
|
14
|
+
* @returns Promise<boolean> - True if the signature is valid, false otherwise
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```javascript
|
|
18
|
+
* // In your webhook handler
|
|
19
|
+
* const signature = req.headers['x-calmlens-signature'];
|
|
20
|
+
* const payload = req.body;
|
|
21
|
+
* const isValid = await CalmLensClient.verifyWebhookSignature(payload, signature, WEBHOOK_SECRET);
|
|
22
|
+
*
|
|
23
|
+
* if (!isValid) {
|
|
24
|
+
* return res.status(401).send('Unauthorized');
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
static verifyWebhookSignature(payload: string | object, signatureHex: string, secret: string): Promise<boolean>;
|
|
29
|
+
constructor(options: CalmLensClientOptions);
|
|
30
|
+
submitAsset(options: SubmitAssetOptions): Promise<Asset>;
|
|
31
|
+
getAsset(assetId: string): Promise<Asset>;
|
|
32
|
+
listAssets(options?: {
|
|
33
|
+
pageIndex?: number;
|
|
34
|
+
pageSize?: number;
|
|
35
|
+
}): Promise<{
|
|
36
|
+
items: Asset[];
|
|
37
|
+
total: number;
|
|
38
|
+
pageIndex: number;
|
|
39
|
+
pageSize: number;
|
|
40
|
+
}>;
|
|
41
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { Api } from "api-def";
|
|
11
|
+
import { verifyWebhookSignature } from "./CalmLensUtils";
|
|
12
|
+
const createApi = (options) => {
|
|
13
|
+
const api = new Api({
|
|
14
|
+
name: "Calm Lens",
|
|
15
|
+
baseUrl: options.baseUrl,
|
|
16
|
+
middleware: [
|
|
17
|
+
{
|
|
18
|
+
beforeSend: (context) => {
|
|
19
|
+
context.updateHeaders({
|
|
20
|
+
"X-Api-Key": options.apiKey,
|
|
21
|
+
});
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
});
|
|
26
|
+
return api;
|
|
27
|
+
};
|
|
28
|
+
// API endpoint definitions
|
|
29
|
+
const createEndpoints = (api) => {
|
|
30
|
+
const postUploadAsset = api
|
|
31
|
+
.endpoint()
|
|
32
|
+
.bodyOf()
|
|
33
|
+
.paramsOf()
|
|
34
|
+
.responseOf()
|
|
35
|
+
.build({
|
|
36
|
+
id: "postUploadAsset",
|
|
37
|
+
method: "post",
|
|
38
|
+
path: "/projects/:projectId/assets",
|
|
39
|
+
});
|
|
40
|
+
const getAsset = api.endpoint().paramsOf().responseOf().build({
|
|
41
|
+
id: "getAsset",
|
|
42
|
+
method: "get",
|
|
43
|
+
path: "/projects/:projectId/assets/:assetId",
|
|
44
|
+
});
|
|
45
|
+
const getAssetsPage = api
|
|
46
|
+
.endpoint()
|
|
47
|
+
.queryOf()
|
|
48
|
+
.paramsOf()
|
|
49
|
+
.responseOf()
|
|
50
|
+
.build({
|
|
51
|
+
id: "getAssetsPage",
|
|
52
|
+
method: "get",
|
|
53
|
+
path: "/projects/:projectId/assets/page",
|
|
54
|
+
});
|
|
55
|
+
return {
|
|
56
|
+
postUploadAsset,
|
|
57
|
+
getAsset,
|
|
58
|
+
getAssetsPage,
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
export default class CalmLensClient {
|
|
62
|
+
/**
|
|
63
|
+
* Validates a webhook signature to ensure the webhook payload is authentic.
|
|
64
|
+
*
|
|
65
|
+
* @param payload - The webhook payload (string or object)
|
|
66
|
+
* @param signatureHex - The signature from the 'x-calmlens-signature' header
|
|
67
|
+
* @param secret - The webhook secret used to sign the payload
|
|
68
|
+
* @returns Promise<boolean> - True if the signature is valid, false otherwise
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```javascript
|
|
72
|
+
* // In your webhook handler
|
|
73
|
+
* const signature = req.headers['x-calmlens-signature'];
|
|
74
|
+
* const payload = req.body;
|
|
75
|
+
* const isValid = await CalmLensClient.verifyWebhookSignature(payload, signature, WEBHOOK_SECRET);
|
|
76
|
+
*
|
|
77
|
+
* if (!isValid) {
|
|
78
|
+
* return res.status(401).send('Unauthorized');
|
|
79
|
+
* }
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
static verifyWebhookSignature(payload, signatureHex, secret) {
|
|
83
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
return verifyWebhookSignature(payload, signatureHex, secret);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
constructor(options) {
|
|
88
|
+
var _a;
|
|
89
|
+
this.options = options;
|
|
90
|
+
if (!options.apiKey) {
|
|
91
|
+
throw new Error("API key is required");
|
|
92
|
+
}
|
|
93
|
+
if (!options.projectId) {
|
|
94
|
+
throw new Error("Project ID is required");
|
|
95
|
+
}
|
|
96
|
+
this.options.baseUrl = (_a = this.options.baseUrl) !== null && _a !== void 0 ? _a : "https://api.calmlens.com";
|
|
97
|
+
this.api = createApi(this.options);
|
|
98
|
+
this.endpoints = createEndpoints(this.api);
|
|
99
|
+
}
|
|
100
|
+
submitAsset(options) {
|
|
101
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
if (!("file" in options) && !("url" in options)) {
|
|
103
|
+
throw new Error("Either file content or URL is required");
|
|
104
|
+
}
|
|
105
|
+
if (!options.name) {
|
|
106
|
+
throw new Error("Asset name is required");
|
|
107
|
+
}
|
|
108
|
+
const result = yield this.endpoints.postUploadAsset.submit({
|
|
109
|
+
body: options,
|
|
110
|
+
params: {
|
|
111
|
+
projectId: this.options.projectId,
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
return result.data;
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
getAsset(assetId) {
|
|
118
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
119
|
+
if (!assetId) {
|
|
120
|
+
throw new Error("Asset ID is required");
|
|
121
|
+
}
|
|
122
|
+
const result = yield this.endpoints.getAsset.submit({
|
|
123
|
+
params: {
|
|
124
|
+
projectId: this.options.projectId,
|
|
125
|
+
assetId,
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
return result.data;
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
listAssets() {
|
|
132
|
+
return __awaiter(this, arguments, void 0, function* (options = {}) {
|
|
133
|
+
const result = yield this.endpoints.getAssetsPage.submit({
|
|
134
|
+
params: {
|
|
135
|
+
projectId: this.options.projectId,
|
|
136
|
+
},
|
|
137
|
+
query: options,
|
|
138
|
+
});
|
|
139
|
+
return result.data;
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function verifyWebhookSignature(payload: string | object, signatureHex: string, secret: string): Promise<boolean>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
export function verifyWebhookSignature(payload, signatureHex, secret) {
|
|
11
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
12
|
+
const encoder = new TextEncoder();
|
|
13
|
+
const normalizePayload = typeof payload === "string" ? payload : JSON.stringify(payload);
|
|
14
|
+
const key = yield crypto.subtle.importKey("raw", encoder.encode(secret), { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
|
|
15
|
+
const sig = yield crypto.subtle.sign("HMAC", key, encoder.encode(normalizePayload));
|
|
16
|
+
const hex = Array.from(new Uint8Array(sig))
|
|
17
|
+
.map((b) => b.toString(16).padStart(2, "0"))
|
|
18
|
+
.join("");
|
|
19
|
+
// Timing-safe equality not available in Node <20 cross-platform via subtle; compare length and constant-time loop
|
|
20
|
+
if (hex.length !== signatureHex.length)
|
|
21
|
+
return false;
|
|
22
|
+
let diff = 0;
|
|
23
|
+
for (let i = 0; i < hex.length; i++) {
|
|
24
|
+
diff |= hex.charCodeAt(i) ^ signatureHex.charCodeAt(i);
|
|
25
|
+
}
|
|
26
|
+
return diff === 0;
|
|
27
|
+
});
|
|
28
|
+
}
|