calmlens 0.31.0 → 0.32.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 45077d27cc23f4fbfbae7a056b96b6ce575a5d0ba2e306ff0d96daacb9406dd9
4
- data.tar.gz: 321e112bc8d3efab4dd12e9c32c7118335c5759442a2a20883677fbc77ee779a
3
+ metadata.gz: a9c9bdd909c33d7c663c778452b7c0972dcf2cdb9d440ac992e5ff85547cf721
4
+ data.tar.gz: 7c876fa95569e523d51b71abdb9dbe05a52b745765ba5cba4169820ac6406208
5
5
  SHA512:
6
- metadata.gz: 3f9cb8b271474880af0d0e54853a935faac758ac167d38109cc16fb2910c3fc7a376217d3764b832991eab19d0c86a0c80a199baa48911ef5dc8791ba97bdc8a
7
- data.tar.gz: b7e71f082a6bbe59529f2c49bf46b0a02aae43316b2bf390801e4a791e72272dc31627d0289c4ad6f3550c396f6703aa22043a4b09a1d9e1e7178c80f50d647a
6
+ metadata.gz: e44c83c5d880129a7e5d25119a6b2aae0d4516d74145f43bf1ada33cea8956614e6cb06e9c0f38cda0786e6297bf3620571ecae0bc36853837603f5029016fd1
7
+ data.tar.gz: 35741ca38d293e7fba7e4d148a34ca7e6164194826151cd989954c5a479779f3c6b7a90577e72d1faf776b115c49f570f38c7fca5e2ad29bf8bcfaf5c4edcbb1
@@ -19,14 +19,18 @@ module CalmLens
19
19
  # The asset fields an upload carries in its body: the JSON body for text, the `options` part of
20
20
  # an upload form for files. They never go in the URL, which proxies and servers log, and the
21
21
  # API refuses them there.
22
- UPLOAD_OPTION_KEYS = %w[name description processingOptions visibility metadata tags authorId context externalId
23
- externalUrl folderId uploadPresetId].freeze
22
+ UPLOAD_OPTION_KEYS = %w[name processingOptions visibility metadata tags authorId context externalId externalUrl
23
+ folderId uploadPresetId].freeze
24
24
  MAX_MULTIPART_IMAGE_BYTES = 20 * 1024 * 1024
25
25
  # The API's limits for one-request uploads: images up to 10 MiB (larger ones are uploaded in
26
26
  # parts), audio and video up to 50 MiB and other files up to 5,000 MiB.
27
27
  MAX_DIRECT_IMAGE_BYTES = 10 * 1024 * 1024
28
28
  MAX_MEDIA_BYTES = 50 * 1024 * 1024
29
29
  MAX_FILE_BYTES = 5000 * 1024 * 1024
30
+ # However they are sent, PDFs can be up to 2,000 MiB and other documents (Word, spreadsheets,
31
+ # presentations, OpenDocument and RTF) up to 50 MiB.
32
+ MAX_PDF_BYTES = 2000 * 1024 * 1024
33
+ MAX_OTHER_DOCUMENT_BYTES = 50 * 1024 * 1024
30
34
  # Audio and video sent in parts can be up to 2 GiB; the API holds free uploads, made before
31
35
  # billing is set up, to MAX_MEDIA_BYTES itself.
32
36
  MAX_LONG_MEDIA_BYTES = 2 * 1024 * 1024 * 1024
@@ -50,7 +54,7 @@ module CalmLens
50
54
  # @option options [String] :query
51
55
  # @option options [String] :mode `hybrid`, `semantic` or `keyword`
52
56
  # @option options [Integer] :page_size how many results, 1 to 20 (default 10)
53
- # @return [AssetSearchResult] `query`, `items` (each with `asset`, `score` and `matched_fields`) and
57
+ # @return [AssetSearchResult] enumerable over its `items` (each with `asset`, `score` and `matched_fields`), with `query` and
54
58
  # `semantic_status`
55
59
  def search(**options)
56
60
  call(options, __method__) do |api, request|
@@ -143,7 +147,7 @@ module CalmLens
143
147
  end
144
148
  end
145
149
 
146
- # Updates an asset's name, description, tags, visibility, metadata and similar fields.
150
+ # Updates an asset's name, tags, visibility, metadata and similar fields.
147
151
  # @param asset_id [String]
148
152
  # @return [Asset] the updated asset
149
153
  def update(asset_id, **options)
@@ -264,7 +268,7 @@ module CalmLens
264
268
  # memory; pass `size_in_bytes:` when its length is unknown (a pipe or socket).
265
269
  #
266
270
  # Text is sent as a JSON body. Other content is sent as `multipart/form-data`: the asset's fields
267
- # (name, description, metadata, author ID, context and so on) in its `options` part, then the
271
+ # (name, metadata, author ID, context and so on) in its `options` part, then the
268
272
  # file. The URL carries only transport values (`wait`, the content type and sizes), never the
269
273
  # asset's fields.
270
274
  #
@@ -546,12 +550,16 @@ module CalmLens
546
550
  end
547
551
 
548
552
  # Refuses content whose known size is over the API's limit for its type, before any of it is
549
- # sent: `in_parts` selects the limits for content sent in parts. Images in parts are checked by
550
- # {#check_image_size}.
553
+ # sent: `in_parts` selects the limits for content sent in parts. `mime` is normalized
554
+ # ({#check_mime}). Images in parts are checked by {#check_image_size}.
551
555
  def check_upload_size(mime, size, in_parts: false)
552
556
  return if size.nil?
553
557
 
554
- limit, message = if mime.start_with?('image/')
558
+ limit, message = if mime == 'application/pdf'
559
+ [MAX_PDF_BYTES, 'PDFs can be at most 2,000 MiB']
560
+ elsif Internal::UPLOAD_MIME_DOCUMENTS.include?(mime)
561
+ [MAX_OTHER_DOCUMENT_BYTES, 'Documents other than PDFs can be at most 50 MiB']
562
+ elsif mime.start_with?('image/')
555
563
  [MAX_DIRECT_IMAGE_BYTES, 'Images uploaded in one request can be at most 10 MiB; upload larger images in parts']
556
564
  elsif mime.start_with?('audio/', 'video/')
557
565
  [in_parts ? MAX_LONG_MEDIA_BYTES : MAX_MEDIA_BYTES,
data/lib/calmlens/cdn.rb CHANGED
@@ -42,9 +42,9 @@ module CalmLens
42
42
  TG TH TJ TK TL TM TN TO TR TT TV TW TZ UA UG UM US UY UZ VA VC VE VG VI VN VU WF WS YE YT ZA ZM ZW
43
43
  ].freeze
44
44
 
45
- # Builds an asset's CDN URL without a request: the asset URL, which every resource is a path
46
- # beneath, or a resource URL when `resource` is given, with its lens or transform and the viewer
47
- # claims. Use it for public assets; private ones need {#sign_asset_url} (or the API key, through
45
+ # Builds an asset's CDN URL without a request: the URL of `resource` (`rendered` unless one is
46
+ # given) beneath the asset URL, with its lens or transform and the viewer claims, ready to fetch.
47
+ # Use it for public assets; private ones need {#sign_asset_url} (or the API key, through
48
48
  # {#serve}).
