@calmlens/sdk 0.7.0 → 0.8.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.
- package/cjs/{CalmLensTypes-BpmT60j-.d.ts → CalmLensTypes-B7hr0SBv.d.ts} +105 -0
- package/cjs/index.d.ts +1 -1
- package/cjs/index.js +43 -28
- package/cjs/testing.d.ts +1 -1
- package/esm/{CalmLensTypes-BpmT60j-.d.ts → CalmLensTypes-B7hr0SBv.d.ts} +105 -0
- package/esm/index.d.ts +1 -1
- package/esm/index.js +43 -28
- package/esm/testing.d.ts +1 -1
- package/package.json +4 -8
|
@@ -2979,6 +2979,109 @@ declare const EVENT_TYPE_INFO: {
|
|
|
2979
2979
|
lastError: zod.ZodOptional<zod.ZodNullable<zod.ZodString>>;
|
|
2980
2980
|
}, zod.core.$strip>;
|
|
2981
2981
|
};
|
|
2982
|
+
readonly "appeal.submitted": {
|
|
2983
|
+
id: "appeal.submitted";
|
|
2984
|
+
name: string;
|
|
2985
|
+
description: string;
|
|
2986
|
+
category: EventCategory;
|
|
2987
|
+
severity: EventSeverity;
|
|
2988
|
+
/** Whether the in-app connector (notification bell) subscribes to the type by default. */
|
|
2989
|
+
notify: boolean;
|
|
2990
|
+
fields: {
|
|
2991
|
+
appealId: EventFieldDefinition<zod.ZodString>;
|
|
2992
|
+
subjectType: EventFieldDefinition<zod.ZodEnum<{
|
|
2993
|
+
post: "post";
|
|
2994
|
+
"reported-post": "reported-post";
|
|
2995
|
+
"reported-user": "reported-user";
|
|
2996
|
+
user: "user";
|
|
2997
|
+
}>>;
|
|
2998
|
+
subjectId: EventFieldDefinition<zod.ZodString>;
|
|
2999
|
+
};
|
|
3000
|
+
/** Example data, used for synthetic test sends (`createSampleEvent`). */
|
|
3001
|
+
example: NoInfer<{
|
|
3002
|
+
appealId: string;
|
|
3003
|
+
subjectType: "post" | "reported-post" | "reported-user" | "user";
|
|
3004
|
+
subjectId: string;
|
|
3005
|
+
}>;
|
|
3006
|
+
factInfo: {
|
|
3007
|
+
label: string;
|
|
3008
|
+
description: string;
|
|
3009
|
+
display: EventFieldDisplay;
|
|
3010
|
+
/** Kept in the data but left out of rendered messages (usually an ID shown by another field). */
|
|
3011
|
+
hidden?: boolean;
|
|
3012
|
+
schema: zod.ZodType<unknown, unknown, zod.core.$ZodTypeInternals<unknown, unknown>>;
|
|
3013
|
+
key: string;
|
|
3014
|
+
}[];
|
|
3015
|
+
values: zod.ZodObject<{
|
|
3016
|
+
appealId: zod.ZodString;
|
|
3017
|
+
subjectType: zod.ZodEnum<{
|
|
3018
|
+
post: "post";
|
|
3019
|
+
"reported-post": "reported-post";
|
|
3020
|
+
"reported-user": "reported-user";
|
|
3021
|
+
user: "user";
|
|
3022
|
+
}>;
|
|
3023
|
+
subjectId: zod.ZodString;
|
|
3024
|
+
}, zod.core.$strip>;
|
|
3025
|
+
};
|
|
3026
|
+
readonly "appeal.resolved": {
|
|
3027
|
+
id: "appeal.resolved";
|
|
3028
|
+
name: string;
|
|
3029
|
+
description: string;
|
|
3030
|
+
category: EventCategory;
|
|
3031
|
+
severity: EventSeverity;
|
|
3032
|
+
/** Whether the in-app connector (notification bell) subscribes to the type by default. */
|
|
3033
|
+
notify: boolean;
|
|
3034
|
+
fields: {
|
|
3035
|
+
appealId: EventFieldDefinition<zod.ZodString>;
|
|
3036
|
+
subjectType: EventFieldDefinition<zod.ZodEnum<{
|
|
3037
|
+
post: "post";
|
|
3038
|
+
"reported-post": "reported-post";
|
|
3039
|
+
"reported-user": "reported-user";
|
|
3040
|
+
user: "user";
|
|
3041
|
+
}>>;
|
|
3042
|
+
subjectId: EventFieldDefinition<zod.ZodString>;
|
|
3043
|
+
decision: EventFieldDefinition<zod.ZodEnum<{
|
|
3044
|
+
overturned: "overturned";
|
|
3045
|
+
upheld: "upheld";
|
|
3046
|
+
}>>;
|
|
3047
|
+
action: EventFieldDefinition<zod.ZodString>;
|
|
3048
|
+
appliedToAsset: EventFieldDefinition<zod.ZodBoolean>;
|
|
3049
|
+
};
|
|
3050
|
+
/** Example data, used for synthetic test sends (`createSampleEvent`). */
|
|
3051
|
+
example: NoInfer<{
|
|
3052
|
+
appealId: string;
|
|
3053
|
+
subjectType: "post" | "reported-post" | "reported-user" | "user";
|
|
3054
|
+
subjectId: string;
|
|
3055
|
+
decision: "overturned" | "upheld";
|
|
3056
|
+
action: string;
|
|
3057
|
+
appliedToAsset: boolean;
|
|
3058
|
+
}>;
|
|
3059
|
+
factInfo: {
|
|
3060
|
+
label: string;
|
|
3061
|
+
description: string;
|
|
3062
|
+
display: EventFieldDisplay;
|
|
3063
|
+
/** Kept in the data but left out of rendered messages (usually an ID shown by another field). */
|
|
3064
|
+
hidden?: boolean;
|
|
3065
|
+
schema: zod.ZodType<unknown, unknown, zod.core.$ZodTypeInternals<unknown, unknown>>;
|
|
3066
|
+
key: string;
|
|
3067
|
+
}[];
|
|
3068
|
+
values: zod.ZodObject<{
|
|
3069
|
+
appealId: zod.ZodString;
|
|
3070
|
+
subjectType: zod.ZodEnum<{
|
|
3071
|
+
post: "post";
|
|
3072
|
+
"reported-post": "reported-post";
|
|
3073
|
+
"reported-user": "reported-user";
|
|
3074
|
+
user: "user";
|
|
3075
|
+
}>;
|
|
3076
|
+
subjectId: zod.ZodString;
|
|
3077
|
+
decision: zod.ZodEnum<{
|
|
3078
|
+
overturned: "overturned";
|
|
3079
|
+
upheld: "upheld";
|
|
3080
|
+
}>;
|
|
3081
|
+
action: zod.ZodString;
|
|
3082
|
+
appliedToAsset: zod.ZodBoolean;
|
|
3083
|
+
}, zod.core.$strip>;
|
|
3084
|
+
};
|
|
2982
3085
|
};
|
|
2983
3086
|
type EventType = keyof typeof EVENT_TYPE_INFO;
|
|
2984
3087
|
type EventTypeInfo<TType extends EventType = EventType> = (typeof EVENT_TYPE_INFO)[TType];
|
|
@@ -3022,6 +3125,8 @@ declare const EVENT_SCHEMA: zod.ZodObject<{
|
|
|
3022
3125
|
projectId: zod.ZodString;
|
|
3023
3126
|
userId: zod.ZodOptional<zod.ZodNullable<zod.ZodPipe<zod.ZodString, zod.ZodTransform<string, string>>>>;
|
|
3024
3127
|
type: zod.ZodEnum<{
|
|
3128
|
+
"appeal.resolved": "appeal.resolved";
|
|
3129
|
+
"appeal.submitted": "appeal.submitted";
|
|
3025
3130
|
"asset.approved": "asset.approved";
|
|
3026
3131
|
"asset.classified": "asset.classified";
|
|
3027
3132
|
"asset.failed": "asset.failed";
|
package/cjs/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as GetEventsResponse, B as EventFactValues, C as UpdateAssetOptions, D as GetAssetChildrenResponse, E as VerifyWebhookSignatureOptions, F as Folder, G as AssetStatus, H as EventSeverity, I as Event, J as MetadataItem, K as AssetType, L as TypedEvent, M as RequestErrorCode, O as GetAssetResponse, P as Lens, R as EventCategory, S as SubmitAssetOptions, T as UploadAssetPartOptions, U as EventType, V as EventFacts, W as Asset, Y as ProcessingOptions, _ as MultipartUploadOptions, a as CreateAssetSignedUrlOptions, b as RetrieveAssetOptions, c as EnsureLensOptions, d as ListAssetChildrenOptions, f as ListAssetsOptions, g as MoveFolderOptions, h as MoveAssetOptions, i as CdnServeOptions, j as PostAssetSignedUrlResponse, k as GetAssetsPageResponse, l as EnsureLensesOptions, m as ModerateTextOptions, n as CalmLensClientOptions, o as CreateFolderOptions, p as ListEventsOptions, q as AssetVisibility, r as CdnAssetUrlOptions, s as CreateMultipartUploadPartOptions, t as AssetContentOptions, u as FolderIdOptions, v as MultipartUploadPartOptions, w as UpdateFolderOptions, x as RetryAssetOptions, y as RequestOptions, z as EventFact } from "./CalmLensTypes-
|
|
1
|
+
import { A as GetEventsResponse, B as EventFactValues, C as UpdateAssetOptions, D as GetAssetChildrenResponse, E as VerifyWebhookSignatureOptions, F as Folder, G as AssetStatus, H as EventSeverity, I as Event, J as MetadataItem, K as AssetType, L as TypedEvent, M as RequestErrorCode, O as GetAssetResponse, P as Lens, R as EventCategory, S as SubmitAssetOptions, T as UploadAssetPartOptions, U as EventType, V as EventFacts, W as Asset, Y as ProcessingOptions, _ as MultipartUploadOptions, a as CreateAssetSignedUrlOptions, b as RetrieveAssetOptions, c as EnsureLensOptions, d as ListAssetChildrenOptions, f as ListAssetsOptions, g as MoveFolderOptions, h as MoveAssetOptions, i as CdnServeOptions, j as PostAssetSignedUrlResponse, k as GetAssetsPageResponse, l as EnsureLensesOptions, m as ModerateTextOptions, n as CalmLensClientOptions, o as CreateFolderOptions, p as ListEventsOptions, q as AssetVisibility, r as CdnAssetUrlOptions, s as CreateMultipartUploadPartOptions, t as AssetContentOptions, u as FolderIdOptions, v as MultipartUploadPartOptions, w as UpdateFolderOptions, x as RetryAssetOptions, y as RequestOptions, z as EventFact } from "./CalmLensTypes-B7hr0SBv.js";
|
|
2
2
|
import * as zod from "zod";
|
|
3
3
|
//#region ../shared/src/AssetSearch.d.ts
|
|
4
4
|
declare const ASSET_SEARCH_QUERY_SCHEMA: zod.ZodObject<{
|
package/cjs/index.js
CHANGED
|
@@ -244,6 +244,42 @@ function generateMediaTestCode(signal, projectId) {
|
|
|
244
244
|
return `Calm Lens test ${[...suffix].map((character) => HEX_WORDS[Number.parseInt(character, 16)]).join(" ")} ${signal.replace(/[.-]/g, " ")} end test`;
|
|
245
245
|
}
|
|
246
246
|
//#endregion
|
|
247
|
+
//#region ../shared/src/CryptoUtils.ts
|
|
248
|
+
const encoder = new TextEncoder();
|
|
249
|
+
/** Lowercase hex of `bytes`, two characters per byte. */
|
|
250
|
+
const bytesToHex = (bytes) => Array.from(bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
251
|
+
(function() {
|
|
252
|
+
var _ref = require_CalmLensUtils._asyncToGenerator(function* (value) {
|
|
253
|
+
return bytesToHex(yield crypto.subtle.digest("SHA-256", encoder.encode(value)));
|
|
254
|
+
});
|
|
255
|
+
return function sha256Hex(_x) {
|
|
256
|
+
return _ref.apply(this, arguments);
|
|
257
|
+
};
|
|
258
|
+
})();
|
|
259
|
+
/** HMAC-SHA256 of `message` keyed with `secret` (both UTF-8 encoded), as lowercase hex. */
|
|
260
|
+
const hmacSha256Hex = function() {
|
|
261
|
+
var _ref2 = require_CalmLensUtils._asyncToGenerator(function* (secret, message) {
|
|
262
|
+
const key = yield crypto.subtle.importKey("raw", encoder.encode(secret), {
|
|
263
|
+
name: "HMAC",
|
|
264
|
+
hash: "SHA-256"
|
|
265
|
+
}, false, ["sign"]);
|
|
266
|
+
return bytesToHex(yield crypto.subtle.sign("HMAC", key, encoder.encode(message)));
|
|
267
|
+
});
|
|
268
|
+
return function hmacSha256Hex(_x2, _x3) {
|
|
269
|
+
return _ref2.apply(this, arguments);
|
|
270
|
+
};
|
|
271
|
+
}();
|
|
272
|
+
/**
|
|
273
|
+
* Compares two strings without leaking, through timing, where they first differ. Strings of
|
|
274
|
+
* different lengths are unequal immediately (the length itself is not secret here).
|
|
275
|
+
*/
|
|
276
|
+
const timingSafeEqual = (a, b) => {
|
|
277
|
+
if (a.length !== b.length) return false;
|
|
278
|
+
let difference = 0;
|
|
279
|
+
for (let index = 0; index < a.length; index++) difference |= a.charCodeAt(index) ^ b.charCodeAt(index);
|
|
280
|
+
return difference === 0;
|
|
281
|
+
};
|
|
282
|
+
//#endregion
|
|
247
283
|
//#region src/client/CalmLensWebhooks.ts
|
|
248
284
|
const WEBHOOK_DELIVERY_HEADER = "x-calmlens-delivery";
|
|
249
285
|
const WEBHOOK_TIMESTAMP_HEADER = "x-calmlens-timestamp";
|
|
@@ -268,39 +304,18 @@ const toWebhookEventPayload = (event) => {
|
|
|
268
304
|
}
|
|
269
305
|
};
|
|
270
306
|
};
|
|
271
|
-
const encoder = new TextEncoder();
|
|
272
|
-
const hmacSha256Hex = function() {
|
|
273
|
-
var _ref = require_CalmLensUtils._asyncToGenerator(function* (secret, message) {
|
|
274
|
-
const key = yield crypto.subtle.importKey("raw", encoder.encode(secret), {
|
|
275
|
-
name: "HMAC",
|
|
276
|
-
hash: "SHA-256"
|
|
277
|
-
}, false, ["sign"]);
|
|
278
|
-
const signature = yield crypto.subtle.sign("HMAC", key, encoder.encode(message));
|
|
279
|
-
return Array.from(new Uint8Array(signature), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
280
|
-
});
|
|
281
|
-
return function hmacSha256Hex(_x, _x2) {
|
|
282
|
-
return _ref.apply(this, arguments);
|
|
283
|
-
};
|
|
284
|
-
}();
|
|
285
|
-
/** Constant-time comparison of two strings of the same length. */
|
|
286
|
-
const timingSafeEqual = (a, b) => {
|
|
287
|
-
if (a.length !== b.length) return false;
|
|
288
|
-
let diff = 0;
|
|
289
|
-
for (let i = 0; i < a.length; i++) diff |= a.charCodeAt(i) ^ b.charCodeAt(i);
|
|
290
|
-
return diff === 0;
|
|
291
|
-
};
|
|
292
307
|
/** `v1=<hex HMAC-SHA256 of "<timestamp>.<body>">`, the `x-calmlens-signature` header value. */
|
|
293
308
|
const createWebhookSignatureHeader = function() {
|
|
294
|
-
var
|
|
309
|
+
var _ref = require_CalmLensUtils._asyncToGenerator(function* (secret, timestamp, body) {
|
|
295
310
|
return `v1=${yield hmacSha256Hex(secret, `${timestamp}.${body}`)}`;
|
|
296
311
|
});
|
|
297
|
-
return function createWebhookSignatureHeader(
|
|
298
|
-
return
|
|
312
|
+
return function createWebhookSignatureHeader(_x, _x2, _x3) {
|
|
313
|
+
return _ref.apply(this, arguments);
|
|
299
314
|
};
|
|
300
315
|
}();
|
|
301
316
|
/** Headers for one signed delivery of `body`. */
|
|
302
317
|
const createWebhookHeaders = function() {
|
|
303
|
-
var
|
|
318
|
+
var _ref2 = require_CalmLensUtils._asyncToGenerator(function* (options) {
|
|
304
319
|
var _options$timestampSec;
|
|
305
320
|
const timestamp = (_options$timestampSec = options.timestampSeconds) !== null && _options$timestampSec !== void 0 ? _options$timestampSec : Math.floor(Date.now() / 1e3);
|
|
306
321
|
return {
|
|
@@ -310,8 +325,8 @@ const createWebhookHeaders = function() {
|
|
|
310
325
|
[WEBHOOK_SIGNATURE_HEADER]: yield createWebhookSignatureHeader(options.secret, timestamp, options.body)
|
|
311
326
|
};
|
|
312
327
|
});
|
|
313
|
-
return function createWebhookHeaders(
|
|
314
|
-
return
|
|
328
|
+
return function createWebhookHeaders(_x4) {
|
|
329
|
+
return _ref2.apply(this, arguments);
|
|
315
330
|
};
|
|
316
331
|
}();
|
|
317
332
|
/**
|
|
@@ -319,7 +334,7 @@ const createWebhookHeaders = function() {
|
|
|
319
334
|
* `"<x-calmlens-timestamp>.<raw body>"`, and the timestamp must be within `toleranceSeconds`
|
|
320
335
|
* (default 300) of now. Returns `false` for anything missing or malformed.
|
|
321
336
|
*/
|
|
322
|
-
function verifyWebhookSignature(
|
|
337
|
+
function verifyWebhookSignature(_x5) {
|
|
323
338
|
return _verifyWebhookSignature.apply(this, arguments);
|
|
324
339
|
}
|
|
325
340
|
function _verifyWebhookSignature() {
|
package/cjs/testing.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as GetEventsResponse, C as UpdateAssetOptions, D as GetAssetChildrenResponse, F as Folder, G as AssetStatus, N as AssetBinaryPayloadInput, O as GetAssetResponse, P as Lens, S as SubmitAssetOptions, T as UploadAssetPartOptions, W as Asset, a as CreateAssetSignedUrlOptions, b as RetrieveAssetOptions, c as EnsureLensOptions, d as ListAssetChildrenOptions, f as ListAssetsOptions, g as MoveFolderOptions, h as MoveAssetOptions, i as CdnServeOptions, j as PostAssetSignedUrlResponse, k as GetAssetsPageResponse, l as EnsureLensesOptions, m as ModerateTextOptions, n as CalmLensClientOptions, o as CreateFolderOptions, p as ListEventsOptions, r as CdnAssetUrlOptions, u as FolderIdOptions, w as UpdateFolderOptions, x as RetryAssetOptions } from "./CalmLensTypes-
|
|
1
|
+
import { A as GetEventsResponse, C as UpdateAssetOptions, D as GetAssetChildrenResponse, F as Folder, G as AssetStatus, N as AssetBinaryPayloadInput, O as GetAssetResponse, P as Lens, S as SubmitAssetOptions, T as UploadAssetPartOptions, W as Asset, a as CreateAssetSignedUrlOptions, b as RetrieveAssetOptions, c as EnsureLensOptions, d as ListAssetChildrenOptions, f as ListAssetsOptions, g as MoveFolderOptions, h as MoveAssetOptions, i as CdnServeOptions, j as PostAssetSignedUrlResponse, k as GetAssetsPageResponse, l as EnsureLensesOptions, m as ModerateTextOptions, n as CalmLensClientOptions, o as CreateFolderOptions, p as ListEventsOptions, r as CdnAssetUrlOptions, u as FolderIdOptions, w as UpdateFolderOptions, x as RetryAssetOptions } from "./CalmLensTypes-B7hr0SBv.js";
|
|
2
2
|
import * as zod from "zod";
|
|
3
3
|
//#region ../shared/src/Permissions.d.ts
|
|
4
4
|
declare const GRANT_SCHEMA: zod.ZodObject<{
|
|
@@ -2979,6 +2979,109 @@ declare const EVENT_TYPE_INFO: {
|
|
|
2979
2979
|
lastError: zod.ZodOptional<zod.ZodNullable<zod.ZodString>>;
|
|
2980
2980
|
}, zod.core.$strip>;
|
|
2981
2981
|
};
|
|
2982
|
+
readonly "appeal.submitted": {
|
|
2983
|
+
id: "appeal.submitted";
|
|
2984
|
+
name: string;
|
|
2985
|
+
description: string;
|
|
2986
|
+
category: EventCategory;
|
|
2987
|
+
severity: EventSeverity;
|
|
2988
|
+
/** Whether the in-app connector (notification bell) subscribes to the type by default. */
|
|
2989
|
+
notify: boolean;
|
|
2990
|
+
fields: {
|
|
2991
|
+
appealId: EventFieldDefinition<zod.ZodString>;
|
|
2992
|
+
subjectType: EventFieldDefinition<zod.ZodEnum<{
|
|
2993
|
+
post: "post";
|
|
2994
|
+
"reported-post": "reported-post";
|
|
2995
|
+
"reported-user": "reported-user";
|
|
2996
|
+
user: "user";
|
|
2997
|
+
}>>;
|
|
2998
|
+
subjectId: EventFieldDefinition<zod.ZodString>;
|
|
2999
|
+
};
|
|
3000
|
+
/** Example data, used for synthetic test sends (`createSampleEvent`). */
|
|
3001
|
+
example: NoInfer<{
|
|
3002
|
+
appealId: string;
|
|
3003
|
+
subjectType: "post" | "reported-post" | "reported-user" | "user";
|
|
3004
|
+
subjectId: string;
|
|
3005
|
+
}>;
|
|
3006
|
+
factInfo: {
|
|
3007
|
+
label: string;
|
|
3008
|
+
description: string;
|
|
3009
|
+
display: EventFieldDisplay;
|
|
3010
|
+
/** Kept in the data but left out of rendered messages (usually an ID shown by another field). */
|
|
3011
|
+
hidden?: boolean;
|
|
3012
|
+
schema: zod.ZodType<unknown, unknown, zod.core.$ZodTypeInternals<unknown, unknown>>;
|
|
3013
|
+
key: string;
|
|
3014
|
+
}[];
|
|
3015
|
+
values: zod.ZodObject<{
|
|
3016
|
+
appealId: zod.ZodString;
|
|
3017
|
+
subjectType: zod.ZodEnum<{
|
|
3018
|
+
post: "post";
|
|
3019
|
+
"reported-post": "reported-post";
|
|
3020
|
+
"reported-user": "reported-user";
|
|
3021
|
+
user: "user";
|
|
3022
|
+
}>;
|
|
3023
|
+
subjectId: zod.ZodString;
|
|
3024
|
+
}, zod.core.$strip>;
|
|
3025
|
+
};
|
|
3026
|
+
readonly "appeal.resolved": {
|
|
3027
|
+
id: "appeal.resolved";
|
|
3028
|
+
name: string;
|
|
3029
|
+
description: string;
|
|
3030
|
+
category: EventCategory;
|
|
3031
|
+
severity: EventSeverity;
|
|
3032
|
+
/** Whether the in-app connector (notification bell) subscribes to the type by default. */
|
|
3033
|
+
notify: boolean;
|
|
3034
|
+
fields: {
|
|
3035
|
+
appealId: EventFieldDefinition<zod.ZodString>;
|
|
3036
|
+
subjectType: EventFieldDefinition<zod.ZodEnum<{
|
|
3037
|
+
post: "post";
|
|
3038
|
+
"reported-post": "reported-post";
|
|
3039
|
+
"reported-user": "reported-user";
|
|
3040
|
+
user: "user";
|
|
3041
|
+
}>>;
|
|
3042
|
+
subjectId: EventFieldDefinition<zod.ZodString>;
|
|
3043
|
+
decision: EventFieldDefinition<zod.ZodEnum<{
|
|
3044
|
+
overturned: "overturned";
|
|
3045
|
+
upheld: "upheld";
|
|
3046
|
+
}>>;
|
|
3047
|
+
action: EventFieldDefinition<zod.ZodString>;
|
|
3048
|
+
appliedToAsset: EventFieldDefinition<zod.ZodBoolean>;
|
|
3049
|
+
};
|
|
3050
|
+
/** Example data, used for synthetic test sends (`createSampleEvent`). */
|
|
3051
|
+
example: NoInfer<{
|
|
3052
|
+
appealId: string;
|
|
3053
|
+
subjectType: "post" | "reported-post" | "reported-user" | "user";
|
|
3054
|
+
subjectId: string;
|
|
3055
|
+
decision: "overturned" | "upheld";
|
|
3056
|
+
action: string;
|
|
3057
|
+
appliedToAsset: boolean;
|
|
3058
|
+
}>;
|
|
3059
|
+
factInfo: {
|
|
3060
|
+
label: string;
|
|
3061
|
+
description: string;
|
|
3062
|
+
display: EventFieldDisplay;
|
|
3063
|
+
/** Kept in the data but left out of rendered messages (usually an ID shown by another field). */
|
|
3064
|
+
hidden?: boolean;
|
|
3065
|
+
schema: zod.ZodType<unknown, unknown, zod.core.$ZodTypeInternals<unknown, unknown>>;
|
|
3066
|
+
key: string;
|
|
3067
|
+
}[];
|
|
3068
|
+
values: zod.ZodObject<{
|
|
3069
|
+
appealId: zod.ZodString;
|
|
3070
|
+
subjectType: zod.ZodEnum<{
|
|
3071
|
+
post: "post";
|
|
3072
|
+
"reported-post": "reported-post";
|
|
3073
|
+
"reported-user": "reported-user";
|
|
3074
|
+
user: "user";
|
|
3075
|
+
}>;
|
|
3076
|
+
subjectId: zod.ZodString;
|
|
3077
|
+
decision: zod.ZodEnum<{
|
|
3078
|
+
overturned: "overturned";
|
|
3079
|
+
upheld: "upheld";
|
|
3080
|
+
}>;
|
|
3081
|
+
action: zod.ZodString;
|
|
3082
|
+
appliedToAsset: zod.ZodBoolean;
|
|
3083
|
+
}, zod.core.$strip>;
|
|
3084
|
+
};
|
|
2982
3085
|
};
|
|
2983
3086
|
type EventType = keyof typeof EVENT_TYPE_INFO;
|
|
2984
3087
|
type EventTypeInfo<TType extends EventType = EventType> = (typeof EVENT_TYPE_INFO)[TType];
|
|
@@ -3022,6 +3125,8 @@ declare const EVENT_SCHEMA: zod.ZodObject<{
|
|
|
3022
3125
|
projectId: zod.ZodString;
|
|
3023
3126
|
userId: zod.ZodOptional<zod.ZodNullable<zod.ZodPipe<zod.ZodString, zod.ZodTransform<string, string>>>>;
|
|
3024
3127
|
type: zod.ZodEnum<{
|
|
3128
|
+
"appeal.resolved": "appeal.resolved";
|
|
3129
|
+
"appeal.submitted": "appeal.submitted";
|
|
3025
3130
|
"asset.approved": "asset.approved";
|
|
3026
3131
|
"asset.classified": "asset.classified";
|
|
3027
3132
|
"asset.failed": "asset.failed";
|
package/esm/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as GetEventsResponse, B as EventFactValues, C as UpdateAssetOptions, D as GetAssetChildrenResponse, E as VerifyWebhookSignatureOptions, F as Folder, G as AssetStatus, H as EventSeverity, I as Event, J as MetadataItem, K as AssetType, L as TypedEvent, M as RequestErrorCode, O as GetAssetResponse, P as Lens, R as EventCategory, S as SubmitAssetOptions, T as UploadAssetPartOptions, U as EventType, V as EventFacts, W as Asset, Y as ProcessingOptions, _ as MultipartUploadOptions, a as CreateAssetSignedUrlOptions, b as RetrieveAssetOptions, c as EnsureLensOptions, d as ListAssetChildrenOptions, f as ListAssetsOptions, g as MoveFolderOptions, h as MoveAssetOptions, i as CdnServeOptions, j as PostAssetSignedUrlResponse, k as GetAssetsPageResponse, l as EnsureLensesOptions, m as ModerateTextOptions, n as CalmLensClientOptions, o as CreateFolderOptions, p as ListEventsOptions, q as AssetVisibility, r as CdnAssetUrlOptions, s as CreateMultipartUploadPartOptions, t as AssetContentOptions, u as FolderIdOptions, v as MultipartUploadPartOptions, w as UpdateFolderOptions, x as RetryAssetOptions, y as RequestOptions, z as EventFact } from "./CalmLensTypes-
|
|
1
|
+
import { A as GetEventsResponse, B as EventFactValues, C as UpdateAssetOptions, D as GetAssetChildrenResponse, E as VerifyWebhookSignatureOptions, F as Folder, G as AssetStatus, H as EventSeverity, I as Event, J as MetadataItem, K as AssetType, L as TypedEvent, M as RequestErrorCode, O as GetAssetResponse, P as Lens, R as EventCategory, S as SubmitAssetOptions, T as UploadAssetPartOptions, U as EventType, V as EventFacts, W as Asset, Y as ProcessingOptions, _ as MultipartUploadOptions, a as CreateAssetSignedUrlOptions, b as RetrieveAssetOptions, c as EnsureLensOptions, d as ListAssetChildrenOptions, f as ListAssetsOptions, g as MoveFolderOptions, h as MoveAssetOptions, i as CdnServeOptions, j as PostAssetSignedUrlResponse, k as GetAssetsPageResponse, l as EnsureLensesOptions, m as ModerateTextOptions, n as CalmLensClientOptions, o as CreateFolderOptions, p as ListEventsOptions, q as AssetVisibility, r as CdnAssetUrlOptions, s as CreateMultipartUploadPartOptions, t as AssetContentOptions, u as FolderIdOptions, v as MultipartUploadPartOptions, w as UpdateFolderOptions, x as RetryAssetOptions, y as RequestOptions, z as EventFact } from "./CalmLensTypes-B7hr0SBv.js";
|
|
2
2
|
import * as zod from "zod";
|
|
3
3
|
//#region ../shared/src/AssetSearch.d.ts
|
|
4
4
|
declare const ASSET_SEARCH_QUERY_SCHEMA: zod.ZodObject<{
|
package/esm/index.js
CHANGED
|
@@ -242,6 +242,42 @@ function generateMediaTestCode(signal, projectId) {
|
|
|
242
242
|
return `Calm Lens test ${[...suffix].map((character) => HEX_WORDS[Number.parseInt(character, 16)]).join(" ")} ${signal.replace(/[.-]/g, " ")} end test`;
|
|
243
243
|
}
|
|
244
244
|
//#endregion
|
|
245
|
+
//#region ../shared/src/CryptoUtils.ts
|
|
246
|
+
const encoder = new TextEncoder();
|
|
247
|
+
/** Lowercase hex of `bytes`, two characters per byte. */
|
|
248
|
+
const bytesToHex = (bytes) => Array.from(bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
249
|
+
(function() {
|
|
250
|
+
var _ref = _asyncToGenerator(function* (value) {
|
|
251
|
+
return bytesToHex(yield crypto.subtle.digest("SHA-256", encoder.encode(value)));
|
|
252
|
+
});
|
|
253
|
+
return function sha256Hex(_x) {
|
|
254
|
+
return _ref.apply(this, arguments);
|
|
255
|
+
};
|
|
256
|
+
})();
|
|
257
|
+
/** HMAC-SHA256 of `message` keyed with `secret` (both UTF-8 encoded), as lowercase hex. */
|
|
258
|
+
const hmacSha256Hex = function() {
|
|
259
|
+
var _ref2 = _asyncToGenerator(function* (secret, message) {
|
|
260
|
+
const key = yield crypto.subtle.importKey("raw", encoder.encode(secret), {
|
|
261
|
+
name: "HMAC",
|
|
262
|
+
hash: "SHA-256"
|
|
263
|
+
}, false, ["sign"]);
|
|
264
|
+
return bytesToHex(yield crypto.subtle.sign("HMAC", key, encoder.encode(message)));
|
|
265
|
+
});
|
|
266
|
+
return function hmacSha256Hex(_x2, _x3) {
|
|
267
|
+
return _ref2.apply(this, arguments);
|
|
268
|
+
};
|
|
269
|
+
}();
|
|
270
|
+
/**
|
|
271
|
+
* Compares two strings without leaking, through timing, where they first differ. Strings of
|
|
272
|
+
* different lengths are unequal immediately (the length itself is not secret here).
|
|
273
|
+
*/
|
|
274
|
+
const timingSafeEqual = (a, b) => {
|
|
275
|
+
if (a.length !== b.length) return false;
|
|
276
|
+
let difference = 0;
|
|
277
|
+
for (let index = 0; index < a.length; index++) difference |= a.charCodeAt(index) ^ b.charCodeAt(index);
|
|
278
|
+
return difference === 0;
|
|
279
|
+
};
|
|
280
|
+
//#endregion
|
|
245
281
|
//#region src/client/CalmLensWebhooks.ts
|
|
246
282
|
const WEBHOOK_DELIVERY_HEADER = "x-calmlens-delivery";
|
|
247
283
|
const WEBHOOK_TIMESTAMP_HEADER = "x-calmlens-timestamp";
|
|
@@ -266,39 +302,18 @@ const toWebhookEventPayload = (event) => {
|
|
|
266
302
|
}
|
|
267
303
|
};
|
|
268
304
|
};
|
|
269
|
-
const encoder = new TextEncoder();
|
|
270
|
-
const hmacSha256Hex = function() {
|
|
271
|
-
var _ref = _asyncToGenerator(function* (secret, message) {
|
|
272
|
-
const key = yield crypto.subtle.importKey("raw", encoder.encode(secret), {
|
|
273
|
-
name: "HMAC",
|
|
274
|
-
hash: "SHA-256"
|
|
275
|
-
}, false, ["sign"]);
|
|
276
|
-
const signature = yield crypto.subtle.sign("HMAC", key, encoder.encode(message));
|
|
277
|
-
return Array.from(new Uint8Array(signature), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
278
|
-
});
|
|
279
|
-
return function hmacSha256Hex(_x, _x2) {
|
|
280
|
-
return _ref.apply(this, arguments);
|
|
281
|
-
};
|
|
282
|
-
}();
|
|
283
|
-
/** Constant-time comparison of two strings of the same length. */
|
|
284
|
-
const timingSafeEqual = (a, b) => {
|
|
285
|
-
if (a.length !== b.length) return false;
|
|
286
|
-
let diff = 0;
|
|
287
|
-
for (let i = 0; i < a.length; i++) diff |= a.charCodeAt(i) ^ b.charCodeAt(i);
|
|
288
|
-
return diff === 0;
|
|
289
|
-
};
|
|
290
305
|
/** `v1=<hex HMAC-SHA256 of "<timestamp>.<body>">`, the `x-calmlens-signature` header value. */
|
|
291
306
|
const createWebhookSignatureHeader = function() {
|
|
292
|
-
var
|
|
307
|
+
var _ref = _asyncToGenerator(function* (secret, timestamp, body) {
|
|
293
308
|
return `v1=${yield hmacSha256Hex(secret, `${timestamp}.${body}`)}`;
|
|
294
309
|
});
|
|
295
|
-
return function createWebhookSignatureHeader(
|
|
296
|
-
return
|
|
310
|
+
return function createWebhookSignatureHeader(_x, _x2, _x3) {
|
|
311
|
+
return _ref.apply(this, arguments);
|
|
297
312
|
};
|
|
298
313
|
}();
|
|
299
314
|
/** Headers for one signed delivery of `body`. */
|
|
300
315
|
const createWebhookHeaders = function() {
|
|
301
|
-
var
|
|
316
|
+
var _ref2 = _asyncToGenerator(function* (options) {
|
|
302
317
|
var _options$timestampSec;
|
|
303
318
|
const timestamp = (_options$timestampSec = options.timestampSeconds) !== null && _options$timestampSec !== void 0 ? _options$timestampSec : Math.floor(Date.now() / 1e3);
|
|
304
319
|
return {
|
|
@@ -308,8 +323,8 @@ const createWebhookHeaders = function() {
|
|
|
308
323
|
[WEBHOOK_SIGNATURE_HEADER]: yield createWebhookSignatureHeader(options.secret, timestamp, options.body)
|
|
309
324
|
};
|
|
310
325
|
});
|
|
311
|
-
return function createWebhookHeaders(
|
|
312
|
-
return
|
|
326
|
+
return function createWebhookHeaders(_x4) {
|
|
327
|
+
return _ref2.apply(this, arguments);
|
|
313
328
|
};
|
|
314
329
|
}();
|
|
315
330
|
/**
|
|
@@ -317,7 +332,7 @@ const createWebhookHeaders = function() {
|
|
|
317
332
|
* `"<x-calmlens-timestamp>.<raw body>"`, and the timestamp must be within `toleranceSeconds`
|
|
318
333
|
* (default 300) of now. Returns `false` for anything missing or malformed.
|
|
319
334
|
*/
|
|
320
|
-
function verifyWebhookSignature(
|
|
335
|
+
function verifyWebhookSignature(_x5) {
|
|
321
336
|
return _verifyWebhookSignature.apply(this, arguments);
|
|
322
337
|
}
|
|
323
338
|
function _verifyWebhookSignature() {
|
package/esm/testing.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as GetEventsResponse, C as UpdateAssetOptions, D as GetAssetChildrenResponse, F as Folder, G as AssetStatus, N as AssetBinaryPayloadInput, O as GetAssetResponse, P as Lens, S as SubmitAssetOptions, T as UploadAssetPartOptions, W as Asset, a as CreateAssetSignedUrlOptions, b as RetrieveAssetOptions, c as EnsureLensOptions, d as ListAssetChildrenOptions, f as ListAssetsOptions, g as MoveFolderOptions, h as MoveAssetOptions, i as CdnServeOptions, j as PostAssetSignedUrlResponse, k as GetAssetsPageResponse, l as EnsureLensesOptions, m as ModerateTextOptions, n as CalmLensClientOptions, o as CreateFolderOptions, p as ListEventsOptions, r as CdnAssetUrlOptions, u as FolderIdOptions, w as UpdateFolderOptions, x as RetryAssetOptions } from "./CalmLensTypes-
|
|
1
|
+
import { A as GetEventsResponse, C as UpdateAssetOptions, D as GetAssetChildrenResponse, F as Folder, G as AssetStatus, N as AssetBinaryPayloadInput, O as GetAssetResponse, P as Lens, S as SubmitAssetOptions, T as UploadAssetPartOptions, W as Asset, a as CreateAssetSignedUrlOptions, b as RetrieveAssetOptions, c as EnsureLensOptions, d as ListAssetChildrenOptions, f as ListAssetsOptions, g as MoveFolderOptions, h as MoveAssetOptions, i as CdnServeOptions, j as PostAssetSignedUrlResponse, k as GetAssetsPageResponse, l as EnsureLensesOptions, m as ModerateTextOptions, n as CalmLensClientOptions, o as CreateFolderOptions, p as ListEventsOptions, r as CdnAssetUrlOptions, u as FolderIdOptions, w as UpdateFolderOptions, x as RetryAssetOptions } from "./CalmLensTypes-B7hr0SBv.js";
|
|
2
2
|
import * as zod from "zod";
|
|
3
3
|
//#region ../shared/src/Permissions.d.ts
|
|
4
4
|
declare const GRANT_SCHEMA: zod.ZodObject<{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@calmlens/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/Censkh/CalmLens.git",
|
|
@@ -18,17 +18,13 @@
|
|
|
18
18
|
"node": ">=22"
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
21
|
-
"generate:fixtures": "bun scripts/generateFixtures.ts",
|
|
22
21
|
"prepublishOnly": "npm run check && npm run test && npm run build",
|
|
23
22
|
"test": "bun test --parallel=4 tests",
|
|
24
|
-
"example:start": "cd example && npm run start",
|
|
25
23
|
"check:fix": "tsc --noEmit --project tsconfig.json && npx @biomejs/biome check --write",
|
|
26
24
|
"check": "tsc --noEmit --project tsconfig.json && npx @biomejs/biome check",
|
|
27
25
|
"cleanup": "rimraf esm && rimraf cjs && rimraf bin",
|
|
28
26
|
"build": "npm run cleanup && rolldown -c rolldown.config.mjs && node scripts/post-build.js && npm run verify:package",
|
|
29
|
-
"verify:package": "node scripts/verify-package.mjs"
|
|
30
|
-
"website:dev": "cd website && npm run start",
|
|
31
|
-
"website:deploy": "cd website && npm run deploy"
|
|
27
|
+
"verify:package": "node scripts/verify-package.mjs"
|
|
32
28
|
},
|
|
33
29
|
"keywords": [
|
|
34
30
|
"typescript",
|
|
@@ -51,8 +47,8 @@
|
|
|
51
47
|
"devDependencies": {
|
|
52
48
|
"@biomejs/biome": "^2.5.15",
|
|
53
49
|
"@oxc-project/runtime": "0.148.0",
|
|
54
|
-
"@types/bun": "^1.
|
|
55
|
-
"@types/node": "
|
|
50
|
+
"@types/bun": "^1.4.2",
|
|
51
|
+
"@types/node": "26.6.1",
|
|
56
52
|
"rimraf": "6.1.3",
|
|
57
53
|
"rolldown": "1.2.13",
|
|
58
54
|
"rolldown-plugin-dts": "0.28.7",
|