@calmlens/sdk 0.14.0 → 0.16.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 +30 -10
- package/cjs/{CalmLensConnection-Bth5fJyp.js → CalmLensConnection-CPdx_acA.js} +2 -2
- package/cjs/{CalmLensUtils-DNdmYeX6.js → CalmLensUtils-DvhY8-cU.js} +1 -1
- package/cjs/{CalmLensVersion-Bs0DreBV.js → CalmLensVersion-CrlGk2gX.js} +6 -1
- package/cjs/{CalmLensWebhooks-6thkvr_F.js → CalmLensWebhooks-C2VrleZm.js} +4 -4
- package/cjs/Classification-DJU_DfOO.d.ts +4565 -0
- package/cjs/TestTriggers-CxFZ-3uz.d.ts +43 -0
- package/cjs/{WebhookPayload-vy8HNMaK.d.ts → WebhookPayload-BfUmVu2y.d.ts} +77 -4622
- package/cjs/app.d.ts +4 -3
- package/cjs/app.js +3 -3
- package/cjs/{index-Dz340UQ9.d.ts → index-VxklV9OQ.d.ts} +4 -1
- package/cjs/index.d.ts +4 -3
- package/cjs/index.js +1 -1
- package/cjs/server.d.ts +8 -7
- package/cjs/server.js +17 -21
- package/cjs/test-inputs.d.ts +2 -0
- package/cjs/test-inputs.js +265 -0
- package/cjs/testing.d.ts +3 -5
- package/cjs/testing.js +51 -30
- package/esm/{CalmLensConnection-DrCOL9h9.js → CalmLensConnection-DYo5U2L0.js} +2 -2
- package/esm/{CalmLensUtils-BQo79TA1.js → CalmLensUtils-BDtpOfho.js} +1 -1
- package/esm/{CalmLensVersion-DPnL_Ebv.js → CalmLensVersion-CchG7NWy.js} +6 -1
- package/esm/{CalmLensWebhooks-CWlD-f_P.js → CalmLensWebhooks-B7nQMCHx.js} +4 -4
- package/esm/Classification-DJU_DfOO.d.ts +4565 -0
- package/esm/TestTriggers-CxFZ-3uz.d.ts +43 -0
- package/esm/{WebhookPayload-vy8HNMaK.d.ts → WebhookPayload-BfUmVu2y.d.ts} +77 -4622
- package/esm/app.d.ts +4 -3
- package/esm/app.js +3 -3
- package/esm/{index-Dz340UQ9.d.ts → index-VxklV9OQ.d.ts} +4 -1
- package/esm/index.d.ts +4 -3
- package/esm/index.js +1 -1
- package/esm/server.d.ts +8 -7
- package/esm/server.js +17 -21
- package/esm/test-inputs.d.ts +2 -0
- package/esm/test-inputs.js +256 -0
- package/esm/testing.d.ts +3 -5
- package/esm/testing.js +51 -30
- package/package.json +13 -2
package/esm/app.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
import {
|
|
1
|
+
import { $ as SearchAssetsOptions, A as DeleteAssetContentOptions, At as AssetSearchQuery, B as Lens, C as CdnAssetUrlOptions, Ct as EventType, D as CreateAssetSignedUrlOptions, Dt as Order, E as ConnectionOptions, Et as CursorPage, F as IdempotencyOptions, Ft as ImageData, G as ModerateTextOptions, H as ListAssetChildrenOptions, I as ImageTransform, It as MetadataItem, J as MultipartUploadOptions, K as MoveAssetOptions, L as ImageTransformOptions, Lt as PreviewImage, M as EnsureLensOptions, Mt as AssetSafetyHold, N as EnsureLensesOptions, Nt as AssetSafetyHoldReason, O as CreateFolderOptions, Ot as LensType, P as FolderIdOptions, Pt as ExtractedText, Q as RetryAssetOptions, R as IterateAssetChildrenOptions, Rt as ProcessingOptions, S as CalmLensServerClientOptions, St as EventSeverity, T as CdnTransform, Tt as Folder, U as ListAssetsOptions, V as LensTransform, W as ListEventsOptions, X as RequestOptions, Y as MultipartUploadPartOptions, Z as RetrieveAssetOptions, _ as AssetSearchResponse, _t as TypedEvent, a as AssetChildrenPage, at as UpdateFolderOptions, b as AssetVisibility, bt as EventFactValues, c as AssetContentRemovalReason, ct as UploadedAsset, d as AssetModerationAction, dt as WebhookHeadersInput, et as SignUploadTokenOptions, f as AssetModerationStatus, ft as WebhookPayloadInput, g as AssetReviewerAction, gt as EventAsset, h as AssetProcessingStatus, i as AssetChecksums, it as UpdateAssetOptions, j as DeleteAssetOptions, k as CreateMultipartUploadPartOptions, kt as AssetSearchMatchField, l as AssetContentStatus, lt as VerifyWebhookSignatureOptions, m as AssetProcessing, nt as SignedUrl, o as AssetContent, ot as UploadAssetPartOptions, p as AssetPage, pt as GetEventsResponse, q as MoveFolderOptions, r as Asset, rt as SubmitAssetOptions, s as AssetContentOptions, st as UploadPresetSubmitAssetOptions, t as ReceivedWebhookEventPayload, tt as SignedUploadToken, u as AssetModeration, ut as WaitForAssetDecisionOptions, v as AssetSearchResult, vt as EventCategory, w as CdnServeOptions, x as CalmLensAppClientOptions, xt as EventFacts, y as AssetType, yt as EventFact, z as IterateAssetsOptions } from "./WebhookPayload-BfUmVu2y.js";
|
|
2
|
+
import { a as ClassificationNotEvaluatedReason, c as Likelihood, i as ClassificationLabel, l as ModerationQualifier, n as ClassificationCategory, o as ClassificationQualifierResults, r as ClassificationCategoryReport, s as ClassificationReport, t as ClassificationCategories } from "./Classification-DJU_DfOO.js";
|
|
3
|
+
import { _ as ProcessingFeatureStage, a as CalmLensErrorDetails, c as ApiErrorCode, d as AgeRange, f as BoundingBox, g as ProcessingFeatureResults, h as ProcessingFeatureId, i as CalmLensErrorCode, l as FlaggedContentAction, m as DetectedPerson, n as CALMLENS_ERROR_CODES, o as CalmLensErrorOptions, p as DetectedFace, r as CalmLensError, s as SdkErrorCode, t as SDK_VERSION, u as FlaggedContentPolicy, v as ProcessingFeatures } from "./index-VxklV9OQ.js";
|
|
3
4
|
//#region src/client/CalmLensAppClient.d.ts
|
|
4
5
|
declare const inspectSymbol: unique symbol;
|
|
5
6
|
/**
|
|
@@ -40,4 +41,4 @@ declare class CalmLensAppClient {
|
|
|
40
41
|
};
|
|
41
42
|
}
|
|
42
43
|
//#endregion
|
|
43
|
-
export { type AgeRange, type ApiErrorCode, type Asset, type AssetChecksums, type AssetChildrenPage, type AssetContent, type AssetContentOptions, type AssetContentRemovalReason, type AssetContentStatus, type AssetModeration, type AssetModerationAction, type AssetModerationStatus, type AssetPage, type AssetProcessing, type AssetProcessingStatus, type AssetReviewerAction, type AssetSafetyHold, type AssetSafetyHoldReason, type AssetSearchMatchField, type AssetSearchQuery, type AssetSearchResponse, type AssetSearchResult, type AssetType, type AssetVisibility, type BoundingBox, CALMLENS_ERROR_CODES, CalmLensAppClient, type CalmLensAppClientOptions, CalmLensError, type CalmLensErrorCode, type CalmLensErrorDetails, type CalmLensErrorOptions, type CalmLensServerClientOptions, type CdnAssetUrlOptions, type CdnServeOptions, type CdnTransform, type ClassificationCategories, type ClassificationCategory, type ClassificationCategoryReport, type ClassificationLabel, type ClassificationNotEvaluatedReason, type ClassificationQualifierResults, type ClassificationReport, type ConnectionOptions, type CreateAssetSignedUrlOptions, type CreateFolderOptions, type CreateMultipartUploadPartOptions, type DeleteAssetContentOptions, type DeleteAssetOptions, type DetectedFace, type DetectedPerson, type EnsureLensOptions, type EnsureLensesOptions, type EventAsset, type EventCategory, type EventFact, type EventFactValues, type EventFacts, type EventSeverity, type EventType, type GetEventsResponse as EventsPage, type ExtractedText, type FlaggedContentAction, type FlaggedContentPolicy, type Folder, type FolderIdOptions, type IdempotencyOptions, type ImageData, type ImageTransform, type ImageTransformOptions, type IterateAssetChildrenOptions, type IterateAssetsOptions, type Lens, type LensTransform, type LensType, type Likelihood, type ListAssetChildrenOptions, type ListAssetsOptions, type ListEventsOptions, type MetadataItem, type ModerateTextOptions, type ModerationQualifier, type MoveAssetOptions, type MoveFolderOptions, type MultipartUploadOptions, type MultipartUploadPartOptions, type Order, type
|
|
44
|
+
export { type AgeRange, type ApiErrorCode, type Asset, type AssetChecksums, type AssetChildrenPage, type AssetContent, type AssetContentOptions, type AssetContentRemovalReason, type AssetContentStatus, type AssetModeration, type AssetModerationAction, type AssetModerationStatus, type AssetPage, type AssetProcessing, type AssetProcessingStatus, type AssetReviewerAction, type AssetSafetyHold, type AssetSafetyHoldReason, type AssetSearchMatchField, type AssetSearchQuery, type AssetSearchResponse, type AssetSearchResult, type AssetType, type AssetVisibility, type BoundingBox, CALMLENS_ERROR_CODES, CalmLensAppClient, type CalmLensAppClientOptions, CalmLensError, type CalmLensErrorCode, type CalmLensErrorDetails, type CalmLensErrorOptions, type CalmLensServerClientOptions, type CdnAssetUrlOptions, type CdnServeOptions, type CdnTransform, type ClassificationCategories, type ClassificationCategory, type ClassificationCategoryReport, type ClassificationLabel, type ClassificationNotEvaluatedReason, type ClassificationQualifierResults, type ClassificationReport, type ConnectionOptions, type CreateAssetSignedUrlOptions, type CreateFolderOptions, type CreateMultipartUploadPartOptions, type CursorPage, type DeleteAssetContentOptions, type DeleteAssetOptions, type DetectedFace, type DetectedPerson, type EnsureLensOptions, type EnsureLensesOptions, type EventAsset, type EventCategory, type EventFact, type EventFactValues, type EventFacts, type EventSeverity, type EventType, type GetEventsResponse as EventsPage, type ExtractedText, type FlaggedContentAction, type FlaggedContentPolicy, type Folder, type FolderIdOptions, type IdempotencyOptions, type ImageData, type ImageTransform, type ImageTransformOptions, type IterateAssetChildrenOptions, type IterateAssetsOptions, type Lens, type LensTransform, type LensType, type Likelihood, type ListAssetChildrenOptions, type ListAssetsOptions, type ListEventsOptions, type MetadataItem, type ModerateTextOptions, type ModerationQualifier, type MoveAssetOptions, type MoveFolderOptions, type MultipartUploadOptions, type MultipartUploadPartOptions, type Order, type PreviewImage, type ProcessingFeatureId, type ProcessingFeatureResults, type ProcessingFeatureStage, type ProcessingFeatures, type ProcessingOptions, type RequestOptions, type RetrieveAssetOptions, type RetryAssetOptions, SDK_VERSION, type SdkErrorCode, type SearchAssetsOptions, type SignUploadTokenOptions, type SignedUploadToken, type SignedUrl, type SubmitAssetOptions, type TypedEvent, type UpdateAssetOptions, type UpdateFolderOptions, type UploadAssetPartOptions, type UploadPresetSubmitAssetOptions, type UploadedAsset, type VerifyWebhookSignatureOptions, type WaitForAssetDecisionOptions, type ReceivedWebhookEventPayload as WebhookEventPayload, type WebhookHeadersInput, type WebhookPayloadInput };
|
package/esm/app.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { a as CALMLENS_ERROR_CODES, c as invalidArgument, l as invalidConfig, o as CalmLensError, t as SDK_VERSION } from "./CalmLensVersion-
|
|
1
|
+
import { a as CALMLENS_ERROR_CODES, c as invalidArgument, l as invalidConfig, o as CalmLensError, t as SDK_VERSION } from "./CalmLensVersion-CchG7NWy.js";
|
|
2
2
|
import "./index.js";
|
|
3
|
-
import { c as validateAppClientOptions, n as encodePathSegment } from "./CalmLensUtils-
|
|
4
|
-
import { o as prepareSubmitAssetOptions, r as expectUploadedAsset, s as resolveConnectionOptions, t as CalmLensConnection } from "./CalmLensConnection-
|
|
3
|
+
import { c as validateAppClientOptions, n as encodePathSegment } from "./CalmLensUtils-BDtpOfho.js";
|
|
4
|
+
import { o as prepareSubmitAssetOptions, r as expectUploadedAsset, s as resolveConnectionOptions, t as CalmLensConnection } from "./CalmLensConnection-DYo5U2L0.js";
|
|
5
5
|
//#region src/client/CalmLensAppClient.ts
|
|
6
6
|
const inspectSymbol = Symbol.for("nodejs.util.inspect.custom");
|
|
7
7
|
/**
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import "./WebhookPayload-
|
|
1
|
+
import "./WebhookPayload-BfUmVu2y.js";
|
|
2
|
+
import "./Classification-DJU_DfOO.js";
|
|
2
3
|
import * as zod from "zod";
|
|
3
4
|
//#region ../shared/src/ProcessingFeatures.d.ts
|
|
4
5
|
/**
|
|
@@ -142,6 +143,7 @@ type FlaggedContentPolicy = zod.infer<typeof FLAGGED_CONTENT_POLICY_SCHEMA>;
|
|
|
142
143
|
//#region src/client/CalmLensErrorCodes.d.ts
|
|
143
144
|
/** Error codes the CalmLens API documents, by name. */
|
|
144
145
|
declare const API_ERROR_CODES: {
|
|
146
|
+
readonly INVALID_CURSOR: "validation/invalid-cursor";
|
|
145
147
|
readonly MISSING_TOKEN: "auth/missing-token";
|
|
146
148
|
readonly INVALID_API_KEY: "auth/invalid-api-key";
|
|
147
149
|
readonly API_KEY_PROJECT_MISMATCH: "auth/project-mismatch";
|
|
@@ -234,6 +236,7 @@ declare const SDK_ERROR_CODES: {
|
|
|
234
236
|
type SdkErrorCode = (typeof SDK_ERROR_CODES)[keyof typeof SDK_ERROR_CODES];
|
|
235
237
|
/** Every error code the SDK can throw: the documented API codes and the SDK's own `sdk/*` codes. */
|
|
236
238
|
declare const CALMLENS_ERROR_CODES: {
|
|
239
|
+
readonly INVALID_CURSOR: "validation/invalid-cursor";
|
|
237
240
|
readonly MISSING_TOKEN: "auth/missing-token";
|
|
238
241
|
readonly INVALID_API_KEY: "auth/invalid-api-key";
|
|
239
242
|
readonly API_KEY_PROJECT_MISMATCH: "auth/project-mismatch";
|
package/esm/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { $ as SearchAssetsOptions, A as DeleteAssetContentOptions, At as AssetSearchQuery, B as Lens, C as CdnAssetUrlOptions, Ct as EventType, D as CreateAssetSignedUrlOptions, Dt as Order, E as ConnectionOptions, Et as CursorPage, F as IdempotencyOptions, Ft as ImageData, G as ModerateTextOptions, H as ListAssetChildrenOptions, I as ImageTransform, It as MetadataItem, J as MultipartUploadOptions, K as MoveAssetOptions, L as ImageTransformOptions, Lt as PreviewImage, M as EnsureLensOptions, Mt as AssetSafetyHold, N as EnsureLensesOptions, Nt as AssetSafetyHoldReason, O as CreateFolderOptions, Ot as LensType, P as FolderIdOptions, Pt as ExtractedText, Q as RetryAssetOptions, R as IterateAssetChildrenOptions, Rt as ProcessingOptions, S as CalmLensServerClientOptions, St as EventSeverity, T as CdnTransform, Tt as Folder, U as ListAssetsOptions, V as LensTransform, W as ListEventsOptions, X as RequestOptions, Y as MultipartUploadPartOptions, Z as RetrieveAssetOptions, _ as AssetSearchResponse, _t as TypedEvent, a as AssetChildrenPage, at as UpdateFolderOptions, b as AssetVisibility, bt as EventFactValues, c as AssetContentRemovalReason, ct as UploadedAsset, d as AssetModerationAction, dt as WebhookHeadersInput, et as SignUploadTokenOptions, f as AssetModerationStatus, ft as WebhookPayloadInput, g as AssetReviewerAction, gt as EventAsset, h as AssetProcessingStatus, i as AssetChecksums, it as UpdateAssetOptions, j as DeleteAssetOptions, k as CreateMultipartUploadPartOptions, kt as AssetSearchMatchField, l as AssetContentStatus, lt as VerifyWebhookSignatureOptions, m as AssetProcessing, nt as SignedUrl, o as AssetContent, ot as UploadAssetPartOptions, p as AssetPage, pt as GetEventsResponse, q as MoveFolderOptions, r as Asset, rt as SubmitAssetOptions, s as AssetContentOptions, st as UploadPresetSubmitAssetOptions, t as ReceivedWebhookEventPayload, tt as SignedUploadToken, u as AssetModeration, ut as WaitForAssetDecisionOptions, v as AssetSearchResult, vt as EventCategory, w as CdnServeOptions, x as CalmLensAppClientOptions, xt as EventFacts, y as AssetType, yt as EventFact, z as IterateAssetsOptions } from "./WebhookPayload-BfUmVu2y.js";
|
|
2
|
+
import { a as ClassificationNotEvaluatedReason, c as Likelihood, i as ClassificationLabel, l as ModerationQualifier, n as ClassificationCategory, o as ClassificationQualifierResults, r as ClassificationCategoryReport, s as ClassificationReport, t as ClassificationCategories } from "./Classification-DJU_DfOO.js";
|
|
3
|
+
import { _ as ProcessingFeatureStage, a as CalmLensErrorDetails, c as ApiErrorCode, d as AgeRange, f as BoundingBox, g as ProcessingFeatureResults, h as ProcessingFeatureId, i as CalmLensErrorCode, l as FlaggedContentAction, m as DetectedPerson, n as CALMLENS_ERROR_CODES, o as CalmLensErrorOptions, p as DetectedFace, r as CalmLensError, s as SdkErrorCode, t as SDK_VERSION, u as FlaggedContentPolicy, v as ProcessingFeatures } from "./index-VxklV9OQ.js";
|
|
4
|
+
export { type AgeRange, type ApiErrorCode, type Asset, type AssetChecksums, type AssetChildrenPage, type AssetContent, type AssetContentOptions, type AssetContentRemovalReason, type AssetContentStatus, type AssetModeration, type AssetModerationAction, type AssetModerationStatus, type AssetPage, type AssetProcessing, type AssetProcessingStatus, type AssetReviewerAction, type AssetSafetyHold, type AssetSafetyHoldReason, type AssetSearchMatchField, type AssetSearchQuery, type AssetSearchResponse, type AssetSearchResult, type AssetType, type AssetVisibility, type BoundingBox, CALMLENS_ERROR_CODES, type CalmLensAppClientOptions, CalmLensError, type CalmLensErrorCode, type CalmLensErrorDetails, type CalmLensErrorOptions, type CalmLensServerClientOptions, type CdnAssetUrlOptions, type CdnServeOptions, type CdnTransform, type ClassificationCategories, type ClassificationCategory, type ClassificationCategoryReport, type ClassificationLabel, type ClassificationNotEvaluatedReason, type ClassificationQualifierResults, type ClassificationReport, type ConnectionOptions, type CreateAssetSignedUrlOptions, type CreateFolderOptions, type CreateMultipartUploadPartOptions, type CursorPage, type DeleteAssetContentOptions, type DeleteAssetOptions, type DetectedFace, type DetectedPerson, type EnsureLensOptions, type EnsureLensesOptions, type EventAsset, type EventCategory, type EventFact, type EventFactValues, type EventFacts, type EventSeverity, type EventType, type GetEventsResponse as EventsPage, type ExtractedText, type FlaggedContentAction, type FlaggedContentPolicy, type Folder, type FolderIdOptions, type IdempotencyOptions, type ImageData, type ImageTransform, type ImageTransformOptions, type IterateAssetChildrenOptions, type IterateAssetsOptions, type Lens, type LensTransform, type LensType, type Likelihood, type ListAssetChildrenOptions, type ListAssetsOptions, type ListEventsOptions, type MetadataItem, type ModerateTextOptions, type ModerationQualifier, type MoveAssetOptions, type MoveFolderOptions, type MultipartUploadOptions, type MultipartUploadPartOptions, type Order, type PreviewImage, type ProcessingFeatureId, type ProcessingFeatureResults, type ProcessingFeatureStage, type ProcessingFeatures, type ProcessingOptions, type RequestOptions, type RetrieveAssetOptions, type RetryAssetOptions, SDK_VERSION, type SdkErrorCode, type SearchAssetsOptions, type SignUploadTokenOptions, type SignedUploadToken, type SignedUrl, type SubmitAssetOptions, type TypedEvent, type UpdateAssetOptions, type UpdateFolderOptions, type UploadAssetPartOptions, type UploadPresetSubmitAssetOptions, type UploadedAsset, type VerifyWebhookSignatureOptions, type WaitForAssetDecisionOptions, type ReceivedWebhookEventPayload as WebhookEventPayload, type WebhookHeadersInput, type WebhookPayloadInput };
|
package/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { a as CALMLENS_ERROR_CODES, o as CalmLensError, t as SDK_VERSION } from "./CalmLensVersion-
|
|
1
|
+
export { a as CALMLENS_ERROR_CODES, o as CalmLensError, t as SDK_VERSION } from "./CalmLensVersion-CchG7NWy.js";
|
package/esm/server.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
import {
|
|
1
|
+
import { $ as SearchAssetsOptions, A as DeleteAssetContentOptions, At as AssetSearchQuery, B as Lens, C as CdnAssetUrlOptions, Ct as EventType, D as CreateAssetSignedUrlOptions, Dt as Order, E as ConnectionOptions, Et as CursorPage, F as IdempotencyOptions, Ft as ImageData, G as ModerateTextOptions, H as ListAssetChildrenOptions, I as ImageTransform, It as MetadataItem, J as MultipartUploadOptions, K as MoveAssetOptions, L as ImageTransformOptions, Lt as PreviewImage, M as EnsureLensOptions, Mt as AssetSafetyHold, N as EnsureLensesOptions, Nt as AssetSafetyHoldReason, O as CreateFolderOptions, Ot as LensType, P as FolderIdOptions, Pt as ExtractedText, Q as RetryAssetOptions, R as IterateAssetChildrenOptions, Rt as ProcessingOptions, S as CalmLensServerClientOptions, St as EventSeverity, T as CdnTransform, Tt as Folder, U as ListAssetsOptions, V as LensTransform, W as ListEventsOptions, X as RequestOptions, Y as MultipartUploadPartOptions, Z as RetrieveAssetOptions, _ as AssetSearchResponse, _t as TypedEvent, a as AssetChildrenPage, at as UpdateFolderOptions, b as AssetVisibility, bt as EventFactValues, c as AssetContentRemovalReason, ct as UploadedAsset, d as AssetModerationAction, dt as WebhookHeadersInput, et as SignUploadTokenOptions, f as AssetModerationStatus, ft as WebhookPayloadInput, g as AssetReviewerAction, gt as EventAsset, h as AssetProcessingStatus, i as AssetChecksums, it as UpdateAssetOptions, j as DeleteAssetOptions, k as CreateMultipartUploadPartOptions, kt as AssetSearchMatchField, l as AssetContentStatus, lt as VerifyWebhookSignatureOptions, m as AssetProcessing, mt as PostAssetSignedUrlResponse, nt as SignedUrl, o as AssetContent, ot as UploadAssetPartOptions, p as AssetPage, pt as GetEventsResponse, q as MoveFolderOptions, r as Asset, rt as SubmitAssetOptions, s as AssetContentOptions, st as UploadPresetSubmitAssetOptions, t as ReceivedWebhookEventPayload, tt as SignedUploadToken, u as AssetModeration, ut as WaitForAssetDecisionOptions, v as AssetSearchResult, vt as EventCategory, w as CdnServeOptions, x as CalmLensAppClientOptions, xt as EventFacts, y as AssetType, yt as EventFact, z as IterateAssetsOptions } from "./WebhookPayload-BfUmVu2y.js";
|
|
2
|
+
import { a as ClassificationNotEvaluatedReason, c as Likelihood, i as ClassificationLabel, l as ModerationQualifier, n as ClassificationCategory, o as ClassificationQualifierResults, r as ClassificationCategoryReport, s as ClassificationReport, t as ClassificationCategories } from "./Classification-DJU_DfOO.js";
|
|
3
|
+
import { _ as ProcessingFeatureStage, a as CalmLensErrorDetails, c as ApiErrorCode, d as AgeRange, f as BoundingBox, g as ProcessingFeatureResults, h as ProcessingFeatureId, i as CalmLensErrorCode, l as FlaggedContentAction, m as DetectedPerson, n as CALMLENS_ERROR_CODES, o as CalmLensErrorOptions, p as DetectedFace, r as CalmLensError, s as SdkErrorCode, t as SDK_VERSION, u as FlaggedContentPolicy, v as ProcessingFeatures } from "./index-VxklV9OQ.js";
|
|
3
4
|
//#region src/client/CalmLensServerClient.d.ts
|
|
4
5
|
interface LensCache {
|
|
5
6
|
readonly ensuredLenses: Map<string, Lens>;
|
|
@@ -75,8 +76,8 @@ declare class CalmLensServerClient {
|
|
|
75
76
|
/** Lists one page of the project's assets, with optional filter and ordering. */
|
|
76
77
|
list: (options?: ListAssetsOptions) => Promise<AssetPage>;
|
|
77
78
|
/**
|
|
78
|
-
* Yields every asset matching `options`, fetching pages as needed.
|
|
79
|
-
*
|
|
79
|
+
* Yields every asset matching `options`, fetching pages as needed. The cursor keeps the position
|
|
80
|
+
* stable when other assets are inserted or deleted.
|
|
80
81
|
*/
|
|
81
82
|
iterate: (options?: IterateAssetsOptions) => AsyncGenerator<Asset, void, undefined>;
|
|
82
83
|
/** Retrieves an asset with its status and moderation report. */
|
|
@@ -201,11 +202,11 @@ export declare function verifyWebhookSignature(options: VerifyWebhookSignatureOp
|
|
|
201
202
|
/**
|
|
202
203
|
* Verifies a webhook delivery and parses its body. Throws `sdk/invalid-webhook-signature`
|
|
203
204
|
* when the signature or timestamp does not verify, and `sdk/invalid-webhook-payload` when a
|
|
204
|
-
* verified body is not a webhook event.
|
|
205
|
+
* verified body is not a webhook event. Unknown event types, fact values and fields remain available.
|
|
205
206
|
*
|
|
206
207
|
* Event types and fact keys added to CalmLens after this SDK version are returned as they are,
|
|
207
208
|
* so keep a default branch when you switch on `type`.
|
|
208
209
|
*/
|
|
209
|
-
export declare function parseWebhookEvent(options: VerifyWebhookSignatureOptions): Promise<
|
|
210
|
+
export declare function parseWebhookEvent(options: VerifyWebhookSignatureOptions): Promise<ReceivedWebhookEventPayload>;
|
|
210
211
|
//#endregion
|
|
211
|
-
export { type AgeRange, type ApiErrorCode, type Asset, type AssetChecksums, type AssetChildrenPage, type AssetContent, type AssetContentOptions, type AssetContentRemovalReason, type AssetContentStatus, type AssetModeration, type AssetModerationAction, type AssetModerationStatus, type AssetPage, type AssetProcessing, type AssetProcessingStatus, type AssetReviewerAction, type AssetSafetyHold, type AssetSafetyHoldReason, type AssetSearchMatchField, type AssetSearchQuery, type AssetSearchResponse, type AssetSearchResult, type AssetType, type AssetVisibility, type BoundingBox, CALMLENS_ERROR_CODES, type CalmLensAppClientOptions, CalmLensError, type CalmLensErrorCode, type CalmLensErrorDetails, type CalmLensErrorOptions, CalmLensServerClient, type CalmLensServerClientOptions, type CdnAssetUrlOptions, type CdnServeOptions, type CdnTransform, type ClassificationCategories, type ClassificationCategory, type ClassificationCategoryReport, type ClassificationLabel, type ClassificationNotEvaluatedReason, type ClassificationQualifierResults, type ClassificationReport, type ConnectionOptions, type CreateAssetSignedUrlOptions, type CreateFolderOptions, type CreateMultipartUploadPartOptions, type DeleteAssetContentOptions, type DeleteAssetOptions, type DetectedFace, type DetectedPerson, type EnsureLensOptions, type EnsureLensesOptions, type EventAsset, type EventCategory, type EventFact, type EventFactValues, type EventFacts, type EventSeverity, type EventType, type GetEventsResponse as EventsPage, type ExtractedText, type FlaggedContentAction, type FlaggedContentPolicy, type Folder, type FolderIdOptions, type IdempotencyOptions, type ImageData, type ImageTransform, type ImageTransformOptions, type IterateAssetChildrenOptions, type IterateAssetsOptions, type Lens, type LensTransform, type LensType, type Likelihood, type ListAssetChildrenOptions, type ListAssetsOptions, type ListEventsOptions, type MetadataItem, type ModerateTextOptions, type ModerationQualifier, type MoveAssetOptions, type MoveFolderOptions, type MultipartUploadOptions, type MultipartUploadPartOptions, type Order, type
|
|
212
|
+
export { type AgeRange, type ApiErrorCode, type Asset, type AssetChecksums, type AssetChildrenPage, type AssetContent, type AssetContentOptions, type AssetContentRemovalReason, type AssetContentStatus, type AssetModeration, type AssetModerationAction, type AssetModerationStatus, type AssetPage, type AssetProcessing, type AssetProcessingStatus, type AssetReviewerAction, type AssetSafetyHold, type AssetSafetyHoldReason, type AssetSearchMatchField, type AssetSearchQuery, type AssetSearchResponse, type AssetSearchResult, type AssetType, type AssetVisibility, type BoundingBox, CALMLENS_ERROR_CODES, type CalmLensAppClientOptions, CalmLensError, type CalmLensErrorCode, type CalmLensErrorDetails, type CalmLensErrorOptions, CalmLensServerClient, type CalmLensServerClientOptions, type CdnAssetUrlOptions, type CdnServeOptions, type CdnTransform, type ClassificationCategories, type ClassificationCategory, type ClassificationCategoryReport, type ClassificationLabel, type ClassificationNotEvaluatedReason, type ClassificationQualifierResults, type ClassificationReport, type ConnectionOptions, type CreateAssetSignedUrlOptions, type CreateFolderOptions, type CreateMultipartUploadPartOptions, type CursorPage, type DeleteAssetContentOptions, type DeleteAssetOptions, type DetectedFace, type DetectedPerson, type EnsureLensOptions, type EnsureLensesOptions, type EventAsset, type EventCategory, type EventFact, type EventFactValues, type EventFacts, type EventSeverity, type EventType, type GetEventsResponse as EventsPage, type ExtractedText, type FlaggedContentAction, type FlaggedContentPolicy, type Folder, type FolderIdOptions, type IdempotencyOptions, type ImageData, type ImageTransform, type ImageTransformOptions, type IterateAssetChildrenOptions, type IterateAssetsOptions, type Lens, type LensTransform, type LensType, type Likelihood, type ListAssetChildrenOptions, type ListAssetsOptions, type ListEventsOptions, type MetadataItem, type ModerateTextOptions, type ModerationQualifier, type MoveAssetOptions, type MoveFolderOptions, type MultipartUploadOptions, type MultipartUploadPartOptions, type Order, type PreviewImage, type ProcessingFeatureId, type ProcessingFeatureResults, type ProcessingFeatureStage, type ProcessingFeatures, type ProcessingOptions, type RequestOptions, type RetrieveAssetOptions, type RetryAssetOptions, SDK_VERSION, type SdkErrorCode, type SearchAssetsOptions, type SignUploadTokenOptions, type SignedUploadToken, type SignedUrl, type SubmitAssetOptions, type TypedEvent, type UpdateAssetOptions, type UpdateFolderOptions, type UploadAssetPartOptions, type UploadPresetSubmitAssetOptions, type UploadedAsset, type VerifyWebhookSignatureOptions, type WaitForAssetDecisionOptions, type ReceivedWebhookEventPayload as WebhookEventPayload, type WebhookHeadersInput, type WebhookPayloadInput };
|
package/esm/server.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { a as CALMLENS_ERROR_CODES, c as invalidArgument, i as isReactNativeRuntime, l as invalidConfig, o as CalmLensError, r as isBrowserRuntime, s as SDK_ERROR_CODES, t as SDK_VERSION } from "./CalmLensVersion-
|
|
1
|
+
import { a as CALMLENS_ERROR_CODES, c as invalidArgument, i as isReactNativeRuntime, l as invalidConfig, o as CalmLensError, r as isBrowserRuntime, s as SDK_ERROR_CODES, t as SDK_VERSION } from "./CalmLensVersion-CchG7NWy.js";
|
|
2
2
|
import "./index.js";
|
|
3
|
-
import { a as parseWebhookEvent, i as WEBHOOK_TIMESTAMP_HEADER, l as stringifyJsonCanonical, n as WEBHOOK_SIGNATURE_HEADER, o as verifyWebhookSignature, r as WEBHOOK_SIGNATURE_TOLERANCE_SECONDS, s as signUploadTokenWithApiKey, t as WEBHOOK_DELIVERY_HEADER } from "./CalmLensWebhooks-
|
|
4
|
-
import { f as sleep, l as validateRequestOptions, n as encodePathSegment, o as toTextAssetOptions, r as pollForDecision, s as transformSelector, t as appendCdnSelector, u as validateServerClientOptions } from "./CalmLensUtils-
|
|
5
|
-
import { a as newIdempotencyKey, i as invalidPayload, n as expectAsset, o as prepareSubmitAssetOptions, s as resolveConnectionOptions, t as CalmLensConnection } from "./CalmLensConnection-
|
|
3
|
+
import { a as parseWebhookEvent, i as WEBHOOK_TIMESTAMP_HEADER, l as stringifyJsonCanonical, n as WEBHOOK_SIGNATURE_HEADER, o as verifyWebhookSignature, r as WEBHOOK_SIGNATURE_TOLERANCE_SECONDS, s as signUploadTokenWithApiKey, t as WEBHOOK_DELIVERY_HEADER } from "./CalmLensWebhooks-B7nQMCHx.js";
|
|
4
|
+
import { f as sleep, l as validateRequestOptions, n as encodePathSegment, o as toTextAssetOptions, r as pollForDecision, s as transformSelector, t as appendCdnSelector, u as validateServerClientOptions } from "./CalmLensUtils-BDtpOfho.js";
|
|
5
|
+
import { a as newIdempotencyKey, i as invalidPayload, n as expectAsset, o as prepareSubmitAssetOptions, s as resolveConnectionOptions, t as CalmLensConnection } from "./CalmLensConnection-DYo5U2L0.js";
|
|
6
6
|
const getEnsureLensCacheKey = (options) => stringifyJsonCanonical({
|
|
7
7
|
identifier: options.identifier,
|
|
8
8
|
name: options.name,
|
|
@@ -167,33 +167,27 @@ sign: async (options) => {
|
|
|
167
167
|
/** Searches accessible assets by keyword or a natural-language description. */
|
|
168
168
|
search: async (options) => this.request("GET", `${this.projectPath}/assets/search`, { query: options }),
|
|
169
169
|
/** Lists one page of the project's assets, with optional filter and ordering. */
|
|
170
|
-
list: async (options = {}) => this.request("GET", `${this.projectPath}/assets/page`, { query:
|
|
171
|
-
...options,
|
|
172
|
-
pageIndex: options.pageIndex ?? 0
|
|
173
|
-
} }),
|
|
170
|
+
list: async (options = {}) => this.request("GET", `${this.projectPath}/assets/page`, { query: options }),
|
|
174
171
|
/**
|
|
175
|
-
* Yields every asset matching `options`, fetching pages as needed.
|
|
176
|
-
*
|
|
172
|
+
* Yields every asset matching `options`, fetching pages as needed. The cursor keeps the position
|
|
173
|
+
* stable when other assets are inserted or deleted.
|
|
177
174
|
*/
|
|
178
|
-
iterate: (options = {}) => this.iteratePages((
|
|
175
|
+
iterate: (options = {}) => this.iteratePages((cursor) => this.buildAssets().list({
|
|
179
176
|
...options,
|
|
180
|
-
|
|
177
|
+
cursor
|
|
181
178
|
})),
|
|
182
179
|
/** Retrieves an asset with its status and moderation report. */
|
|
183
180
|
retrieve: async ({ assetId }) => this.request("GET", `/assets/${requireId(assetId, "Asset ID")}`),
|
|
184
181
|
/** Updates an asset's editable fields. */
|
|
185
182
|
update: async ({ assetId, ...body }) => this.request("PATCH", `/assets/${requireId(assetId, "Asset ID")}`, { body }),
|
|
186
183
|
/** Lists one page of the assets extracted from a website or multimedia document. */
|
|
187
|
-
listChildren: async ({ assetId, ...options } = {}) => this.request("GET", `/assets/${requireId(assetId, "Asset ID")}/children`, { query:
|
|
188
|
-
...options,
|
|
189
|
-
pageIndex: options.pageIndex ?? 0
|
|
190
|
-
} }),
|
|
184
|
+
listChildren: async ({ assetId, ...options } = {}) => this.request("GET", `/assets/${requireId(assetId, "Asset ID")}/children`, { query: options }),
|
|
191
185
|
/** Yields every child of an asset, fetching pages as needed. */
|
|
192
186
|
iterateChildren: (options) => {
|
|
193
187
|
requireId(options?.assetId, "Asset ID");
|
|
194
|
-
return this.iteratePages((
|
|
188
|
+
return this.iteratePages((cursor) => this.buildAssets().listChildren({
|
|
195
189
|
...options,
|
|
196
|
-
|
|
190
|
+
cursor
|
|
197
191
|
}));
|
|
198
192
|
},
|
|
199
193
|
/**
|
|
@@ -290,10 +284,12 @@ sign: async (options) => {
|
|
|
290
284
|
}
|
|
291
285
|
}
|
|
292
286
|
async *iteratePages(listPage) {
|
|
293
|
-
|
|
294
|
-
|
|
287
|
+
let cursor;
|
|
288
|
+
for (;;) {
|
|
289
|
+
const page = await listPage(cursor);
|
|
295
290
|
yield* page.items;
|
|
296
|
-
if (!page.hasMore || page.items.length === 0) return;
|
|
291
|
+
if (!page.nextCursor || !page.hasMore || page.items.length === 0) return;
|
|
292
|
+
cursor = page.nextCursor;
|
|
297
293
|
}
|
|
298
294
|
}
|
|
299
295
|
get folders() {
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as detectTestImage, c as getImageTestCategories, d as paintTestImage, i as TestImageKeyCell, l as getTestImageKeyCells, n as TEST_IMAGE_PALETTES, o as detectTestTrigger, r as TEST_INPUT_KEY_PATTERN, s as generateTestTextCode, t as ClassificationTestSignal, u as getTestImageKeyColors } from "./TestTriggers-CxFZ-3uz.js";
|
|
2
|
+
export { type ClassificationTestSignal, TEST_IMAGE_PALETTES, TEST_INPUT_KEY_PATTERN, type TestImageKeyCell, detectTestImage, detectTestTrigger, generateTestTextCode, getImageTestCategories, getTestImageKeyCells, getTestImageKeyColors, paintTestImage };
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
//#region ../shared/src/TestTriggers.ts
|
|
2
|
+
const TEST_IMAGE_PALETTES = {
|
|
3
|
+
sexual: [
|
|
4
|
+
[
|
|
5
|
+
255,
|
|
6
|
+
20,
|
|
7
|
+
147,
|
|
8
|
+
255
|
|
9
|
+
],
|
|
10
|
+
[
|
|
11
|
+
255,
|
|
12
|
+
105,
|
|
13
|
+
180,
|
|
14
|
+
255
|
|
15
|
+
],
|
|
16
|
+
[
|
|
17
|
+
199,
|
|
18
|
+
21,
|
|
19
|
+
133,
|
|
20
|
+
255
|
|
21
|
+
],
|
|
22
|
+
[
|
|
23
|
+
255,
|
|
24
|
+
69,
|
|
25
|
+
0,
|
|
26
|
+
255
|
|
27
|
+
]
|
|
28
|
+
],
|
|
29
|
+
violence: [
|
|
30
|
+
[
|
|
31
|
+
139,
|
|
32
|
+
0,
|
|
33
|
+
0,
|
|
34
|
+
255
|
|
35
|
+
],
|
|
36
|
+
[
|
|
37
|
+
220,
|
|
38
|
+
20,
|
|
39
|
+
60,
|
|
40
|
+
255
|
|
41
|
+
],
|
|
42
|
+
[
|
|
43
|
+
178,
|
|
44
|
+
34,
|
|
45
|
+
34,
|
|
46
|
+
255
|
|
47
|
+
],
|
|
48
|
+
[
|
|
49
|
+
255,
|
|
50
|
+
0,
|
|
51
|
+
0,
|
|
52
|
+
255
|
|
53
|
+
]
|
|
54
|
+
],
|
|
55
|
+
harassment: [
|
|
56
|
+
[
|
|
57
|
+
180,
|
|
58
|
+
83,
|
|
59
|
+
9,
|
|
60
|
+
255
|
|
61
|
+
],
|
|
62
|
+
[
|
|
63
|
+
217,
|
|
64
|
+
119,
|
|
65
|
+
6,
|
|
66
|
+
255
|
|
67
|
+
],
|
|
68
|
+
[
|
|
69
|
+
245,
|
|
70
|
+
158,
|
|
71
|
+
11,
|
|
72
|
+
255
|
|
73
|
+
],
|
|
74
|
+
[
|
|
75
|
+
251,
|
|
76
|
+
191,
|
|
77
|
+
36,
|
|
78
|
+
255
|
|
79
|
+
]
|
|
80
|
+
],
|
|
81
|
+
hate: [
|
|
82
|
+
[
|
|
83
|
+
30,
|
|
84
|
+
64,
|
|
85
|
+
175,
|
|
86
|
+
255
|
|
87
|
+
],
|
|
88
|
+
[
|
|
89
|
+
37,
|
|
90
|
+
99,
|
|
91
|
+
235,
|
|
92
|
+
255
|
|
93
|
+
],
|
|
94
|
+
[
|
|
95
|
+
59,
|
|
96
|
+
130,
|
|
97
|
+
246,
|
|
98
|
+
255
|
|
99
|
+
],
|
|
100
|
+
[
|
|
101
|
+
96,
|
|
102
|
+
165,
|
|
103
|
+
250,
|
|
104
|
+
255
|
|
105
|
+
]
|
|
106
|
+
],
|
|
107
|
+
"criminal-activity": [
|
|
108
|
+
[
|
|
109
|
+
6,
|
|
110
|
+
95,
|
|
111
|
+
70,
|
|
112
|
+
255
|
|
113
|
+
],
|
|
114
|
+
[
|
|
115
|
+
5,
|
|
116
|
+
150,
|
|
117
|
+
105,
|
|
118
|
+
255
|
|
119
|
+
],
|
|
120
|
+
[
|
|
121
|
+
16,
|
|
122
|
+
185,
|
|
123
|
+
129,
|
|
124
|
+
255
|
|
125
|
+
],
|
|
126
|
+
[
|
|
127
|
+
52,
|
|
128
|
+
211,
|
|
129
|
+
153,
|
|
130
|
+
255
|
|
131
|
+
]
|
|
132
|
+
],
|
|
133
|
+
"self-harm": [
|
|
134
|
+
[
|
|
135
|
+
75,
|
|
136
|
+
0,
|
|
137
|
+
130,
|
|
138
|
+
255
|
|
139
|
+
],
|
|
140
|
+
[
|
|
141
|
+
138,
|
|
142
|
+
43,
|
|
143
|
+
226,
|
|
144
|
+
255
|
|
145
|
+
],
|
|
146
|
+
[
|
|
147
|
+
72,
|
|
148
|
+
61,
|
|
149
|
+
139,
|
|
150
|
+
255
|
|
151
|
+
],
|
|
152
|
+
[
|
|
153
|
+
147,
|
|
154
|
+
112,
|
|
155
|
+
219,
|
|
156
|
+
255
|
|
157
|
+
]
|
|
158
|
+
]
|
|
159
|
+
};
|
|
160
|
+
/** A project's test input key: eight hexadecimal characters only its members can see. */
|
|
161
|
+
const TEST_INPUT_KEY_PATTERN = /^[a-f0-9]{8}$/;
|
|
162
|
+
const TEXT_CODE_SIGNALS = [
|
|
163
|
+
"harassment",
|
|
164
|
+
"hate",
|
|
165
|
+
"criminal-activity",
|
|
166
|
+
"sexual.involving-minors"
|
|
167
|
+
];
|
|
168
|
+
/**
|
|
169
|
+
* The text code that CalmLens classifies as `category` for the project with this test input key.
|
|
170
|
+
* @returns The code, or an empty string for a category without a text code
|
|
171
|
+
*/
|
|
172
|
+
const generateTestTextCode = (category, testInputKey) => TEXT_CODE_SIGNALS.includes(category) ? `<!calmlens-test ${testInputKey} ${category}>` : "";
|
|
173
|
+
const TEST_TRIGGER_PATTERN = /<!calmlens-test\s+([a-f0-9]{8})\s+(harassment|hate|criminal-activity|sexual\.involving-minors)\s*>/gi;
|
|
174
|
+
/**
|
|
175
|
+
* The test signals in `text` whose codes carry the project's test input key. Codes with another
|
|
176
|
+
* key are ignored, so a code can only be used by the project it belongs to.
|
|
177
|
+
*/
|
|
178
|
+
const detectTestTrigger = (text, testInputKey) => {
|
|
179
|
+
const signals = [];
|
|
180
|
+
for (const [, key, signal] of text.matchAll(TEST_TRIGGER_PATTERN)) {
|
|
181
|
+
if (key.toLowerCase() !== testInputKey.toLowerCase()) continue;
|
|
182
|
+
const testSignal = signal.toLowerCase();
|
|
183
|
+
if (!signals.includes(testSignal)) signals.push(testSignal);
|
|
184
|
+
}
|
|
185
|
+
return {
|
|
186
|
+
isTestTrigger: signals.length > 0,
|
|
187
|
+
signals
|
|
188
|
+
};
|
|
189
|
+
};
|
|
190
|
+
/** Sixteen cells encode two bits each using the category's four existing colours. */
|
|
191
|
+
const getTestImageKeyCells = (width, height) => {
|
|
192
|
+
return Array.from({ length: 16 }, (_, index) => {
|
|
193
|
+
const column = index % 4;
|
|
194
|
+
const row = Math.floor(index / 4);
|
|
195
|
+
const x = Math.floor(column * width / 4);
|
|
196
|
+
const y = Math.floor(row * height / 4);
|
|
197
|
+
return {
|
|
198
|
+
x,
|
|
199
|
+
y,
|
|
200
|
+
width: Math.floor((column + 1) * width / 4) - x,
|
|
201
|
+
height: Math.floor((row + 1) * height / 4) - y
|
|
202
|
+
};
|
|
203
|
+
});
|
|
204
|
+
};
|
|
205
|
+
const getTestImageKeyColors = (signal, testInputKey) => {
|
|
206
|
+
const colors = TEST_IMAGE_PALETTES[signal];
|
|
207
|
+
if (!colors || !TEST_INPUT_KEY_PATTERN.test(testInputKey)) throw new Error("Invalid image test signal or key");
|
|
208
|
+
return [...testInputKey].flatMap((character) => {
|
|
209
|
+
const value = Number.parseInt(character, 16);
|
|
210
|
+
return [colors[value >> 2], colors[value & 3]];
|
|
211
|
+
});
|
|
212
|
+
};
|
|
213
|
+
/**
|
|
214
|
+
* Gets all test trigger categories that support images
|
|
215
|
+
*/
|
|
216
|
+
const getImageTestCategories = () => {
|
|
217
|
+
return Object.keys(TEST_IMAGE_PALETTES);
|
|
218
|
+
};
|
|
219
|
+
/** Paint a full-image 4×4 grid as RGBA pixels; callers choose their image encoder. */
|
|
220
|
+
const paintTestImage = (signal, testInputKey, width = 512, height = width) => {
|
|
221
|
+
if (!Number.isSafeInteger(width) || !Number.isSafeInteger(height) || width < 24 || height < 24) throw new RangeError("Test image dimensions must be integers of at least 24 pixels");
|
|
222
|
+
const colors = getTestImageKeyColors(signal, testInputKey);
|
|
223
|
+
const rgba = new Uint8Array(width * height * 4);
|
|
224
|
+
getTestImageKeyCells(width, height).forEach((cell, index) => {
|
|
225
|
+
for (let y = cell.y; y < cell.y + cell.height; y++) for (let x = cell.x; x < cell.x + cell.width; x++) rgba.set(colors[index], (y * width + x) * 4);
|
|
226
|
+
});
|
|
227
|
+
return rgba;
|
|
228
|
+
};
|
|
229
|
+
/** Decode the project key from pixels, tolerating resizing and lossy compression. */
|
|
230
|
+
const detectTestImage = (image, testInputKey) => {
|
|
231
|
+
const { width, height, rgba } = image;
|
|
232
|
+
if (!Number.isSafeInteger(width) || !Number.isSafeInteger(height) || width < 24 || height < 24 || rgba.length !== width * height * 4 || !TEST_INPUT_KEY_PATTERN.test(testInputKey)) return void 0;
|
|
233
|
+
const cells = getTestImageKeyCells(width, height);
|
|
234
|
+
for (const category of getImageTestCategories()) {
|
|
235
|
+
const colors = getTestImageKeyColors(category, testInputKey);
|
|
236
|
+
if (cells.every((cell, index) => {
|
|
237
|
+
const sample = [
|
|
238
|
+
0,
|
|
239
|
+
0,
|
|
240
|
+
0
|
|
241
|
+
];
|
|
242
|
+
let count = 0;
|
|
243
|
+
for (let y = cell.y + Math.ceil(cell.height / 4); y < cell.y + cell.height * 3 / 4; y++) for (let x = cell.x + Math.ceil(cell.width / 4); x < cell.x + cell.width * 3 / 4; x++) {
|
|
244
|
+
const offset = (y * width + x) * 4;
|
|
245
|
+
if (rgba[offset + 3] < 250) return false;
|
|
246
|
+
for (let c = 0; c < 3; c++) sample[c] += rgba[offset + c];
|
|
247
|
+
count++;
|
|
248
|
+
}
|
|
249
|
+
const distances = TEST_IMAGE_PALETTES[category].map((color) => sample.reduce((sum, value, c) => sum + (value / count - color[c]) ** 2, 0));
|
|
250
|
+
const nearest = distances.indexOf(Math.min(...distances));
|
|
251
|
+
return distances[nearest] <= 900 && TEST_IMAGE_PALETTES[category][nearest] === colors[index];
|
|
252
|
+
})) return category;
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
//#endregion
|
|
256
|
+
export { TEST_IMAGE_PALETTES, TEST_INPUT_KEY_PATTERN, detectTestImage, detectTestTrigger, generateTestTextCode, getImageTestCategories, getTestImageKeyCells, getTestImageKeyColors, paintTestImage };
|
package/esm/testing.d.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
|
|
3
|
-
type ClassificationTestSignal = ClassificationCategory | "sexual.involving-minors" | "violence.graphic";
|
|
4
|
-
//#endregion
|
|
1
|
+
import { $ as SearchAssetsOptions, A as DeleteAssetContentOptions, B as Lens, C as CdnAssetUrlOptions, D as CreateAssetSignedUrlOptions, G as ModerateTextOptions, H as ListAssetChildrenOptions, K as MoveAssetOptions, M as EnsureLensOptions, N as EnsureLensesOptions, O as CreateFolderOptions, P as FolderIdOptions, Q as RetryAssetOptions, R as IterateAssetChildrenOptions, S as CalmLensServerClientOptions, Tt as Folder, U as ListAssetsOptions, W as ListEventsOptions, Z as RetrieveAssetOptions, _ as AssetSearchResponse, _t as TypedEvent, a as AssetChildrenPage, at as UpdateFolderOptions, et as SignUploadTokenOptions, ht as Event, it as UpdateAssetOptions, j as DeleteAssetOptions, jt as AssetBinaryPayloadInput, mt as PostAssetSignedUrlResponse, n as WebhookEventPayload, ot as UploadAssetPartOptions, p as AssetPage, pt as GetEventsResponse, q as MoveFolderOptions, r as Asset, rt as SubmitAssetOptions, tt as SignedUploadToken, ut as WaitForAssetDecisionOptions, w as CdnServeOptions, wt as PermissionGrant, z as IterateAssetsOptions } from "./WebhookPayload-BfUmVu2y.js";
|
|
2
|
+
import { t as ClassificationTestSignal } from "./TestTriggers-CxFZ-3uz.js";
|
|
5
3
|
//#region ../shared/src/MediaTestTriggers.d.ts
|
|
6
4
|
export declare const MEDIA_TEST_SIGNALS: readonly ["sexual", "violence", "self-harm", "harassment", "hate", "criminal-activity", "violence.graphic"];
|
|
7
5
|
/** Read this aloud, or render it as large, high-contrast text in a video frame. */
|
|
8
|
-
export declare function generateMediaTestCode(signal: ClassificationTestSignal,
|
|
6
|
+
export declare function generateMediaTestCode(signal: ClassificationTestSignal, testInputKey: string): string;
|
|
9
7
|
//#endregion
|
|
10
8
|
//#region src/testing/MockApiKey.d.ts
|
|
11
9
|
export declare const MOCK_API_KEY_PREFIX = "sk_test_";
|