49
49
  # @option options [String] :asset_id the asset ID; give it or `external_id`, not both
50
50
  # @option options [String] :external_id the external ID the asset was uploaded with, written as
@@ -56,10 +56,9 @@ module CalmLens
56
56
  # once `content.hls.status` is `ready`), `embed` (an HTML page that shows the asset, a viewer for its type, for an
57
57
  # iframe), `placeholder` (a small blurred PNG, without age confirmation; private or blocked assets
58
58
  # require a signed URL or download permission) or `info` (the asset's display info, as
59
- # {#get_asset_info} reads it). Without it, the URL is the asset URL itself. Lenses and transforms
60
- # apply to `preview`, and to `rendered` when it is an image; the CDN refuses them on rendered PDFs,
61
- # video and audio with `transform/invalid`, and the SDK refuses them on the other resources and
62
- # without a resource.
59
+ # {#get_asset_info} reads it); `rendered` by default. Lenses and transforms apply to `preview`, and
60
+ # to `rendered` when it is an image; the CDN refuses them on rendered PDFs, video and audio with
61
+ # `transform/invalid`, and the SDK refuses them on the other resources.
63
62
  # @option options [String] :lens a lens identifier
64
63
  # @option options [String, Hash] :transform options applied in one pass: a selector such as
65
64
  # `width=200,fit=cover`, or structured options such as `{width: 200, fit: 'cover'}`. With a lens,
@@ -76,15 +75,16 @@ module CalmLens
76
75
  end
77
76
 
78
77
  # Signs a private asset's URL on your server, so browsers and apps can load it without an API key
79
- # until it expires. With `resource`, it is signed for that resource and ends in it; only a URL
80
- # signed for `original` serves the exact upload, and any other serves every other resource beneath
78
+ # until it expires. It is signed for `resource` (`rendered` unless one is given) and ends in it;
79
+ # only a URL signed for `original` serves the exact upload, and any other serves every other resource beneath
81
80
  # its grant. Lenses, transforms and viewer claims are appended as {#get_asset_url} appends them and
82
81
  # aren't part of the signature.
83
82
  # @option options [String] :asset_id give it or `external_id`, not both
84
83
  # @option options [String] :external_id
85
84
  # @option options [String] :project_id the client's by default
86
85
  # @option options [Integer] :expires_in whole seconds from 1 to 86400; 900 by default
87
- # @option options [String] :resource the resource the URL is signed for and ends in; see {#get_asset_url}
86
+ # @option options [String] :resource the resource the URL is signed for and ends in, `rendered` by
87
+ # default; see {#get_asset_url}
88
88
  # @option options [String] :lens
89
89
  # @option options [String, Hash] :transform
90
90
  # @option options [Hash] :viewer_claims
@@ -95,7 +95,7 @@ module CalmLens
95
95
  project = Internal.segment(api.fetch('projectId', @session.project_id))
96
96
  body = api.slice('assetId', 'externalId')
97
97
  body['expiresIn'] = api.fetch('expiresIn', DEFAULT_SIGNED_URL_EXPIRES_IN)
98
- body['resource'] = api['resource'] if api.key?('resource')
98
+ body['resource'] = api.fetch('resource', 'rendered')
99
99
  signed = request('POST', "/projects/#{project}/signed-asset-urls", body: body, request_options: request)
100
100
  unless signed.is_a?(Hash) && signed['url'].is_a?(String) && !signed['url'].empty? && signed['expiresAt'].is_a?(Integer)
101
101
  raise InvalidResponseError.new(SdkErrorCodes::INVALID_RESPONSE, 'The API returned no signed asset URL')
@@ -135,7 +135,7 @@ module CalmLens
135
135
  # @option options [String] :asset_id see {#get_asset_url}
136
136
  # @option options [String] :external_id
137
137
  # @option options [String] :project_id
138
- # @option options [String] :resource `rendered` by default
138
+ # @option options [String] :resource see {#get_asset_url}; `rendered` by default
139
139
  # @option options [String] :lens
140
140
  # @option options [String, Hash] :transform
141
141
  # @option options [Hash] :viewer_claims see {#get_asset_url}
@@ -157,7 +157,7 @@ module CalmLens
157
157
  verb = init.fetch('method', 'GET').to_s.upcase
158
158
  raise Internal.invalid('init.method must be GET or HEAD') unless %w[GET HEAD].include?(verb)
159
159
 
160
- [verb, asset_url({ 'resource' => 'rendered' }.merge(api)), Internal.headers(init.fetch('headers', {})), request_options]
160
+ [verb, asset_url(api), Internal.headers(init.fetch('headers', {})), request_options]
161
161
  end
162
162
  @session.cdn(method, url, headers, request, &)
163
163
  end
@@ -180,32 +180,27 @@ module CalmLens
180
180
  EXTERNAL_ID_PREFIX + Internal.component(external)
181
181
  end
182
182
 
183
- # Appends a resource, its `@lens` and transform selector, and the viewer claims to an asset URL
184
- # (public or signed). Without a resource the URL stays the asset URL, which takes no selector.
183
+ # Appends a resource (`rendered` unless one is given), its `@lens` and transform selector, and the
184
+ # viewer claims to an asset URL (public or signed).
185
185
  def append_location(url, api)
186
- resource = api['resource']
187
- selected = !api['lens'].nil? || !api['transform'].nil?
188
- if resource.nil?
189
- raise Internal.invalid('A lens or transform needs a resource, such as rendered') if selected
190
- else
191
- raise Internal.invalid("resource must be one of #{RESOURCES.join(', ')}") unless RESOURCE_PATHS.key?(resource)
192
- if Internal::UNSELECTABLE_CDN_RESOURCES.include?(resource) && selected
193
- raise Internal.invalid("The #{resource} resource takes no lens or transform")
194
- end
195
-
196
- url = "#{url}/#{RESOURCE_PATHS.fetch(resource)}"
197
- transform = api['transform']
198
- selector = [("@#{Internal.segment(api['lens'])}" if api['lens']),
199
- (Transforms.path(transform) unless transform.nil? || transform == '')].compact.join(',')
200
- url += "/#{selector}" unless selector.empty?
186
+ resource = api.fetch('resource', 'rendered')
187
+ raise Internal.invalid("resource must be one of #{RESOURCES.join(', ')}") unless RESOURCE_PATHS.key?(resource)
188
+ if Internal::UNSELECTABLE_CDN_RESOURCES.include?(resource) && (!api['lens'].nil? || !api['transform'].nil?)
189
+ raise Internal.invalid("The #{resource} resource takes no lens or transform")
201
190
  end
191
+
192
+ url = "#{url}/#{RESOURCE_PATHS.fetch(resource)}"
193
+ transform = api['transform']
194
+ selector = [("@#{Internal.segment(api['lens'])}" if api['lens']),
195
+ (Transforms.path(transform) unless transform.nil? || transform == '')].compact.join(',')
196
+ url += "/#{selector}" unless selector.empty?
202
197
  "#{url}#{viewer_claims_query(api['viewerClaims'])}"
