calmlens 0.28.0 → 0.28.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f85c3f503981a9430e9032ae390a3f6a93fc3ea3cd25e6dc55b431778f655a5
4
- data.tar.gz: 4bbafa1e0d09344f9617f79f4bb4617717c569d3aa8d9dbec72261b10bab727c
3
+ metadata.gz: ed13745181799826c0582373ed37891d5629adcca5e41286fdd3472b2d3e77a2
4
+ data.tar.gz: 166a77b10c5dad3f0409ae8dda170914d12cf48226e6433255ceac16d5d252e1
5
5
  SHA512:
6
- metadata.gz: 7ee8f7cbc21318a692173523cbce471fccd27927cf504871f8b7fc00747c4bafd99d64e8e4c189af0739bc65f9f564855c09e10d135bb7af101abfcb1fb6dd75
7
- data.tar.gz: bc87dccf6bc1e39428cc8b8dd1363e6a773a8f58428db114846ad54fc3d0431c7c9ac6005576437b1e08bec3c5e95baa4cf1c86218822413014f33c6b03d954d
6
+ metadata.gz: 3ada38d78d5b012a686d7083767c7ebe21347881bdaae2c1c07180781b95e018cbd414d0202c96aa659d682ae133fe43d99efc5a154247fc3ead85fb7ae46c54
7
+ data.tar.gz: 53f5091984ab2f4e81f773a67078167b29cb4fb8163be2c279b7735e90a22034f303ed12988583dc4bdc58d9d28f06feafc5549073aa3a98a1abab7f475e342a
@@ -7,6 +7,7 @@ require 'uri'
7
7
  require_relative 'placeholder'
8
8
  require_relative 'mock_decision'
9
9
  require_relative 'rsql'
10
+ require_relative 'url_asset_types'
10
11
 
11
12
  module CalmLens
12
13
  module Testing
@@ -828,7 +829,7 @@ module CalmLens
828
829
  end
829
830
 
830
831
  def kind(mime, url)
831
- return 'website' if url
832
+ return url_asset_type(url) if url
832
833
  return mime.split('/').first if mime.start_with?('image/', 'video/', 'audio/')
833
834
  return 'plaintext-document' if mime.start_with?('text/')
834
835
  return 'multimedia-document' if mime.include?('pdf') || mime.include?('document')
@@ -836,6 +837,20 @@ module CalmLens
836
837
  'file'
837
838
  end
838
839
 
