ruby-anvil 0.0.1.pre.rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,496 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Generated by dev/generate-types.mjs from @anvilco/types@1.1.0 openapi.json. Do not edit by hand:
4
+ # run `npm run generate` in dev/ to regenerate.
5
+
6
+ module Anvil
7
+ module Payloads
8
+ # Declared empty first, so an attribute below can name a class defined later in the file
9
+ class EtchFinishPageOptions < Base; end
10
+ class EtchSignaturePageOptions < Base; end
11
+ class EtchSignaturePageOptionsStyle < Base; end
12
+ class EtchSigner < Base; end
13
+ class EtchSignerField < Base; end
14
+ class EtchSignerField2 < Base; end
15
+ class EtchSignerField2PayloadMap < Base; end
16
+ class FillPdfFromIntegrationRequest < Base; end
17
+ class FillPdfRequest < Base; end
18
+ class GenerateHtmlPdfRequest < Base; end
19
+ class GenerateHtmlPdfRequestData < Base; end
20
+ class GenerateMarkdownPdfRequest < Base; end
21
+ class GenerateMarkdownPdfRequestData < Base; end
22
+ class GenerateMarkdownPdfRequestDataTable < Base; end
23
+ class GenerateMarkdownPdfRequestDataTableColumnOption < Base; end
24
+ class GenerateMarkdownPdfRequestLogo < Base; end
25
+ class PageOptions < Base; end
26
+ end
27
+ end
28
+
29
+ module Anvil
30
+ module Payloads
31
+ # createEtchPacket's `finishPageOptions` argument: text for the page signers see when they're done.
32
+ class EtchFinishPageOptions
33
+ attribute :complete_description
34
+ attribute :complete_title
35
+ attribute :incomplete_description
36
+ attribute :incomplete_title
37
+ attribute :signature_async_description
38
+ attribute :signature_async_title
39
+ attribute :signature_button_text
40
+ attribute :signature_description
41
+ attribute :signature_title
42
+ attribute :signature_waiting_signers_after_description
43
+ attribute :signature_waiting_signers_after_title
44
+ attribute :signature_waiting_signers_before_description
45
+ attribute :signature_waiting_signers_before_title
46
+ attribute :zip_name
47
+ end
48
+
49
+ # createEtchPacket's `signaturePageOptions` argument: text and styles for the signing page.
50
+ class EtchSignaturePageOptions
51
+ attribute :accept_button_text
52
+ attribute :accept_description
53
+ attribute :accept_title
54
+ attribute :completed_button_text
55
+ attribute :description
56
+ attribute :draw_initials_button_text
57
+ attribute :draw_initials_description
58
+ attribute :draw_initials_title
59
+ attribute :draw_signature_button_text
60
+ attribute :draw_signature_description
61
+ attribute :draw_signature_title
62
+ attribute :error
63
+ attribute :initial_label
64
+ attribute :not_current_user_error
65
+ attribute :review_button_text
66
+ attribute :review_description
67
+ attribute :review_title
68
+ attribute :sign_button_text
69
+ attribute :sign_consent_text
70
+ attribute :sign_description
71
+ attribute :sign_description_completed
72
+ attribute :sign_each_completed_message
73
+ attribute :sign_each_consent_text
74
+ attribute :sign_each_description
75
+ attribute :sign_each_error_message
76
+ attribute :sign_each_finish_button_text
77
+ attribute :sign_each_next_button_text
78
+ attribute :sign_each_not_ready_message
79
+ attribute :sign_each_sign_all_text
80
+ attribute :sign_each_signing_message
81
+ attribute :sign_each_start_button_text
82
+ attribute :sign_each_submitting_message
83
+ attribute :sign_title
84
+ attribute :signature_label
85
+ attribute :style, type: Anvil::Payloads::EtchSignaturePageOptionsStyle
86
+ attribute :title
87
+ end
88
+
89
+ class EtchSignaturePageOptionsStyle
90
+ attribute :info_color
91
+ attribute :link_color
92
+ attribute :primary_color
93
+ attribute :stylesheet_url, key: "stylesheetURL"
94
+ attribute :success_color
95
+ end
96
+
97
+ # A signer in createEtchPacket's `signers` argument: who signs, which fields they sign, and how.
98
+ class EtchSigner
99
+ # What the API requires in this payload
100
+ REQUIRED = %w[id].freeze
101
+
102
+ # The values the API documents for `signatureExperience`
103
+ SIGNATURE_EXPERIENCE_VALUES = %w[signBeforeReviewing signWhileReviewing acknowledgeOnly formCompletionOnly].freeze
104
+
105
+ # The values the API documents for `signatureImageVerticalJustificationDefault`
106
+ SIGNATURE_IMAGE_VERTICAL_JUSTIFICATION_DEFAULT_VALUES = %w[dynamic bottom none].freeze
107
+
108
+ # The values the API documents for `signatureMode`
109
+ SIGNATURE_MODE_VALUES = %w[draw text].freeze
110
+
111
+ # The values the API documents for `signerType`
112
+ SIGNER_TYPE_VALUES = %w[email embedded in-person].freeze
113
+
114
+ attribute :accept_each_field
115
+ attribute :access_code
116
+ attribute :add_timestamp_to_signatures
117
+ attribute :add_uuid_to_signatures
118
+ attribute :allow_email_change
119
+ attribute :allow_name_change
120
+ attribute :email
121
+
122
+ # One of: a boolean; a list of string.
123
+ attribute :enable_emails
124
+
125
+ # Each item is one of: a EtchSignerField; a EtchSignerField2.
126
+ attribute :fields
127
+
128
+ attribute :fields_are_ordered
129
+ attribute :id
130
+ attribute :id_check_phone
131
+ attribute :is_pending
132
+ attribute :name
133
+ attribute :redirect_url, key: "redirectURL"
134
+ attribute :require_email_on_load
135
+
136
+ # One of: a boolean; `"kb"` or `"sms"` or `"smskb"` or `"idsms"`.
137
+ attribute :require_id_check
138
+
139
+ attribute :require_id_check_in_test
140
+ attribute :require_name_on_load
141
+
142
+ # At least 1.
143
+ attribute :routing_order
144
+
145
+ attribute :show_finish_signing_button
146
+
147
+ # See `SIGNATURE_EXPERIENCE_VALUES`.
148
+ attribute :signature_experience
149
+
150
+ # See `SIGNATURE_IMAGE_VERTICAL_JUSTIFICATION_DEFAULT_VALUES`.
151
+ attribute :signature_image_vertical_justification_default
152
+
153
+ # See `SIGNATURE_MODE_VALUES`.
154
+ attribute :signature_mode
155
+
156
+ # See `SIGNER_TYPE_VALUES`.
157
+ attribute :signer_type
158
+
159
+ # Between 1 and 86400.
160
+ attribute :token_valid_for_minutes
161
+
162
+ attribute :token_valid_until
163
+ end
164
+
165
+ class EtchSignerField
166
+ # What the API requires in this payload
167
+ REQUIRED = %w[fieldId fileId].freeze
168
+
169
+ # The values the API documents for `signatureImageVerticalJustification`
170
+ SIGNATURE_IMAGE_VERTICAL_JUSTIFICATION_VALUES = %w[dynamic bottom none].freeze
171
+
172
+ attribute :field_id
173
+ attribute :file_id
174
+
175
+ # See `SIGNATURE_IMAGE_VERTICAL_JUSTIFICATION_VALUES`.
176
+ attribute :signature_image_vertical_justification
177
+ end
178
+
179
+ class EtchSignerField2
180
+ # What the API requires in this payload
181
+ REQUIRED = %w[kind payloadMaps].freeze
182
+
183
+ # The values the API documents for `kind`
184
+ KIND_VALUES = %w[form].freeze
185
+
186
+ attribute :description
187
+ attribute :help_tip
188
+ attribute :ignore_when_filled
189
+
190
+ # See `KIND_VALUES`.
191
+ attribute :kind
192
+
193
+ attribute :label
194
+ attribute :optional
195
+ attribute :options
196
+ attribute :payload_maps, array_of: Anvil::Payloads::EtchSignerField2PayloadMap
197
+ attribute :placeholder
198
+ end
199
+
200
+ class EtchSignerField2PayloadMap
201
+ # What the API requires in this payload
202
+ REQUIRED = %w[fieldId fileId].freeze
203
+
204
+ attribute :field_id
205
+ attribute :file_id
206
+ end
207
+
208
+ class FillPdfFromIntegrationRequest
209
+ # What the API requires in this payload
210
+ REQUIRED = %w[records].freeze
211
+
212
+ # The values the API documents for `outputFormat`
213
+ OUTPUT_FORMAT_VALUES = %w[pdf url].freeze
214
+
215
+ # See `OUTPUT_FORMAT_VALUES`.
216
+ # Defaults to `"pdf"` when left out.
217
+ attribute :output_format
218
+
219
+ # Record IDs keyed by the template's object types, e.g.
220
+ # `{ "contacts": "111", "companies": "999" }`. Each type takes one ID
221
+ # as a numeric string, or a list holding one.
222
+ attribute :records
223
+
224
+ attribute :title
225
+ end
226
+
227
+ class FillPdfRequest
228
+ # What the API requires in this payload
229
+ REQUIRED = %w[data].freeze
230
+
231
+ # The values the API documents for `outputFormat`
232
+ OUTPUT_FORMAT_VALUES = %w[pdf url].freeze
233
+
234
+ # The values the API documents for `verticalAlignment`
235
+ VERTICAL_ALIGNMENT_VALUES = %w[top middle bottom].freeze
236
+
237
+ # Default border color for field bounding boxes, as a CSS hex color.
238
+ attribute :border_color
239
+
240
+ # The field data to fill into the template. Can be a single object keyed by
241
+ # field ID or alias, or an array of objects for multi-page / repeating fills.
242
+ # Each value can be a primitive (string, number, boolean), or a value object
243
+ # with a `value` key alongside styling overrides.
244
+ # One of: an object; a list of object.
245
+ attribute :data
246
+
247
+ # The character used to represent a checked checkbox.
248
+ attribute :default_checkbox_character
249
+
250
+ # When true, checkbox fields are rendered as squares instead of the default shape.
251
+ attribute :default_make_checkbox_square
252
+
253
+ # Controls whether interactive AcroForm fields default to read-only.
254
+ # Only applicable when `useInteractiveFields` is true. Defaults to false
255
+ # when `useInteractiveFields` is enabled.
256
+ attribute :default_read_only
257
+
258
+ # When true, draws visible bounding boxes around each field for debugging layout issues.
259
+ attribute :draw_debug_boxes
260
+
261
+ # Default font family name for all fields.
262
+ attribute :font_family
263
+
264
+ # Default font size in points for all fields.
265
+ # Between 5 and 30.
266
+ attribute :font_size
267
+
268
+ # Controls the response format. When set to `url`, the filled PDF is
269
+ # uploaded to cloud storage and a JSON response with a short-lived signed
270
+ # URL is returned instead of the binary PDF. The signed URL expires 5
271
+ # minutes after generation. Defaults to `pdf` (binary PDF response).
272
+ # See `OUTPUT_FORMAT_VALUES`.
273
+ # Defaults to `"pdf"` when left out.
274
+ attribute :output_format
275
+
276
+ # When true, removes all PDF annotations from the output.
277
+ attribute :strip_annotations
278
+
279
+ # Default text color for all fields, as a CSS hex color (e.g. `#FF0000`).
280
+ attribute :text_color
281
+
282
+ # Custom title for the generated PDF. Overrides the template's default title.
283
+ attribute :title
284
+
285
+ # When true, the filled PDF will contain interactive AcroForm fields
286
+ # that can be edited by the recipient in a PDF viewer. Requires a paid plan.
287
+ attribute :use_interactive_fields
288
+
289
+ # Default vertical alignment for text within fields.
290
+ # See `VERTICAL_ALIGNMENT_VALUES`.
291
+ attribute :vertical_alignment
292
+ end
293
+
294
+ # Generate a PDF by rendering raw HTML and optional CSS.
295
+ class GenerateHtmlPdfRequest
296
+ # What the API requires in this payload
297
+ REQUIRED = %w[data].freeze
298
+
299
+ # The values the API documents for `outputFormat`
300
+ OUTPUT_FORMAT_VALUES = %w[pdf url].freeze
301
+
302
+ # The values the API documents for `type`
303
+ TYPE_VALUES = %w[html].freeze
304
+
305
+ # The HTML content and optional CSS to render into a PDF.
306
+ attribute :data, type: Anvil::Payloads::GenerateHtmlPdfRequestData
307
+
308
+ # Controls the response format. When set to `url`, the generated PDF is
309
+ # uploaded to cloud storage and a JSON response with a short-lived signed
310
+ # URL is returned instead of the binary PDF. The signed URL expires 5
311
+ # minutes after generation. Defaults to `pdf` (binary PDF response).
312
+ # See `OUTPUT_FORMAT_VALUES`.
313
+ # Defaults to `"pdf"` when left out.
314
+ attribute :output_format
315
+
316
+ attribute :page, type: Anvil::Payloads::PageOptions
317
+
318
+ # The document title. Used as the PDF metadata title and in the output filename.
319
+ attribute :title
320
+
321
+ # Set to `html` to explicitly select HTML-to-PDF rendering.
322
+ # See `TYPE_VALUES`.
323
+ attribute :type
324
+ end
325
+
326
+ # The HTML content and optional CSS to render into a PDF.
327
+ class GenerateHtmlPdfRequestData
328
+ # What the API requires in this payload
329
+ REQUIRED = %w[html].freeze
330
+
331
+ # Optional CSS stylesheet applied to the HTML content during rendering.
332
+ attribute :css
333
+
334
+ # The HTML markup to render. This is the full body content of the PDF.
335
+ attribute :html
336
+ end
337
+
338
+ # Generate a PDF from structured Markdown-style content blocks.
339
+ # Each item in the `data` array represents a content section that
340
+ # can contain headings, labeled values, body text, or tables.
341
+ class GenerateMarkdownPdfRequest
342
+ # What the API requires in this payload
343
+ REQUIRED = %w[data].freeze
344
+
345
+ # The values the API documents for `outputFormat`
346
+ OUTPUT_FORMAT_VALUES = %w[pdf url].freeze
347
+
348
+ # An array of content blocks that make up the PDF body. Each block
349
+ # can contain one or more of: `heading`, `label`, `content`, `table`.
350
+ attribute :data, array_of: Anvil::Payloads::GenerateMarkdownPdfRequestData
351
+
352
+ # Default font family for the document.
353
+ attribute :font_family
354
+
355
+ # Default font size in points for the document.
356
+ # Between 5 and 30.
357
+ attribute :font_size
358
+
359
+ # When true, a timestamp is printed on the PDF showing when it was generated.
360
+ attribute :include_timestamp
361
+
362
+ # A logo image to display at the top of the PDF. Set to `false` to
363
+ # explicitly disable any default logo. Provide an object with a
364
+ # base64-encoded or URL image source to include a logo.
365
+ # One of: `false`; a GenerateMarkdownPdfRequestLogo.
366
+ attribute :logo
367
+
368
+ # Controls the response format. When set to `url`, the generated PDF is
369
+ # uploaded to cloud storage and a JSON response with a short-lived signed
370
+ # URL is returned instead of the binary PDF. The signed URL expires 5
371
+ # minutes after generation. Defaults to `pdf` (binary PDF response).
372
+ # See `OUTPUT_FORMAT_VALUES`.
373
+ # Defaults to `"pdf"` when left out.
374
+ attribute :output_format
375
+
376
+ attribute :page, type: Anvil::Payloads::PageOptions
377
+
378
+ # Default text color for the document, as a CSS hex color (e.g. `#333333`).
379
+ attribute :text_color
380
+
381
+ # The document title. Used as the PDF metadata title and in the output filename.
382
+ attribute :title
383
+ end
384
+
385
+ class GenerateMarkdownPdfRequestData
386
+ # Body text content, rendered as a paragraph. Supports Markdown formatting.
387
+ attribute :content
388
+
389
+ # Font family override for this content block.
390
+ attribute :font_family
391
+
392
+ # Font size override for this content block.
393
+ # Between 5 and 30.
394
+ attribute :font_size
395
+
396
+ # A section heading rendered in a larger, bold font.
397
+ attribute :heading
398
+
399
+ # A label rendered in bold, typically used for key-value pairs.
400
+ attribute :label
401
+
402
+ # A table rendered inline in the PDF.
403
+ attribute :table, type: Anvil::Payloads::GenerateMarkdownPdfRequestDataTable
404
+
405
+ # Text color override for this block, as a CSS hex color.
406
+ attribute :text_color
407
+ end
408
+
409
+ # A table rendered inline in the PDF.
410
+ class GenerateMarkdownPdfRequestDataTable
411
+ # What the API requires in this payload
412
+ REQUIRED = %w[rows].freeze
413
+
414
+ # The values the API documents for `verticalAlign`
415
+ VERTICAL_ALIGN_VALUES = %w[top center bottom].freeze
416
+
417
+ # When true, vertical gridlines are drawn between columns.
418
+ attribute :column_gridlines
419
+
420
+ # Per-column display options.
421
+ attribute :column_options, array_of: Anvil::Payloads::GenerateMarkdownPdfRequestDataTableColumnOption
422
+
423
+ # When true, the first row is rendered as a header row with bold styling.
424
+ attribute :first_row_headers
425
+
426
+ # When true, horizontal gridlines are drawn between rows.
427
+ attribute :row_gridlines
428
+
429
+ # Table data as a 2D array of strings (array of rows, each row is an array of cell values).
430
+ attribute :rows
431
+
432
+ # Vertical alignment of cell content.
433
+ # See `VERTICAL_ALIGN_VALUES`.
434
+ attribute :vertical_align
435
+ end
436
+
437
+ class GenerateMarkdownPdfRequestDataTableColumnOption
438
+ # The values the API documents for `align`
439
+ ALIGN_VALUES = %w[left center right].freeze
440
+
441
+ # Horizontal text alignment for this column.
442
+ # See `ALIGN_VALUES`.
443
+ attribute :align
444
+
445
+ # Column width as a percentage or pixel value (e.g. `25%`, `100px`).
446
+ attribute :width
447
+ end
448
+
449
+ class GenerateMarkdownPdfRequestLogo
450
+ # What the API requires in this payload
451
+ REQUIRED = %w[src].freeze
452
+
453
+ # Maximum height of the logo in pixels.
454
+ # One of: a string; a number.
455
+ attribute :max_height
456
+
457
+ # Maximum width of the logo in pixels.
458
+ # One of: a string; a number.
459
+ attribute :max_width
460
+
461
+ # Image source: a base64-encoded data URI or an HTTPS URL.
462
+ attribute :src
463
+ end
464
+
465
+ # Custom page dimensions and margins for the generated PDF.
466
+ class PageOptions
467
+ # The values the API documents for `pageCount`
468
+ PAGE_COUNT_VALUES = %w[topLeft topRight topCenter bottomLeft bottomRight bottomCenter].freeze
469
+
470
+ # Page height with unit (e.g. `11in`, `297mm`).
471
+ attribute :height
472
+
473
+ # Shorthand margin for all sides (e.g. `0.5in`, `10mm 20mm`).
474
+ attribute :margin
475
+
476
+ # Bottom margin with unit.
477
+ attribute :margin_bottom
478
+
479
+ # Left margin with unit.
480
+ attribute :margin_left
481
+
482
+ # Right margin with unit.
483
+ attribute :margin_right
484
+
485
+ # Top margin with unit.
486
+ attribute :margin_top
487
+
488
+ # Position to render page numbers on each page.
489
+ # See `PAGE_COUNT_VALUES`.
490
+ attribute :page_count
491
+
492
+ # Page width with unit (e.g. `8.5in`, `210mm`).
493
+ attribute :width
494
+ end
495
+ end
496
+ end
@@ -0,0 +1,113 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pathname"
4
+
5
+ module Anvil
6
+ # A file to upload through the GraphQL API, together with the filename and
7
+ # mimetype to send it under.
8
+ #
9
+ # Build one with {Anvil.prepare_graphql_file} rather than calling `new`
10
+ # directly: that is where the checks live. This is the Ruby equivalent of
11
+ # node-anvil's `UploadWithOptions`.
12
+ class UploadWithOptions
13
+ # Extensions worth naming. Anything else is sent as application/octet-stream,
14
+ # which Anvil sniffs.
15
+ MIMETYPES = {
16
+ ".pdf" => "application/pdf",
17
+ ".png" => "image/png",
18
+ ".jpg" => "image/jpeg",
19
+ ".jpeg" => "image/jpeg",
20
+ ".gif" => "image/gif",
21
+ ".tif" => "image/tiff",
22
+ ".tiff" => "image/tiff",
23
+ ".bmp" => "image/bmp",
24
+ ".webp" => "image/webp",
25
+ ".svg" => "image/svg+xml",
26
+ ".txt" => "text/plain",
27
+ ".html" => "text/html",
28
+ ".htm" => "text/html",
29
+ ".csv" => "text/csv",
30
+ ".json" => "application/json",
31
+ ".xml" => "application/xml",
32
+ ".doc" => "application/msword",
33
+ ".docx" => "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
34
+ ".xls" => "application/vnd.ms-excel",
35
+ ".xlsx" => "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
36
+ ".zip" => "application/zip"
37
+ }.freeze
38
+
39
+ DEFAULT_MIMETYPE = "application/octet-stream"
40
+
41
+ # @return [String, Pathname, IO] the path or IO this wraps
42
+ attr_reader :file
43
+ # @return [Hash] the options it was prepared with
44
+ attr_reader :options
45
+
46
+ # @param file [String, Pathname, IO]
47
+ # @param options [Hash]
48
+ # @option options [String] :filename
49
+ # @option options [String] :mimetype
50
+ # @option options [Boolean] :ignore_filename_validation
51
+ def initialize(file, options = {})
52
+ @file = file
53
+ @options = options.transform_keys(&:to_sym)
54
+ end
55
+
56
+ # @return [String, nil] the name the file is uploaded under
57
+ def filename
58
+ @options[:filename] || derived_filename
59
+ end
60
+
61
+ # @return [String] the content type the file is uploaded under
62
+ def mimetype
63
+ @options[:mimetype] || MIMETYPES.fetch(extension, DEFAULT_MIMETYPE)
64
+ end
65
+
66
+ # @return [Boolean] whether this wraps a path rather than an open IO
67
+ def path?
68
+ file.is_a?(String) || file.is_a?(Pathname)
69
+ end
70
+
71
+ # Yields an IO positioned at the start of the file's bytes. Opens and
72
+ # closes the file when this wraps a path; rewinds when it can otherwise.
73
+ #
74
+ # @yieldparam io [IO]
75
+ # @return [Object] whatever the block returned
76
+ def with_io
77
+ if path?
78
+ File.open(file.to_s, "rb") { |io| return yield(io) }
79
+ else
80
+ file.rewind if file.respond_to?(:rewind)
81
+ yield(file)
82
+ end
83
+ end
84
+
85
+ # @return [Integer, nil] the file's size in bytes when it is knowable
86
+ # without reading the whole thing
87
+ def size
88
+ return File.size(file.to_s) if path?
89
+ return file.size if file.respond_to?(:size)
90
+
91
+ nil
92
+ end
93
+
94
+ private
95
+
96
+ def derived_filename
97
+ source = if path?
98
+ file.to_s
99
+ elsif file.respond_to?(:path) && file.path.is_a?(String)
100
+ file.path
101
+ elsif file.respond_to?(:original_filename)
102
+ file.original_filename
103
+ end
104
+
105
+ source && File.basename(source)
106
+ end
107
+
108
+ def extension
109
+ name = filename
110
+ name ? File.extname(name).downcase : ""
111
+ end
112
+ end
113
+ end