203
198
  end
204
199
 
205
- # The lens, transform and viewer claims added to a URL the API signed for `api['resource']`,
206
- # which already ends in that resource.
200
+ # The lens, transform and viewer claims added to a URL the API signed for `api['resource']`
201
+ # (`rendered` unless one is given), which already ends in that resource.
207
202
  def append_signed_location(url, api)
208
- resource_path = api['resource'] ? "/#{RESOURCE_PATHS.fetch(api['resource'])}" : ''
203
+ resource_path = "/#{RESOURCE_PATHS.fetch(api.fetch('resource', 'rendered'))}"
209
204
  unless url.end_with?(resource_path)
210
205
  raise InvalidResponseError.new(SdkErrorCodes::INVALID_RESPONSE,
211
206
  "The signed asset URL doesn't end in the resource it was signed for")
@@ -112,7 +112,7 @@ module CalmLens
112
112
 
113
113
  # The value of a field, as Hash#fetch reads one: a field the API didn't send returns the block's
114
114
  # value or `default`, or raises KeyError. A field sent as null returns nil.
115
- # asset.fetch(:description, '') # => '' when the API sent no description
115
+ # asset.fetch(:external_id, '') # => '' when the API sent no external ID
116
116
  def fetch(key, *default)
117
117
  raise ArgumentError, "wrong number of arguments (given #{default.size + 1}, expected 1..2)" if default.size > 1
118
118
 
@@ -159,13 +159,41 @@ module CalmLens
159
159
  def name_of(key) = key.is_a?(Symbol) && @values.key?(key) ? key : Model.field_name(key).to_sym
160
160
  end
161
161
 
162
+ # A result that holds a list of `items`, such as {Assets#search}'s. Enumerating it yields the items.
163
+ #
164
+ # client.assets.search(query: 'red bicycle').map { |item| [item.asset.id, item.score] }
165
+ class ItemList < Model
166
+ include Enumerable
167
+
168
+ # The result in the API's JSON form, as for any model (not Enumerable#to_h).
169
+ def to_h = Model.instance_method(:to_h).bind_call(self)
170
+
171
+ # Yields each item.
172
+ def each(&)
173
+ return enum_for(:each) unless block_given?
174
+
175
+ items_list.each(&)
176
+ self
177
+ end
178
+
179
+ # Whether there are no items.
180
+ def empty? = items_list.empty?
181
+
182
+ private
183
+
184
+ def items_list
185
+ value = self[:items]
186
+ raise InvalidResponseError.new(SdkErrorCodes::INVALID_RESPONSE, "#{self.class} has no items") unless value.is_a?(Array)
187
+
188
+ value
189
+ end
190
+ end
191
+
162
192
  # One page of a list, such as {Assets#list}'s. Enumerating it yields this page's items;
163
193
  # {#auto_paging_each} fetches the following pages as it goes, with the same options.
164
194
  #
165
195
  # client.assets.list(page_size: 100).auto_paging_each { |asset| index(asset) }
166
- class Page < Model
167
- include Enumerable
168
-
196
+ class Page < ItemList
169
197
  # @api private
170
198
  # @param fetch [Proc, nil] fetches the page after a cursor, with the options of this one
171
199
  # @param cursor [String, nil] the cursor this page was fetched with
@@ -175,24 +203,10 @@ module CalmLens
175
203
  super(values, last_response: last_response)
176
204
  end
177
205
 
178
- # The page in the API's JSON form, as for any model (not Enumerable#to_h).
179
- def to_h = Model.instance_method(:to_h).bind_call(self)
180
-
181
- # Yields each item on this page; fetches no more pages.
182
- def each(&)
183
- return enum_for(:each) unless block_given?
184
-
185
- page_items.each(&)
186
- self
187
- end
188
-
189
- # Whether this page has no items.
190
- def empty? = page_items.empty?
191
-
192
206
  # Whether there is a page after this one.
193
207
  def next_page?
194
208
  cursor = self[:next_cursor]
195
- self[:has_more] == true && cursor.is_a?(String) && !cursor.empty? && !page_items.empty?
209
+ self[:has_more] == true && cursor.is_a?(String) && !cursor.empty? && !empty?
196
210
  end
197
211
 
198
212
  # The page after this one, fetched with this page's options; an empty page when there is none.
@@ -235,14 +249,5 @@ module CalmLens
235
249
 
236
250
  each_page { |page| page.each(&block) }
237
251
  end
238
-
239
- private
240
-
241
- def page_items
242
- value = self[:items]
243
- raise InvalidResponseError.new(SdkErrorCodes::INVALID_RESPONSE, "#{self.class} has no items") unless value.is_a?(Array)
244
-
245
- value
246
- end
247
252
  end
248
253
  end
@@ -6,7 +6,7 @@ module CalmLens
6
6
  class AssetBatch < Model; end
7
7
  class AssetPage < Page; end
8
8
  class AssetReviewRequest < Model; end
9
- class AssetSearchResult < Model; end
9
+ class AssetSearchResult < ItemList; end
10
10
  class AssetTimelinePage < Page; end
11
11
  class CategoryPolicyScore < Model; end
12
12
  class CategoryPolicySettings < Model; end
@@ -97,7 +97,6 @@ module CalmLens
97
97
  updated_at: ["updatedAt", nil],
98
98
  type: ["type", nil],
99
99
  name: ["name", nil],
100
- description: ["description", nil],
101
100
  external_id: ["externalId", nil],
102
101
  external_url: ["externalUrl", nil],
103
102
  author_id: ["authorId", nil],