840
+ # A URL upload's type: the type of its path's file extension ({MOCK_URL_EXTENSION_TYPES}),
841
+ # compared lower-case without the query or fragment, or `website` for any other extension or
842
+ # none. The mock fetches nothing, so the extension stands in for the fetched content's type.
843
+ def url_asset_type(url)
844
+ path = begin
845
+ URI.parse(url.to_s).path.to_s
846
+ rescue URI::InvalidURIError
847
+ url.to_s.split(/[?#]/, 2).first.to_s
848
+ end
849
+ segment = path.split('/', -1).last.to_s
850
+ dot = segment.rindex('.')
851
+ dot ? MOCK_URL_EXTENSION_TYPES.fetch(segment[(dot + 1)..].downcase, 'website') : 'website'
852
+ end
853
+
839
854
  def create_asset(options, queue, url: nil, data: nil, open: false)
840
855
  check_upload(options)
841
856
  check_folder(options['folderId']) if options['folderId']
@@ -1082,8 +1097,11 @@ module CalmLens
1082
1097
 
1083
1098
  # Applies `decision` to `asset` with its report. The mock reads nothing in an image, so a
1084
1099
  # decided image reports what the decision supplies ({MockDecision#with_ocr},
1085
- # {MockDecision#with_link_detection}) and no people or faces, for the features its upload ran:
1086
- # OCR and person and face detection when turned on, link detection unless turned off.
1100
+ # {MockDecision#with_link_detection}, {MockDecision#with_person_detection},
1101
+ # {MockDecision#with_face_detection}), and no people or faces without them, for the features
1102
+ # its upload ran: OCR and person and face detection when turned on, link detection unless
1103
+ # turned off. Like the API, a face has its `ageRange` only when the upload asked for age
1104
+ # estimation.
1087
1105
  def decided(asset, decision)
1088
1106
  apply_outcome(asset, decision.status, 'policy', decision.report(@now.call))
1089
1107
  classification = asset['classification']
@@ -1102,8 +1120,13 @@ module CalmLens
1102
1120
  unless setting.call('linkDetection') == false
1103
1121
  classification['linkDetection'] = { 'status' => 'evaluated' }.merge(decision.link_findings || { 'qrCodes' => [], 'links' => [] })
1104
1122
  end
1105
- { 'personDetection' => 'people', 'faceDetection' => 'faces' }.each do |feature, list|
1106
- classification[feature] = { 'status' => 'evaluated', list => [] } if setting.call(feature) == true
1123
+ if setting.call('personDetection') == true
1124
+ classification['personDetection'] = { 'status' => 'evaluated', 'people' => decision.person_findings || [] }
1125
+ end
1126
+ if setting.call('faceDetection') == true
1127
+ ages = features['faceDetection']['ageEstimation'] == true
1128
+ faces = (decision.face_findings || []).map { |face| ages ? face : face.except('ageRange') }
1129
+ classification['faceDetection'] = { 'status' => 'evaluated', 'faces' => faces }
1107
1130
  end
1108
1131
  asset
1109
1132
  end
@@ -134,6 +134,40 @@ module CalmLens
134
134
  self
135
135
  end
136
136
 
137
+ # The people that person detection finds in an image (each `{ 'box' => { 'left', 'top', 'width',
138
+ # 'height' }, 'confidence' }`, as fractions from 0 to 1), reported as
139
+ # `classification.personDetection` when the upload turns person detection on. Without them, the
140
+ # mock finds nobody.
141
+ # @param people [Array<Hash>]
142
+ # @return [self]
143
+ def with_person_detection(people)
144
+ raise Internal.invalid('people must be an Array') unless people.is_a?(Array)
145
+
146
+ @people = MockDecision.json_copy(people)
147
+ self
148
+ end
149
+
150
+ # The faces that face detection finds in an image (each `{ 'box', 'confidence' }` with an optional
151
+ # `'ageRange' => { 'low', 'high' }`), reported as `classification.faceDetection` when the upload
152
+ # turns face detection on; `ageRange` only when the upload also asks for age estimation. Without
153
+ # them, the mock finds no faces.
154
+ # @param faces [Array<Hash>]
155
+ # @return [self]
156
+ def with_face_detection(faces)
157
+ raise Internal.invalid('faces must be an Array') unless faces.is_a?(Array)
158
+
159
+ @faces = MockDecision.json_copy(faces)
160
+ self
161
+ end
162
+
163
+ # What {#with_person_detection} set, or nil.
164
+ # @api private
165
+ def person_findings = @people && MockDecision.json_copy(@people)
166
+
167
+ # What {#with_face_detection} set, or nil.
168
+ # @api private
169
+ def face_findings = @faces && MockDecision.json_copy(@faces)
170
+
137
171
  # What {#with_ocr} set, or nil.
138
172
  # @api private
139
173
  def ocr_findings = @ocr && MockDecision.json_copy(@ocr)
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Generated by packages/sdk-contract/generate.ts from packages/sdk-contract/mockUrlAssetTypes.ts; do not edit.
4
+ # The asset type a mock gives a URL upload: the type of the URL path's file extension (the text
5
+ # after the last dot of its last segment, compared lower-case, without the query or fragment), or
6
+ # website for any other extension or none.
7
+
8
+ module CalmLens
9
+ module Testing
10
+ MOCK_URL_EXTENSION_TYPES = {
11
+ 'jpg' => 'image',
12
+ 'jpeg' => 'image',
13
+ 'png' => 'image',
14
+ 'gif' => 'image',
15
+ 'webp' => 'image',
16
+ 'avif' => 'image',
17
+ 'heic' => 'image',
18
+ 'heif' => 'image',
19
+ 'bmp' => 'image',
20
+ 'tif' => 'image',
21
+ 'tiff' => 'image',
22
+ 'svg' => 'image',
23
+ 'mp4' => 'video',
24
+ 'm4v' => 'video',
25
+ 'mov' => 'video',
26
+ 'webm' => 'video',
27
+ 'mkv' => 'video',
28
+ 'avi' => 'video',
29
+ 'mp3' => 'audio',
30
+ 'm4a' => 'audio',
31
+ 'aac' => 'audio',
32
+ 'wav' => 'audio',
33
+ 'ogg' => 'audio',
34
+ 'oga' => 'audio',
35
+ 'opus' => 'audio',
36
+ 'flac' => 'audio',
37
+ 'pdf' => 'multimedia-document',
38
+ 'doc' => 'multimedia-document',
39
+ 'docx' => 'multimedia-document',
40
+ 'odt' => 'multimedia-document',
41
+ 'ppt' => 'multimedia-document',
42
+ 'pptx' => 'multimedia-document',
43
+ 'odp' => 'multimedia-document',
44
+ 'rtf' => 'multimedia-document',
45
+ 'txt' => 'plaintext-document',
46
+ 'md' => 'plaintext-document'
47
+ }.freeze
48
+ end
49
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module CalmLens
4
4
  # The gem version. The gemspec and the User-Agent header read it from here.
5
- VERSION = '0.28.0'
5
+ VERSION = '0.28.2'
6
6
  end
data/sig/calmlens.rbs CHANGED
@@ -553,6 +553,13 @@ module CalmLens
553
553
  def with_link_detection: (?Array[Hash[String | Symbol, untyped]] qr_codes, ?Array[Hash[String | Symbol, untyped]] links) -> self
554
554
  def ocr_findings: () -> Hash[String, untyped]?
555
555
  def link_findings: () -> Hash[String, untyped]?
556
+ # The people that person detection finds in an image (`classification.personDetection`).
557
+ def with_person_detection: (Array[Hash[String | Symbol, untyped]] people) -> self
558
+ # The faces that face detection finds in an image (`classification.faceDetection`); `ageRange`
559
+ # only when the upload asks for age estimation.
560
+ def with_face_detection: (Array[Hash[String | Symbol, untyped]] faces) -> self
561
+ def person_findings: () -> Array[Hash[String, untyped]]?
562
+ def face_findings: () -> Array[Hash[String, untyped]]?
556
563
  def self.json_copy: (untyped value) -> untyped
557
564
  # The `categories`, `score` and `policy` a decided asset gets; nil for `pending` and `failed`.
558
565
  # `requested_at` is when a pending review joined the queue, in epoch milliseconds.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: calmlens
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.28.0
4
+ version: 0.28.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - CalmLens
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-11-26 00:00:00.000000000 Z
11
+ date: 2026-11-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: 'Server-side client for the CalmLens API: moderation, uploads, events,
14
14
  webhooks and CDN delivery.'
@@ -50,6 +50,7 @@ files:
50
50
  - lib/calmlens/testing/test_input_detections.rb
51
51
  - lib/calmlens/testing/test_input_scenario.rb
52
52
  - lib/calmlens/testing/test_inputs.rb
53
+ - lib/calmlens/testing/url_asset_types.rb
53
54
  - lib/calmlens/text.rb
54
55
  - lib/calmlens/transform_rules.rb
55
56
  - lib/calmlens/transform_schema.rb