@@ -8,12 +8,12 @@ module CalmLens
8
8
  OPTION_KEYS = {
9
9
  'assets.batch' => %w[assetIds operation].freeze,
10
10
  'assets.classify' => %w[
11
- authorId content context description externalId externalUrl folderId isFinal metadata name part
12
- processingOptions sizeInBytes tags totalSizeInBytes uploadPresetId url visibility
11
+ authorId content context externalId externalUrl folderId isFinal metadata name part processingOptions
12
+ sizeInBytes tags totalSizeInBytes uploadPresetId url visibility
13
13
  ].freeze,
14
14
  'assets.create' => %w[
15
- authorId content context description externalId externalUrl folderId isFinal metadata name part
16
- processingOptions sizeInBytes tags totalSizeInBytes uploadPresetId url visibility
15
+ authorId content context externalId externalUrl folderId isFinal metadata name part processingOptions
16
+ sizeInBytes tags totalSizeInBytes uploadPresetId url visibility
17
17
  ].freeze,
18
18
  'assets.decide' => %w[assetId confirmPurge decision note].freeze,
19
19
  'assets.delete' => %w[assetId].freeze,
@@ -30,7 +30,7 @@ module CalmLens
30
30
  'assets.retrieveByExternalId' => %w[externalId].freeze,
31
31
  'assets.retry' => %w[assetId].freeze,
32
32
  'assets.search' => %w[mode pageSize query].freeze,
33
- 'assets.update' => %w[assetId description externalId externalUrl metadata name tags visibility].freeze,
33
+ 'assets.update' => %w[assetId externalId externalUrl metadata name tags visibility].freeze,
34
34
  'assets.uploadPart' => %w[assetId part wait].freeze,
35
35
  'cdn.signAssetUrl' => %w[
36
36
  assetId expiresIn externalId lens projectId resource resource transform viewerClaims
@@ -80,7 +80,7 @@ module CalmLens
80
80
  'projectSettings.get' => %w[].freeze,
81
81
  'projectSettings.update' => %w[revision searchIndexingBudgetUnits settings].freeze,
82
82
  'text.classify' => %w[
83
- authorId context description externalId externalUrl folderId metadata name processingOptions tags text
83
+ authorId context externalId externalUrl folderId metadata name processingOptions tags text
84
84
  uploadPresetId visibility
85
85
  ].freeze,
86
86
  'uploadPresets.delete' => %w[uploadPresetId].freeze,
@@ -93,17 +93,15 @@ module CalmLens
93
93
  # is left out, as the API refuses null for it.
94
94
  NULLABLE_OPTION_KEYS = {
95
95
  'assets.classify' => %w[
96
- authorId context description externalId folderId metadata processingOptions tags uploadPresetId
97
- visibility
96
+ authorId context externalId folderId metadata processingOptions tags uploadPresetId visibility
98
97
  ].freeze,
99
98
  'assets.create' => %w[
100
- authorId context description externalId folderId metadata processingOptions tags uploadPresetId
101
- visibility
99
+ authorId context externalId folderId metadata processingOptions tags uploadPresetId visibility
102
100
  ].freeze,
103
101
  'assets.each' => %w[filter].freeze,
104
102
  'assets.list' => %w[filter].freeze,
105
103
  'assets.move' => %w[folderId].freeze,
106
- 'assets.update' => %w[description externalId externalUrl metadata tags visibility].freeze,
104
+ 'assets.update' => %w[externalId externalUrl metadata tags visibility].freeze,
107
105
  'folders.create' => %w[parentId].freeze,
108
106
  'folders.move' => %w[parentId].freeze,
109
107
  'hashLists.addEntry' => %w[label quality].freeze,
@@ -112,8 +110,7 @@ module CalmLens
112
110
  'lenses.create' => %w[description transform].freeze,
113
111
  'lenses.update' => %w[description transform].freeze,
114
112
  'text.classify' => %w[
115
- authorId context description externalId folderId metadata processingOptions tags uploadPresetId
116
- visibility
113
+ authorId context externalId folderId metadata processingOptions tags uploadPresetId visibility
117
114
  ].freeze
118
115
  }.freeze
119
116
 
@@ -29,7 +29,7 @@ module CalmLens
29
29
  # `method` names the public method: an option it doesn't take, such as a misspelt one, raises
30
30
  # `sdk/invalid-argument` instead of being silently dropped.
31
31
  # An option given as nil is left out, as if omitted, unless the API takes null for it
32
- # (Internal::NULLABLE_OPTION_KEYS), such as `description: nil` to clear a description;
32
+ # (Internal::NULLABLE_OPTION_KEYS), such as `external_id: nil` to clear an external ID;
33
33
  # `keep_nil: true` sends every option as given, as for a lens definition. `prefix` names the
34
34
  # operation's resource, the resource's own unless the method belongs to the client itself.
35
35
  def call(options, method, keep_nil: false, prefix: self.class::OPERATIONS)
@@ -16,7 +16,6 @@ module CalmLens
16
16
  'updatedAt' => { kind: 'number', nullable: false, operators: ['==', '!=', '>', '>=', '<', '<=', '=in=', '=out='].freeze }.freeze,
17
17
  'type' => { kind: 'text', nullable: false, operators: ['==', '!=', '>', '>=', '<', '<=', '=in=', '=out='].freeze }.freeze,
18
18
  'name' => { kind: 'text', nullable: false, operators: ['==', '!=', '>', '>=', '<', '<=', '=in=', '=out='].freeze }.freeze,
19
- 'description' => { kind: 'text', nullable: true, operators: ['==', '!=', '>', '>=', '<', '<=', '=in=', '=out='].freeze }.freeze,
20
19
  'externalId' => { kind: 'text', nullable: true, operators: ['==', '!=', '>', '>=', '<', '<=', '=in=', '=out='].freeze }.freeze,
21
20
  'externalUrl' => { kind: 'text', nullable: true, operators: ['==', '!=', '>', '>=', '<', '<=', '=in=', '=out='].freeze }.freeze,
22
21
  'authorId' => { kind: 'text', nullable: true, operators: ['==', '!=', '>', '>=', '<', '<=', '=in=', '=out='].freeze }.freeze,
@@ -45,9 +45,10 @@ module CalmLens
45
45
  # @api private
46
46
  class FakeAPI
47
47
  JSON_QUERY = %w[wait isFinal sizeInBytes totalSizeInBytes partNumber pageSize].freeze
48
- # Keyword search fields, in the order matches are reported, and where each value sits in the asset.
48
+ # Keyword search fields, in the order matches are reported, and where each value sits in the
49
+ # asset; `content.extractedText` follows them, from the asset's retained text.
49
50
  SEARCH_FIELDS = { 'name' => %w[name], 'id' => %w[id], 'externalId' => %w[externalId],
50
- 'description' => %w[description], 'tags' => %w[tags], 'type' => %w[type],
51
+ 'tags' => %w[tags], 'type' => %w[type],
51
52
  'content.format' => %w[content format], 'content.extension' => %w[content extension],
52
53
  'classification.moderation.decision' => %w[classification moderation decision] }.freeze
53
54
  MAX_SEARCH_TOKENS = 8
@@ -115,8 +116,12 @@ module CalmLens
115
116
  'education-support' => 'Learning and support', 'wholesome-community' => 'Teen-safe' }.freeze
116
117
  # Like the API: 1 to 255 printable ASCII characters, without a space at either end.
117
118
  IDEMPOTENCY_KEY = /\A[\x21-\x7e](?:[\x20-\x7e]{0,253}[\x21-\x7e])?\z/
118
- # Entries with a lower PDQ quality never match (HashList.ts, HASH_MATCH_MIN_QUALITY).
119
+ # Hashes with a lower PDQ quality never match (HashList.ts, HASH_MATCH_MIN_QUALITY).
119
120
  HASH_MATCH_MIN_QUALITY = 50
121
+ # Hashes this many bits apart or fewer match (HASH_MATCH_MAX_DISTANCE); a block list blocks
122
+ # only matches this close and flags looser ones (HASH_BLOCK_MAX_DISTANCE).
123
+ HASH_MATCH_MAX_DISTANCE = 31
124
+ HASH_BLOCK_MAX_DISTANCE = 16
120
125
  # The most hash matches an asset records (HashList.ts).
121
126
  MAX_RECORDED_HASH_MATCHES = 10
122
127
  # Content types a URL upload stores nothing for: the URL is a web page, a `website` asset.
@@ -186,6 +191,8 @@ module CalmLens
186
191
  @processing_options = {}
187
192
  # Each served URL's content, by its normalized URL (see {#serve_url}).
188
193
  @served_urls = {}
194
+ # Each image's declared perceptual hash and quality, by its bytes (see {#set_perceptual_hash}).
195
+ @perceptual_hashes = {}
189
196
  # The review the queue holds for each asset waiting for one, by asset ID.
190
197
  @pending_reviews = {}
191
198
  end
@@ -200,6 +207,18 @@ module CalmLens
200
207
  @served_urls[key] = { bytes: bytes.b, type: type.strip }
201
208
  end
202
209
 
210
+ # Makes an image upload of exactly `bytes` hash as `hash` with `quality`, instead of the
211
+ # SHA-256 of its bytes.
212
+ def set_perceptual_hash(bytes, hash, quality)
213
+ raise Internal.invalid('content must be a String of bytes') unless bytes.is_a?(String)
214
+ unless hash.is_a?(String) && hash.strip.match?(/\A\h{64}\z/)
215
+ raise Internal.invalid('hash must be a PDQ hash of 64 hexadecimal characters')
216
+ end
217
+ raise Internal.invalid('quality must be a whole number from 0 to 100') unless quality.is_a?(Integer) && quality.between?(0, 100)
218
+
219
+ @perceptual_hashes[bytes.b] = [hash.strip.downcase, quality]
220
+ end
221
+
203
222
  # A URL as {#serve_url} compares it, parsed and normalized; nil for one that isn't absolute.
204
223
  def self.url_key(url)
205
224
  uri = URI.parse(url.to_s)
@@ -296,9 +315,9 @@ module CalmLens
296
315
  # the API key as its events' actor; the test hook's is a reviewer's (a `user`).
297
316
  def record_decision(item, decision, note, by_api_key)
298
317
  apply_outcome(item, decision, 'requested')
299
- # Like the API: the human review queue's decision settles its review, one through the API
300
- # leaves it waiting.
301
- item['classification']['moderation']['pendingReview'] = nil unless by_api_key
318
+ # Like the API: the human review queue's decision settles its review, and so does the app's own
319
+ # decision through the API.
320
+ item['classification']['moderation']['pendingReview'] = nil
302
321
  review = { 'id' => @create_id.call('rev'), 'decision' => decision, 'note' => note,
303
322
  'decidedBy' => deep_copy(API_KEY_ACTOR), 'reviewedAt' => @now.call, 'applied' => true }
304
323
  actor = by_api_key ? API_KEY_ACTOR : REVIEWER_ACTOR
@@ -328,7 +347,13 @@ module CalmLens
328
347
  fail!(ErrorCodes::ASSET_PROCESSING) if processing
329
348
  status = item['classification']['moderation']['decision']
330
349
  fail!(ErrorCodes::ASSET_DECISION_NOT_ALLOWED) if status.nil? && !%w[blocked purged].include?(decision)
331
- fail!(ErrorCodes::ASSET_DECISION_UNCHANGED) if status == decision
350
+ if status == decision
351
+ # Like the API: agreeing with the decision a queued review waits on settles the review,
352
+ # leaving the decision as it is.
353
+ fail!(ErrorCodes::ASSET_DECISION_UNCHANGED) if item['classification']['moderation']['pendingReview'].nil?
354
+ item['classification']['moderation']['pendingReview'] = nil
355
+ return item
356
+ end
332
357
  fail!(ErrorCodes::ASSET_CONTENT_PURGED) if status == 'purged' && decision != 'blocked'
333
358
 
334
359
  record_decision(item, decision, note, true)
@@ -886,7 +911,8 @@ module CalmLens
886
911
  end
887
912
 
888
913
  # Keyword search like the API: every whitespace-separated token (case-insensitive, at most 8
889
- # distinct) must appear in some field. Results rank by the API's score, then newest first.
914
+ # distinct) must appear in some field, including the asset's own text while its content is
915
+ # stored. Results rank by the API's score, then newest first.
890
916
  def search(query)
891
917
  text = query['query'].to_s.strip
892
918
  invalid!('validation/too-small', 'query') if text.empty?
@@ -901,6 +927,7 @@ module CalmLens
901
927
  value = 'pending' if value.nil? && field == 'classification.moderation.decision'
902
928
  [field, Array(value).join(' ').downcase]
903
929
  end
930
+ values['content.extractedText'] = retained_text(item).downcase
904
931
  next unless tokens.all? { |token| values.each_value.any? { |value| value.include?(token) } }
905
932
 
906
933
  fields = values.filter_map { |field, value| field if tokens.any? { |token| value.include?(token) } }
@@ -969,7 +996,7 @@ module CalmLens
969
996
  # Fields the API returns as null when they are not set.
970
997
  asset = { 'id' => @create_id.call('asset'), 'projectId' => @project_id, 'parentId' => nil, 'parentPages' => [],
971
998
  'folderId' => options['folderId'], 'uploadPresetId' => options['uploadPresetId'],
972
- 'createdAt' => now, 'updatedAt' => now, 'name' => options['name'], 'description' => options['description'],
999
+ 'createdAt' => now, 'updatedAt' => now, 'name' => options['name'],
973
1000
  'externalId' => options['externalId'], 'externalUrl' => url || options['externalUrl'],
974
1001
  'type' => type || kind(mime, url), 'metadata' => options['metadata'] || [], 'authorId' => options['authorId'],
975
1002
  # Like the API, only the posts CalmLens uses are kept, and only while the content is held.
@@ -1258,6 +1285,13 @@ module CalmLens
1258
1285
  # the most recent ones, newest first, while CONTEXT_USED_ITEMS posts and
1259
1286
  # CONTEXT_USED_CHARACTERS characters allow, returned oldest first. The newest is always kept.
1260
1287
  def select_context(items)
1288
+ # Like the API's schema, a reference that isn't an asset ID is refused before any lookup.
1289
+ Array(items).each_with_index do |item, index|
1290
+ asset_id = item.is_a?(Hash) ? item['assetId'] : nil
1291
+ next if asset_id.is_a?(String) && asset_id.match?(ASSET_ID_PATTERN)
1292
+
1293
+ invalid!('validation/invalid-format', "context.items.#{index}.assetId")
1294
+ end
1261
1295
  posts = Array(items).map do |item|
1262
1296
  asset_id = item.is_a?(Hash) ? item['assetId'] : nil
1263
1297
  asset = asset_id.is_a?(String) ? @state.assets[asset_id] : nil
@@ -1277,16 +1311,26 @@ module CalmLens
1277
1311
 
1278
1312
  # An earlier post's text, to the most CalmLens reads of one post; empty once its content is gone.
1279
1313
  def context_text(asset)
1314
+ asset_text(asset).strip[0, CONTEXT_MAX_ITEM_CHARACTERS]
1315
+ end
1316
+
1317
+ # The text keyword search matches as `content.extractedText`: only while the content is stored.
1318
+ def retained_text(asset)
1319
+ asset['content']['status'] == 'stored' ? asset_text(asset) : ''
1320
+ end
1321
+
1322
+ # A text asset's stored bytes as UTF-8, or else its inline extracted text (such as OCR); empty
1323
+ # once its content is gone.
1324
+ def asset_text(asset)
1280
1325
  bytes = asset['type'] == 'plaintext-document' ? stored_bytes(asset) : nil
1281
1326
  extracted = asset['content']['extractedText']
1282
- text = if bytes && !bytes.empty?
1283
- bytes.dup.force_encoding(Encoding::UTF_8).scrub
1284
- elsif extracted.is_a?(Hash) && extracted['type'] == 'string'
1285
- extracted['content'].to_s
1286
- else
1287
- ''
1288
- end
1289
- text.strip[0, CONTEXT_MAX_ITEM_CHARACTERS]
1327
+ if bytes && !bytes.empty?
1328
+ bytes.dup.force_encoding(Encoding::UTF_8).scrub
1329
+ elsif extracted.is_a?(Hash) && extracted['type'] == 'string'
1330
+ extracted['content'].to_s
1331
+ else
1332
+ ''
1333
+ end
1290
1334
  end
1291
1335
 
1292
1336
  # An asset's stored content, its parts in order, or nil once it is removed.
@@ -1296,26 +1340,32 @@ module CalmLens
1296
1340
  end
1297
1341
 
1298
1342
  # Gives a decided image its hash and the project's hash list matches, as the API records them
1299
- # (AssetClassification.ts, Project.ts and HashList.ts). The mock computes no PDQ hash: an
1343
+ # (AssetClassification.ts, HashMatching.ts and HashList.ts). The mock computes no PDQ hash: an
1300
1344
  # image's `content.perceptualHash` is the SHA-256 of its bytes in lowercase hex, with quality
1301
- # 100, so an entry matches an image whose bytes equal those it was taken from, at distance 0.
1302
- # Entries below quality 50 never match. Each match takes its list's action, blocking matches
1303
- # first; a block raises an allowed, limited or age-restricted decision to `blocked`, with
1304
- # `source: "hash-list"`, and a flag only records the match.
1345
+ # 100, unless {#set_perceptual_hash} declared one for those bytes. An entry matches a hash up to
1346
+ # 31 bits away, so different images' SHA-256 stand-ins never match, and an entry taken from an
1347
+ # image matches the same bytes at distance 0. Hashes below quality 50 never match. A match takes
1348
+ # its list's action, except that a block list only flags matches more than 16 bits away;
1349
+ # blocking matches come first, then the closest. A block raises an allowed, limited or
1350
+ # age-restricted decision to `blocked`, with `source: "hash-list"`, and a flag only records
1351
+ # the match.
1305
1352
  def match_hash_lists(asset, bytes)
1306
- hash = Digest::SHA256.hexdigest(bytes)
1307
- asset['content'].merge!('perceptualHash' => hash, 'perceptualHashQuality' => 100)
1308
- matches = @state.hash_list_entries.values.select do |entry|
1309
- entry['hash'] == hash && (entry['quality'].nil? || entry['quality'] >= HASH_MATCH_MIN_QUALITY) &&
1310
- @state.hash_lists.key?(entry['hashListId'])
1311
- end
1312
- matches = matches.map do |entry|
1313
- { 'source' => 'hash-list', 'hashListId' => entry['hashListId'], 'hashListEntryId' => entry['id'], 'distance' => 0,
1314
- 'action' => @state.hash_lists[entry['hashListId']]['action'] }
1315
- end
1316
- # A stable sort: blocking matches first, each kind in the order its entries were added.
1317
- matches = matches.each_with_index.sort_by { |match, index| [match['action'] == 'block' ? 0 : 1, index] }.map(&:first)
1318
- .first(MAX_RECORDED_HASH_MATCHES)
1353
+ hash, quality = @perceptual_hashes.fetch(bytes.b) { [Digest::SHA256.hexdigest(bytes), 100] }
1354
+ asset['content'].merge!('perceptualHash' => hash, 'perceptualHashQuality' => quality)
1355
+ matches = @state.hash_list_entries.values.filter_map do |entry|
1356
+ list = @state.hash_lists[entry['hashListId']]
1357
+ next unless list && quality >= HASH_MATCH_MIN_QUALITY && (entry['quality'].nil? || entry['quality'] >= HASH_MATCH_MIN_QUALITY)
1358
+
1359
+ distance = (hash.to_i(16) ^ entry['hash'].to_i(16)).to_s(2).count('1')
1360
+ next if distance > HASH_MATCH_MAX_DISTANCE
1361
+
1362
+ action = list['action'] == 'block' && distance <= HASH_BLOCK_MAX_DISTANCE ? 'block' : 'flag'
1363
+ { 'source' => 'hash-list', 'hashListId' => entry['hashListId'], 'hashListEntryId' => entry['id'],
1364
+ 'distance' => distance, 'action' => action }
1365
+ end
1366
+ # A stable sort: blocking matches first, then the closest, then in the order the entries were added.
1367
+ matches = matches.each_with_index.sort_by { |match, index| [match['action'] == 'block' ? 0 : 1, match['distance'], index] }
1368
+ .map(&:first).first(MAX_RECORDED_HASH_MATCHES)
1319
1369
  return if matches.empty?
1320
1370
 
1321
1371
  moderation = asset['classification']['moderation']
@@ -34,8 +34,9 @@ module CalmLens
34
34
  # time: a pending asset times out at once.
35
35
  # Filters join comparisons with `;` (and), which binds tighter than `,` (or), and group them with
36
36
  # `( … )`; list cursors resume after the last item returned. {Assets#search} is the API's keyword
37
- # search: every query word (case-insensitive, up to 8) must appear in a searchable field, and
38
- # results carry the API's `score` and `matchedFields`, ranked by score and then newest first.
37
+ # search: every query word (case-insensitive, up to 8) must appear in a searchable field, which
38
+ # includes a text asset's own words (or OCR text) while its content is stored, and results carry
39
+ # the API's `score` and `matchedFields`, ranked by score and then newest first.
39
40
  #
40
41
  # To script exact responses, enqueue them: queued responses and errors are used first, in order,
41
42
  # before the stand-in answers.
@@ -288,11 +289,25 @@ module CalmLens
288
289
  self
289
290
  end
290
291
 
292
+ # Makes the mock hash an image upload of exactly `content` as `hash`, a PDQ hash, with `quality`,
293
+ # instead of the SHA-256 of its bytes. Hash list entries match hashes up to 31 bits away, as in
294
+ # CalmLens, so a test can make a resized or recompressed copy a near match of a listed image:
295
+ # declare the copy's hash a few bits from the entry's.
296
+ # @param content [String] the image's bytes, or text as UTF-8
297
+ # @param hash [String] 64 hexadecimal characters
298
+ # @param quality [Integer] 0 to 100
299
+ # @return [self]
300
+ # @raise [InvalidArgumentError] `sdk/invalid-argument` for an invalid hash or quality
301
+ def set_perceptual_hash(content, hash, quality: 100)
302
+ @mock_lock.synchronize { @fake.set_perceptual_hash(content, hash, quality) }
303
+ self
304
+ end
305
+
291
306
  # Fetches a URL of the mock's CDN as a browser would, with a GET and without the API key: a signed
292
- # asset URL from {CDN#sign_asset_url} (with a resource appended), or a public one from
293
- # {CDN#get_asset_url}. The request is recorded like any other. Error statuses are returned, not
294
- # raised. A private asset without a grant answers `asset/not-found` (404) whatever its state,
295
- # including its placeholder and display info.
307
+ # asset URL from {CDN#sign_asset_url}, or a public one from {CDN#get_asset_url}. The request is
308
+ # recorded like any other. Error statuses are returned, not raised. A private asset without a
309
+ # grant answers `asset/not-found` (404) whatever its state, including its placeholder and display
310
+ # info.
296
311
  # @param url [String]
297
312
  # @return [Response] with its body read
298
313
  def fetch_cdn(url)
@@ -3,7 +3,8 @@
3
3
  # Generated by packages/sdk-contract/generate.ts from packages/shared/src/UploadMimeTypes.ts; do not edit.
4
4
  # After lower-casing and dropping parameters, a type in REJECTED is refused; otherwise one
5
5
  # that starts with a PREFIXES entry, ends with a SUFFIXES entry or is in TYPES is accepted,
6
- # and any other type is refused with upload/unsupported-type.
6
+ # and any other type is refused with upload/unsupported-type. A type in DOCUMENTS is a
7
+ # document: PDFs can be up to 2,000 MiB and other documents up to 50 MiB.
7
8
 
8
9
  module CalmLens
9
10
  module Internal
@@ -48,5 +49,21 @@ module CalmLens
48
49
  'application/xml',
49
50
  'application/yaml'
50
51
  ].freeze
52
+ UPLOAD_MIME_DOCUMENTS = [
53
+ 'application/pdf',
54
+ 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
55
+ 'application/vnd.ms-word.document.macroenabled.12',
56
+ 'application/msword',
57
+ 'application/rtf',
58
+ 'application/vnd.oasis.opendocument.text',
59
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
60
+ 'application/vnd.ms-excel.sheet.macroenabled.12',
61
+ 'application/vnd.ms-excel',
62
+ 'application/vnd.oasis.opendocument.spreadsheet',
63
+ 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
64
+ 'application/vnd.ms-powerpoint.presentation.macroenabled.12',
65
+ 'application/vnd.ms-powerpoint',
66
+ 'application/vnd.oasis.opendocument.presentation'
67
+ ].freeze
51
68
  end
52
69
  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.31.0'
5
+ VERSION = '0.32.0'
6
6
  end
data/sig/calmlens.rbs CHANGED
@@ -94,14 +94,19 @@ module CalmLens
94
94
  def hash: () -> Integer
95
95
  end
96
96
 
97
- # One page of a list; enumerating it yields this page's items.
98
- class Page[T] < Model
97
+ # A result holding a list of items; enumerating it yields them.
98
+ class ItemList[T] < Model
99
99
  include Enumerable[T]
100
- def initialize: (Hash[String, untyped] values, ?fetch: (^(String cursor) -> Page[T])?, ?cursor: String?,
101
- ?last_response: LastResponse?) -> void
102
100
  def each: () { (T) -> void } -> self
103
101
  | () -> Enumerator[T, self]
104
102
  def empty?: () -> bool
103
+ private def items_list: () -> Array[T]
104
+ end
105
+
106
+ # One page of a list; enumerating it yields this page's items.
107
+ class Page[T] < ItemList[T]
108
+ def initialize: (Hash[String, untyped] values, ?fetch: (^(String cursor) -> Page[T])?, ?cursor: String?,
109
+ ?last_response: LastResponse?) -> void
105
110
  def next_page?: () -> bool
106
111
  def next_page: () -> self
107
112
  def each_page: () { (self) -> void } -> nil
@@ -241,7 +246,7 @@ module CalmLens
241
246
  def retrieve: (String asset_id, ?request_options: request_options) -> Asset
242
247
  def retrieve_by_external_id: (String external_id, ?request_options: request_options) -> Asset
243
248
  def wait_for_decision: (String asset_id, ?timeout: number, ?request_options: request_options) -> Asset
244
- def update: (String asset_id, ?name: String, ?description: String?, ?external_id: String?, ?external_url: String?, ?metadata: Array[metadata_item_input]?, ?tags: Array[String]?, ?visibility: asset_visibility?, ?request_options: request_options) -> Asset
249
+ def update: (String asset_id, ?name: String, ?external_id: String?, ?external_url: String?, ?metadata: Array[metadata_item_input]?, ?tags: Array[String]?, ?visibility: asset_visibility?, ?request_options: request_options) -> Asset
245
250
  def retry: (String asset_id, ?request_options: request_options) -> Asset
246
251
  def decide: (String asset_id, decision: "allowed" | "limited" | "age-restricted" | "blocked" | "purged", note: String, ?confirm_purge: true, ?request_options: request_options) -> Asset
247
252
  def request_review: (String asset_id, ?note: String, ?request_options: request_options) -> AssetReviewRequest
@@ -249,12 +254,12 @@ module CalmLens
249
254
  def delete: (String asset_id, ?request_options: request_options) -> nil
250
255
  def batch: (asset_ids: Array[String], operation: asset_batch_operation, ?request_options: request_options) -> AssetBatch
251
256
  def move: (String asset_id, folder_id: String?, ?request_options: request_options) -> Asset
252
- def create: (name: String, content: upload_content, ?description: String?, ?visibility: asset_visibility?, ?metadata: Array[metadata_item_input]?, ?tags: Array[String]?, ?author_id: String, ?context: moderation_context_input, ?external_id: String?, ?external_url: String?, ?folder_id: String?, ?upload_preset_id: String, ?processing_options: processing_options_input?, ?request_options: request_options) -> Asset
253
- | (name: String, part: upload_first_part, ?total_size_in_bytes: Integer, ?description: String?, ?visibility: asset_visibility?, ?metadata: Array[metadata_item_input]?, ?tags: Array[String]?, ?author_id: String, ?context: moderation_context_input, ?external_id: String?, ?external_url: String?, ?folder_id: String?, ?upload_preset_id: String, ?processing_options: processing_options_input?, ?request_options: request_options) -> Asset
254
- | (name: String, url: String, ?description: String?, ?visibility: asset_visibility?, ?metadata: Array[metadata_item_input]?, ?tags: Array[String]?, ?author_id: String, ?context: moderation_context_input, ?external_id: String?, ?external_url: String?, ?folder_id: String?, ?upload_preset_id: String, ?processing_options: processing_options_input?, ?request_options: request_options) -> Asset
255
- def classify: (name: String, content: upload_content, ?description: String?, ?visibility: asset_visibility?, ?metadata: Array[metadata_item_input]?, ?tags: Array[String]?, ?author_id: String, ?context: moderation_context_input, ?external_id: String?, ?external_url: String?, ?folder_id: String?, ?upload_preset_id: String, ?processing_options: processing_options_input?, ?request_options: request_options) -> Asset
256
- | (name: String, part: upload_first_part, ?total_size_in_bytes: Integer, ?description: String?, ?visibility: asset_visibility?, ?metadata: Array[metadata_item_input]?, ?tags: Array[String]?, ?author_id: String, ?context: moderation_context_input, ?external_id: String?, ?external_url: String?, ?folder_id: String?, ?upload_preset_id: String, ?processing_options: processing_options_input?, ?request_options: request_options) -> Asset
257
- | (name: String, url: String, ?description: String?, ?visibility: asset_visibility?, ?metadata: Array[metadata_item_input]?, ?tags: Array[String]?, ?author_id: String, ?context: moderation_context_input, ?external_id: String?, ?external_url: String?, ?folder_id: String?, ?upload_preset_id: String, ?processing_options: processing_options_input?, ?request_options: request_options) -> Asset
257
+ def create: (name: String, content: upload_content, ?visibility: asset_visibility?, ?metadata: Array[metadata_item_input]?, ?tags: Array[String]?, ?author_id: String, ?context: moderation_context_input, ?external_id: String?, ?external_url: String?, ?folder_id: String?, ?upload_preset_id: String, ?processing_options: processing_options_input?, ?request_options: request_options) -> Asset
258
+ | (name: String, part: upload_first_part, ?total_size_in_bytes: Integer, ?visibility: asset_visibility?, ?metadata: Array[metadata_item_input]?, ?tags: Array[String]?, ?author_id: String, ?context: moderation_context_input, ?external_id: String?, ?external_url: String?, ?folder_id: String?, ?upload_preset_id: String, ?processing_options: processing_options_input?, ?request_options: request_options) -> Asset
259
+ | (name: String, url: String, ?visibility: asset_visibility?, ?metadata: Array[metadata_item_input]?, ?tags: Array[String]?, ?author_id: String, ?context: moderation_context_input, ?external_id: String?, ?external_url: String?, ?folder_id: String?, ?upload_preset_id: String, ?processing_options: processing_options_input?, ?request_options: request_options) -> Asset
260
+ def classify: (name: String, content: upload_content, ?visibility: asset_visibility?, ?metadata: Array[metadata_item_input]?, ?tags: Array[String]?, ?author_id: String, ?context: moderation_context_input, ?external_id: String?, ?external_url: String?, ?folder_id: String?, ?upload_preset_id: String, ?processing_options: processing_options_input?, ?request_options: request_options) -> Asset
261
+ | (name: String, part: upload_first_part, ?total_size_in_bytes: Integer, ?visibility: asset_visibility?, ?metadata: Array[metadata_item_input]?, ?tags: Array[String]?, ?author_id: String, ?context: moderation_context_input, ?external_id: String?, ?external_url: String?, ?folder_id: String?, ?upload_preset_id: String, ?processing_options: processing_options_input?, ?request_options: request_options) -> Asset
262
+ | (name: String, url: String, ?visibility: asset_visibility?, ?metadata: Array[metadata_item_input]?, ?tags: Array[String]?, ?author_id: String, ?context: moderation_context_input, ?external_id: String?, ?external_url: String?, ?folder_id: String?, ?upload_preset_id: String, ?processing_options: processing_options_input?, ?request_options: request_options) -> Asset
258
263
  def upload_part: (String asset_id, part: upload_part, ?wait: bool, ?request_options: request_options) -> Asset
259
264
  # Waits between decision checks; a mock client's waits take no real time.
260
265
  private def sleep: (Numeric seconds) -> void
@@ -333,7 +338,7 @@ module CalmLens
333
338
 
334
339
  class Text < Resource
335
340
  private def initialize: (untyped session, Assets assets) -> void
336
- def classify: (text: String, ?name: String, ?description: String?, ?visibility: asset_visibility?, ?metadata: Array[metadata_item_input]?, ?tags: Array[String]?, ?author_id: String, ?context: moderation_context_input, ?external_id: String?, ?external_url: String?, ?folder_id: String?, ?upload_preset_id: String, ?processing_options: processing_options_input?, ?request_options: request_options) -> Asset
341
+ def classify: (text: String, ?name: String, ?visibility: asset_visibility?, ?metadata: Array[metadata_item_input]?, ?tags: Array[String]?, ?author_id: String, ?context: moderation_context_input, ?external_id: String?, ?external_url: String?, ?folder_id: String?, ?upload_preset_id: String, ?processing_options: processing_options_input?, ?request_options: request_options) -> Asset
337
342
  end
338
343
 
339
344
  class Events < Resource
@@ -517,6 +522,8 @@ module CalmLens
517
522
  def clear_failures: () -> self
518
523
  # Makes a URL upload of `url` store `content` (bytes, or UTF-8 text) typed by its content `type`.
519
524
  def serve_url: (String url, content: String, type: String) -> self
525
+ # Makes an image upload of exactly `content` hash as `hash` (a PDQ hash) with `quality`.
526
+ def set_perceptual_hash: (String content, String hash, ?quality: Integer) -> self
520
527
  def state: () -> Testing::State
521
528
  # `body` is any JSON value, encoded as the response body.
522
529
  def enqueue: (body: json_input, ?status: Integer, ?headers: Hash[String, String]) -> self
data/sig/models.rbs CHANGED
@@ -13,7 +13,6 @@ module CalmLens
13
13
  def updated_at: () -> Integer?
14
14
  def type: () -> asset_type
15
15
  def name: () -> String
16
- def description: () -> String?
17
16
  def external_id: () -> String?
18
17
  def external_url: () -> String?
19
18
  def author_id: () -> String?
@@ -45,7 +44,7 @@ module CalmLens
45
44
  def note: () -> String?
46
45
  def created_at: () -> Integer
47
46
  end
48
- class AssetSearchResult < Model
47
+ class AssetSearchResult < ItemList[AssetSearchResult::Item]
49
48
  def query: () -> String
50
49
  def items: () -> Array[AssetSearchResult::Item]
51
50
  def semantic_status: () -> ("disabled" | "ready" | "indexing" | "unavailable")
data/sig/types.rbs CHANGED
@@ -119,8 +119,8 @@ module CalmLens
119
119
  type sort = String
120
120
 
121
121
  type asset_search_mode = "keyword" | "semantic" | "hybrid"
122
- type asset_search_match_field = "name" | "id" | "externalId" | "description" | "tags" | "type" | "content.format" |
123
- "content.extension" | "classification.moderation.decision" | "visual" | "transcript"
122
+ type asset_search_match_field = "name" | "id" | "externalId" | "tags" | "type" | "content.format" | "content.extension" |
123
+ "content.extractedText" | "classification.moderation.decision" | "visual" | "transcript"
124
124
 
125
125
  type asset_batch_operation = "delete" | "remove-content"
126
126
  # Whether the viewer an asset URL's claims describe can see the content now.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: calmlens
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.31.0
4
+ version: 0.32.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - CalmLens