-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb.go
More file actions
4931 lines (4608 loc) · 235 KB
/
Copy pathweb.go
File metadata and controls
4931 lines (4608 loc) · 235 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package contextdev
import (
"context"
"encoding/json"
"net/http"
"net/url"
"slices"
"github.com/context-dot-dev/context-go-sdk/v2/internal/apijson"
"github.com/context-dot-dev/context-go-sdk/v2/internal/apiquery"
"github.com/context-dot-dev/context-go-sdk/v2/internal/requestconfig"
"github.com/context-dot-dev/context-go-sdk/v2/option"
"github.com/context-dot-dev/context-go-sdk/v2/packages/param"
"github.com/context-dot-dev/context-go-sdk/v2/packages/respjson"
"github.com/context-dot-dev/context-go-sdk/v2/shared/constant"
)
// WebService contains methods and other services that help with interacting with
// the context.dev API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewWebService] method instead.
type WebService struct {
options []option.RequestOption
}
// NewWebService generates a new service that applies the given options to each
// request. These options are applied after the parent client's options (if there
// is one), and before any request-specific options.
func NewWebService(opts ...option.RequestOption) (r WebService) {
r = WebService{}
r.options = opts
return
}
// Crawl a website, use the provided JSON Schema and instructions to prioritize
// relevant internal links, and extract structured data from the selected pages.
func (r *WebService) Extract(ctx context.Context, body WebExtractParams, opts ...option.RequestOption) (res *WebExtractResponse, err error) {
opts = slices.Concat(r.options, opts)
path := "web/extract"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return res, err
}
// Analyze a company's landing page and web search evidence to return direct
// competitors for the same product or market.
func (r *WebService) ExtractCompetitors(ctx context.Context, query WebExtractCompetitorsParams, opts ...option.RequestOption) (res *WebExtractCompetitorsResponse, err error) {
opts = slices.Concat(r.options, opts)
path := "web/competitors"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
return res, err
}
// Scrape font information from a website including font families, usage
// statistics, fallbacks, and element/word counts.
func (r *WebService) ExtractFonts(ctx context.Context, query WebExtractFontsParams, opts ...option.RequestOption) (res *WebExtractFontsResponse, err error) {
opts = slices.Concat(r.options, opts)
path := "web/fonts"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
return res, err
}
// Extract a comprehensive design system from a website including colors,
// typography, spacing, shadows, and UI components.
func (r *WebService) ExtractStyleguide(ctx context.Context, query WebExtractStyleguideParams, opts ...option.RequestOption) (res *WebExtractStyleguideResponse, err error) {
opts = slices.Concat(r.options, opts)
path := "web/styleguide"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
return res, err
}
// Capture a screenshot of a website.
func (r *WebService) Screenshot(ctx context.Context, query WebScreenshotParams, opts ...option.RequestOption) (res *WebScreenshotResponse, err error) {
opts = slices.Concat(r.options, opts)
path := "web/screenshot"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
return res, err
}
// Search the web and optionally scrape each result to Markdown in one round-trip.
func (r *WebService) Search(ctx context.Context, body WebSearchParams, opts ...option.RequestOption) (res *WebSearchResponse, err error) {
opts = slices.Concat(r.options, opts)
path := "web/search"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return res, err
}
// Performs a crawl starting from a given URL, extracts page content as Markdown,
// and returns results for all crawled pages.
func (r *WebService) WebCrawlMd(ctx context.Context, body WebWebCrawlMdParams, opts ...option.RequestOption) (res *WebWebCrawlMdResponse, err error) {
opts = slices.Concat(r.options, opts)
path := "web/crawl"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return res, err
}
// Scrapes the given URL and returns the raw HTML content of the page. The base
// request costs 1 credit; requests with browser actions cost 2 credits.
func (r *WebService) WebScrapeHTML(ctx context.Context, query WebWebScrapeHTMLParams, opts ...option.RequestOption) (res *WebWebScrapeHTMLResponse, err error) {
opts = slices.Concat(r.options, opts)
path := "web/scrape/html"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
return res, err
}
// Extract image assets from a web page, including standard URLs, inline SVGs, data
// URIs, responsive image sources, metadata, CSS backgrounds, video posters, and
// embeds. The base request costs 1 credit, or 2 credits with browser actions. When
// enrichment is enabled, the entire call costs 5 credits, including requests that
// also use actions.
func (r *WebService) WebScrapeImages(ctx context.Context, query WebWebScrapeImagesParams, opts ...option.RequestOption) (res *WebWebScrapeImagesResponse, err error) {
opts = slices.Concat(r.options, opts)
path := "web/scrape/images"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
return res, err
}
// Scrapes the given URL into LLM usable Markdown. Inspect key_metadata on JSON
// responses from a recognized API key; use error_code to distinguish stable
// failure categories.
//
// ### Billing & errors
//
// | HTTP status | Billed? | Meaning |
// | ----------- | ----------------------------------------- | ---------------------------------------------------------------------------------------- |
// | 200 | Yes — 1 credit, or 2 credits with actions | Successful scrape, including a zero-length result when includeSelectors matched nothing |
// | 400 | No | Invalid input, skipped PDF, or the page could not be scraped |
// | 401 / 403 | No | Invalid/disabled key, insufficient permissions, or credits exhausted; inspect error_code |
// | 404 | No | Target page returned or fingerprinted as not found |
// | 408 | No | Request timed out |
// | 415 | No | Unsupported content type |
// | 429 | No | Per-minute rate limit exceeded; honor Retry-After |
// | 500 | No | Internal error |
func (r *WebService) WebScrapeMd(ctx context.Context, query WebWebScrapeMdParams, opts ...option.RequestOption) (res *WebWebScrapeMdResponse, err error) {
opts = slices.Concat(r.options, opts)
path := "web/scrape/markdown"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
return res, err
}
// Crawl an entire website's sitemap and return all discovered page URLs.
func (r *WebService) WebScrapeSitemap(ctx context.Context, query WebWebScrapeSitemapParams, opts ...option.RequestOption) (res *WebWebScrapeSitemapResponse, err error) {
opts = slices.Concat(r.options, opts)
path := "web/scrape/sitemap"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
return res, err
}
type WebExtractResponse struct {
// Extracted data matching the request schema
Data map[string]any `json:"data" api:"required"`
Metadata WebExtractResponseMetadata `json:"metadata" api:"required"`
// Status of the response, e.g., 'ok'
Status string `json:"status" api:"required"`
// The starting URL that was analyzed
URL string `json:"url" api:"required"`
// List of URLs whose Markdown was used for extraction
URLsAnalyzed []string `json:"urls_analyzed" api:"required"`
// Metadata about the API key used for the request. Included in every response
// whenever a valid API key is provided, even when the response status is not 200.
KeyMetadata WebExtractResponseKeyMetadata `json:"key_metadata"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Data respjson.Field
Metadata respjson.Field
Status respjson.Field
URL respjson.Field
URLsAnalyzed respjson.Field
KeyMetadata respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r WebExtractResponse) RawJSON() string { return r.JSON.raw }
func (r *WebExtractResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type WebExtractResponseMetadata struct {
MaxCrawlDepth int64 `json:"maxCrawlDepth" api:"required"`
// Number of crawled pages excluded because they were anti-bot challenges, error
// pages, or parked-domain placeholders.
NumBlocked int64 `json:"numBlocked" api:"required"`
NumFailed int64 `json:"numFailed" api:"required"`
NumSkipped int64 `json:"numSkipped" api:"required"`
NumSucceeded int64 `json:"numSucceeded" api:"required"`
NumURLs int64 `json:"numUrls" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
MaxCrawlDepth respjson.Field
NumBlocked respjson.Field
NumFailed respjson.Field
NumSkipped respjson.Field
NumSucceeded respjson.Field
NumURLs respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r WebExtractResponseMetadata) RawJSON() string { return r.JSON.raw }
func (r *WebExtractResponseMetadata) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Metadata about the API key used for the request. Included in every response
// whenever a valid API key is provided, even when the response status is not 200.
type WebExtractResponseKeyMetadata struct {
// The number of credits consumed by this request.
CreditsConsumed int64 `json:"credits_consumed" api:"required"`
// The number of credits remaining for your organization after this request.
CreditsRemaining int64 `json:"credits_remaining" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
CreditsConsumed respjson.Field
CreditsRemaining respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r WebExtractResponseKeyMetadata) RawJSON() string { return r.JSON.raw }
func (r *WebExtractResponseKeyMetadata) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type WebExtractCompetitorsResponse struct {
// Direct competitors ordered by relevance and confidence.
Competitors []WebExtractCompetitorsResponseCompetitor `json:"competitors" api:"required"`
// Normalized input domain.
Domain string `json:"domain" api:"required"`
// Status of the response.
//
// Any of "ok".
Status WebExtractCompetitorsResponseStatus `json:"status" api:"required"`
// Target company profile inferred from the landing page.
Target WebExtractCompetitorsResponseTarget `json:"target" api:"required"`
// Metadata about the API key used for the request. Included in every response
// whenever a valid API key is provided, even when the response status is not 200.
KeyMetadata WebExtractCompetitorsResponseKeyMetadata `json:"key_metadata"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Competitors respjson.Field
Domain respjson.Field
Status respjson.Field
Target respjson.Field
KeyMetadata respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r WebExtractCompetitorsResponse) RawJSON() string { return r.JSON.raw }
func (r *WebExtractCompetitorsResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type WebExtractCompetitorsResponseCompetitor struct {
// Confidence that this company is a direct competitor.
//
// Any of "high", "medium".
Confidence string `json:"confidence" api:"required"`
// Short description of the competitor.
Description string `json:"description" api:"required"`
// Competitor's normalized official domain.
Domain string `json:"domain" api:"required"`
// Competitor company or product name.
Name string `json:"name" api:"required"`
// Search result URLs used as evidence for this competitor.
SourceURLs []string `json:"sourceUrls" api:"required"`
// Competitor website URL.
URL string `json:"url" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Confidence respjson.Field
Description respjson.Field
Domain respjson.Field
Name respjson.Field
SourceURLs respjson.Field
URL respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r WebExtractCompetitorsResponseCompetitor) RawJSON() string { return r.JSON.raw }
func (r *WebExtractCompetitorsResponseCompetitor) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Status of the response.
type WebExtractCompetitorsResponseStatus string
const (
WebExtractCompetitorsResponseStatusOk WebExtractCompetitorsResponseStatus = "ok"
)
// Target company profile inferred from the landing page.
type WebExtractCompetitorsResponseTarget struct {
// Company or product name inferred from the landing page.
CompanyName string `json:"companyName" api:"required"`
// Specific operating field, product category, or market.
Field string `json:"field" api:"required"`
// One-sentence description of what the target company sells and who it serves.
FieldDescription string `json:"fieldDescription" api:"required"`
// Resolved URL used for the landing page analysis.
WebsiteURL string `json:"websiteUrl" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
CompanyName respjson.Field
Field respjson.Field
FieldDescription respjson.Field
WebsiteURL respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r WebExtractCompetitorsResponseTarget) RawJSON() string { return r.JSON.raw }
func (r *WebExtractCompetitorsResponseTarget) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Metadata about the API key used for the request. Included in every response
// whenever a valid API key is provided, even when the response status is not 200.
type WebExtractCompetitorsResponseKeyMetadata struct {
// The number of credits consumed by this request.
CreditsConsumed int64 `json:"credits_consumed" api:"required"`
// The number of credits remaining for your organization after this request.
CreditsRemaining int64 `json:"credits_remaining" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
CreditsConsumed respjson.Field
CreditsRemaining respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r WebExtractCompetitorsResponseKeyMetadata) RawJSON() string { return r.JSON.raw }
func (r *WebExtractCompetitorsResponseKeyMetadata) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type WebExtractFontsResponse struct {
// HTTP status code, e.g., 200
Code int64 `json:"code" api:"required"`
// The normalized domain that was processed
Domain string `json:"domain" api:"required"`
// Array of font usage information
Fonts []WebExtractFontsResponseFont `json:"fonts" api:"required"`
// Status of the response, e.g., 'ok'
Status string `json:"status" api:"required"`
// Font assets keyed by family name as it appears in the fonts array (non-generic
// names only). Clients match entries in fonts to pick a file URL from files.
// Omitted when no families resolve to Google or custom @font-face URLs.
FontLinks map[string]WebExtractFontsResponseFontLink `json:"fontLinks"`
// Metadata about the API key used for the request. Included in every response
// whenever a valid API key is provided, even when the response status is not 200.
KeyMetadata WebExtractFontsResponseKeyMetadata `json:"key_metadata"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Code respjson.Field
Domain respjson.Field
Fonts respjson.Field
Status respjson.Field
FontLinks respjson.Field
KeyMetadata respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r WebExtractFontsResponse) RawJSON() string { return r.JSON.raw }
func (r *WebExtractFontsResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type WebExtractFontsResponseFont struct {
// Array of fallback font families
Fallbacks []string `json:"fallbacks" api:"required"`
// Font family name
Font string `json:"font" api:"required"`
// Number of elements using this font
NumElements float64 `json:"num_elements" api:"required"`
// Number of words using this font
NumWords float64 `json:"num_words" api:"required"`
// Percentage of elements using this font
PercentElements float64 `json:"percent_elements" api:"required"`
// Percentage of words using this font
PercentWords float64 `json:"percent_words" api:"required"`
// Array of CSS selectors or element types where this font is used
Uses []string `json:"uses" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Fallbacks respjson.Field
Font respjson.Field
NumElements respjson.Field
NumWords respjson.Field
PercentElements respjson.Field
PercentWords respjson.Field
Uses respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r WebExtractFontsResponseFont) RawJSON() string { return r.JSON.raw }
func (r *WebExtractFontsResponseFont) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type WebExtractFontsResponseFontLink struct {
// Upright font files keyed by weight string (e.g. "400" for regular, "500",
// "700"). Values are absolute URLs.
Files map[string]string `json:"files" api:"required"`
// Any of "google", "custom".
Type string `json:"type" api:"required"`
// Google Fonts category when type is google (e.g. sans-serif, serif, monospace,
// display, handwriting). Omitted for custom fonts when unknown.
Category string `json:"category"`
// Present when type is custom: human-readable name derived from the fontLinks key
// (strip build/hash suffixes, split camelCase / PascalCase, normalize separators).
// Google entries omit this.
DisplayName string `json:"displayName"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Files respjson.Field
Type respjson.Field
Category respjson.Field
DisplayName respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r WebExtractFontsResponseFontLink) RawJSON() string { return r.JSON.raw }
func (r *WebExtractFontsResponseFontLink) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Metadata about the API key used for the request. Included in every response
// whenever a valid API key is provided, even when the response status is not 200.
type WebExtractFontsResponseKeyMetadata struct {
// The number of credits consumed by this request.
CreditsConsumed int64 `json:"credits_consumed" api:"required"`
// The number of credits remaining for your organization after this request.
CreditsRemaining int64 `json:"credits_remaining" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
CreditsConsumed respjson.Field
CreditsRemaining respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r WebExtractFontsResponseKeyMetadata) RawJSON() string { return r.JSON.raw }
func (r *WebExtractFontsResponseKeyMetadata) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type WebExtractStyleguideResponse struct {
// HTTP status code
Code int64 `json:"code"`
// The normalized domain that was processed
Domain string `json:"domain"`
// Metadata about the API key used for the request. Included in every response
// whenever a valid API key is provided, even when the response status is not 200.
KeyMetadata WebExtractStyleguideResponseKeyMetadata `json:"key_metadata"`
// Status of the response, e.g., 'ok'
Status string `json:"status"`
// Comprehensive styleguide data extracted from the website
Styleguide WebExtractStyleguideResponseStyleguide `json:"styleguide"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Code respjson.Field
Domain respjson.Field
KeyMetadata respjson.Field
Status respjson.Field
Styleguide respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r WebExtractStyleguideResponse) RawJSON() string { return r.JSON.raw }
func (r *WebExtractStyleguideResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Metadata about the API key used for the request. Included in every response
// whenever a valid API key is provided, even when the response status is not 200.
type WebExtractStyleguideResponseKeyMetadata struct {
// The number of credits consumed by this request.
CreditsConsumed int64 `json:"credits_consumed" api:"required"`
// The number of credits remaining for your organization after this request.
CreditsRemaining int64 `json:"credits_remaining" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
CreditsConsumed respjson.Field
CreditsRemaining respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r WebExtractStyleguideResponseKeyMetadata) RawJSON() string { return r.JSON.raw }
func (r *WebExtractStyleguideResponseKeyMetadata) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Comprehensive styleguide data extracted from the website
type WebExtractStyleguideResponseStyleguide struct {
// Primary colors used on the website
Colors WebExtractStyleguideResponseStyleguideColors `json:"colors" api:"required"`
// UI component styles
Components WebExtractStyleguideResponseStyleguideComponents `json:"components" api:"required"`
// Spacing system used on the website
ElementSpacing WebExtractStyleguideResponseStyleguideElementSpacing `json:"elementSpacing" api:"required"`
// Font assets keyed by family name as it appears in fontFamily/fontFallbacks
// (non-generic names only). Clients match typography.fontFamily / fontWeight or
// button styles to pick a file URL from files.
FontLinks map[string]WebExtractStyleguideResponseStyleguideFontLink `json:"fontLinks" api:"required"`
// The primary color mode of the website design
//
// Any of "light", "dark".
Mode string `json:"mode" api:"required"`
// Shadow styles used on the website
Shadows WebExtractStyleguideResponseStyleguideShadows `json:"shadows" api:"required"`
// Typography styles used on the website
Typography WebExtractStyleguideResponseStyleguideTypography `json:"typography" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Colors respjson.Field
Components respjson.Field
ElementSpacing respjson.Field
FontLinks respjson.Field
Mode respjson.Field
Shadows respjson.Field
Typography respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r WebExtractStyleguideResponseStyleguide) RawJSON() string { return r.JSON.raw }
func (r *WebExtractStyleguideResponseStyleguide) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Primary colors used on the website
type WebExtractStyleguideResponseStyleguideColors struct {
// Accent color (hex format)
Accent string `json:"accent" api:"required"`
// Background color (hex format)
Background string `json:"background" api:"required"`
// Text color (hex format)
Text string `json:"text" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Accent respjson.Field
Background respjson.Field
Text respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r WebExtractStyleguideResponseStyleguideColors) RawJSON() string { return r.JSON.raw }
func (r *WebExtractStyleguideResponseStyleguideColors) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// UI component styles
type WebExtractStyleguideResponseStyleguideComponents struct {
// Button component styles
Button WebExtractStyleguideResponseStyleguideComponentsButton `json:"button" api:"required"`
// Card component style
Card WebExtractStyleguideResponseStyleguideComponentsCard `json:"card"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Button respjson.Field
Card respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r WebExtractStyleguideResponseStyleguideComponents) RawJSON() string { return r.JSON.raw }
func (r *WebExtractStyleguideResponseStyleguideComponents) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Button component styles
type WebExtractStyleguideResponseStyleguideComponentsButton struct {
Link WebExtractStyleguideResponseStyleguideComponentsButtonLink `json:"link"`
Primary WebExtractStyleguideResponseStyleguideComponentsButtonPrimary `json:"primary"`
Secondary WebExtractStyleguideResponseStyleguideComponentsButtonSecondary `json:"secondary"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Link respjson.Field
Primary respjson.Field
Secondary respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r WebExtractStyleguideResponseStyleguideComponentsButton) RawJSON() string { return r.JSON.raw }
func (r *WebExtractStyleguideResponseStyleguideComponentsButton) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type WebExtractStyleguideResponseStyleguideComponentsButtonLink struct {
BackgroundColor string `json:"backgroundColor" api:"required"`
// Border color as CSS hex (#RRGGBB or #RRGGBBAA when computed border-color has
// alpha)
BorderColor string `json:"borderColor" api:"required"`
BorderRadius string `json:"borderRadius" api:"required"`
BorderStyle string `json:"borderStyle" api:"required"`
BorderWidth string `json:"borderWidth" api:"required"`
// Computed box-shadow (comma-separated layers when present)
BoxShadow string `json:"boxShadow" api:"required"`
Color string `json:"color" api:"required"`
// Ready-to-use CSS declaration block for this component style
Css string `json:"css" api:"required"`
FontSize string `json:"fontSize" api:"required"`
FontWeight float64 `json:"fontWeight" api:"required"`
// Sampled minimum height of the button box (typically px)
MinHeight string `json:"minHeight" api:"required"`
// Sampled minimum width of the button box (typically px)
MinWidth string `json:"minWidth" api:"required"`
Padding string `json:"padding" api:"required"`
TextDecoration string `json:"textDecoration" api:"required"`
// Full ordered font list from computed font-family
FontFallbacks []string `json:"fontFallbacks"`
// Primary button typeface (first in fontFallbacks)
FontFamily string `json:"fontFamily"`
// Hex color of the underline when it differs from the text color
TextDecorationColor string `json:"textDecorationColor"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
BackgroundColor respjson.Field
BorderColor respjson.Field
BorderRadius respjson.Field
BorderStyle respjson.Field
BorderWidth respjson.Field
BoxShadow respjson.Field
Color respjson.Field
Css respjson.Field
FontSize respjson.Field
FontWeight respjson.Field
MinHeight respjson.Field
MinWidth respjson.Field
Padding respjson.Field
TextDecoration respjson.Field
FontFallbacks respjson.Field
FontFamily respjson.Field
TextDecorationColor respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r WebExtractStyleguideResponseStyleguideComponentsButtonLink) RawJSON() string {
return r.JSON.raw
}
func (r *WebExtractStyleguideResponseStyleguideComponentsButtonLink) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type WebExtractStyleguideResponseStyleguideComponentsButtonPrimary struct {
BackgroundColor string `json:"backgroundColor" api:"required"`
// Border color as CSS hex (#RRGGBB or #RRGGBBAA when computed border-color has
// alpha)
BorderColor string `json:"borderColor" api:"required"`
BorderRadius string `json:"borderRadius" api:"required"`
BorderStyle string `json:"borderStyle" api:"required"`
BorderWidth string `json:"borderWidth" api:"required"`
// Computed box-shadow (comma-separated layers when present)
BoxShadow string `json:"boxShadow" api:"required"`
Color string `json:"color" api:"required"`
// Ready-to-use CSS declaration block for this component style
Css string `json:"css" api:"required"`
FontSize string `json:"fontSize" api:"required"`
FontWeight float64 `json:"fontWeight" api:"required"`
// Sampled minimum height of the button box (typically px)
MinHeight string `json:"minHeight" api:"required"`
// Sampled minimum width of the button box (typically px)
MinWidth string `json:"minWidth" api:"required"`
Padding string `json:"padding" api:"required"`
TextDecoration string `json:"textDecoration" api:"required"`
// Full ordered font list from computed font-family
FontFallbacks []string `json:"fontFallbacks"`
// Primary button typeface (first in fontFallbacks)
FontFamily string `json:"fontFamily"`
// Hex color of the underline when it differs from the text color
TextDecorationColor string `json:"textDecorationColor"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
BackgroundColor respjson.Field
BorderColor respjson.Field
BorderRadius respjson.Field
BorderStyle respjson.Field
BorderWidth respjson.Field
BoxShadow respjson.Field
Color respjson.Field
Css respjson.Field
FontSize respjson.Field
FontWeight respjson.Field
MinHeight respjson.Field
MinWidth respjson.Field
Padding respjson.Field
TextDecoration respjson.Field
FontFallbacks respjson.Field
FontFamily respjson.Field
TextDecorationColor respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r WebExtractStyleguideResponseStyleguideComponentsButtonPrimary) RawJSON() string {
return r.JSON.raw
}
func (r *WebExtractStyleguideResponseStyleguideComponentsButtonPrimary) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type WebExtractStyleguideResponseStyleguideComponentsButtonSecondary struct {
BackgroundColor string `json:"backgroundColor" api:"required"`
// Border color as CSS hex (#RRGGBB or #RRGGBBAA when computed border-color has
// alpha)
BorderColor string `json:"borderColor" api:"required"`
BorderRadius string `json:"borderRadius" api:"required"`
BorderStyle string `json:"borderStyle" api:"required"`
BorderWidth string `json:"borderWidth" api:"required"`
// Computed box-shadow (comma-separated layers when present)
BoxShadow string `json:"boxShadow" api:"required"`
Color string `json:"color" api:"required"`
// Ready-to-use CSS declaration block for this component style
Css string `json:"css" api:"required"`
FontSize string `json:"fontSize" api:"required"`
FontWeight float64 `json:"fontWeight" api:"required"`
// Sampled minimum height of the button box (typically px)
MinHeight string `json:"minHeight" api:"required"`
// Sampled minimum width of the button box (typically px)
MinWidth string `json:"minWidth" api:"required"`
Padding string `json:"padding" api:"required"`
TextDecoration string `json:"textDecoration" api:"required"`
// Full ordered font list from computed font-family
FontFallbacks []string `json:"fontFallbacks"`
// Primary button typeface (first in fontFallbacks)
FontFamily string `json:"fontFamily"`
// Hex color of the underline when it differs from the text color
TextDecorationColor string `json:"textDecorationColor"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
BackgroundColor respjson.Field
BorderColor respjson.Field
BorderRadius respjson.Field
BorderStyle respjson.Field
BorderWidth respjson.Field
BoxShadow respjson.Field
Color respjson.Field
Css respjson.Field
FontSize respjson.Field
FontWeight respjson.Field
MinHeight respjson.Field
MinWidth respjson.Field
Padding respjson.Field
TextDecoration respjson.Field
FontFallbacks respjson.Field
FontFamily respjson.Field
TextDecorationColor respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r WebExtractStyleguideResponseStyleguideComponentsButtonSecondary) RawJSON() string {
return r.JSON.raw
}
func (r *WebExtractStyleguideResponseStyleguideComponentsButtonSecondary) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Card component style
type WebExtractStyleguideResponseStyleguideComponentsCard struct {
BackgroundColor string `json:"backgroundColor" api:"required"`
// Border color as CSS hex (#RRGGBB or #RRGGBBAA when computed border-color has
// alpha)
BorderColor string `json:"borderColor" api:"required"`
BorderRadius string `json:"borderRadius" api:"required"`
BorderStyle string `json:"borderStyle" api:"required"`
BorderWidth string `json:"borderWidth" api:"required"`
BoxShadow string `json:"boxShadow" api:"required"`
// Ready-to-use CSS declaration block for this component style
Css string `json:"css" api:"required"`
Padding string `json:"padding" api:"required"`
TextColor string `json:"textColor" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
BackgroundColor respjson.Field
BorderColor respjson.Field
BorderRadius respjson.Field
BorderStyle respjson.Field
BorderWidth respjson.Field
BoxShadow respjson.Field
Css respjson.Field
Padding respjson.Field
TextColor respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r WebExtractStyleguideResponseStyleguideComponentsCard) RawJSON() string { return r.JSON.raw }
func (r *WebExtractStyleguideResponseStyleguideComponentsCard) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Spacing system used on the website
type WebExtractStyleguideResponseStyleguideElementSpacing struct {
Lg string `json:"lg" api:"required"`
Md string `json:"md" api:"required"`
Sm string `json:"sm" api:"required"`
Xl string `json:"xl" api:"required"`
Xs string `json:"xs" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Lg respjson.Field
Md respjson.Field
Sm respjson.Field
Xl respjson.Field
Xs respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r WebExtractStyleguideResponseStyleguideElementSpacing) RawJSON() string { return r.JSON.raw }
func (r *WebExtractStyleguideResponseStyleguideElementSpacing) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type WebExtractStyleguideResponseStyleguideFontLink struct {
// Upright font files keyed by weight string (e.g. "400" for regular, "500",
// "700"). Values are absolute URLs.
Files map[string]string `json:"files" api:"required"`
// Any of "google", "custom".
Type string `json:"type" api:"required"`
// Google Fonts category when type is google (e.g. sans-serif, serif, monospace,
// display, handwriting). Omitted for custom fonts when unknown.
Category string `json:"category"`
// Present when type is custom: human-readable name derived from the fontLinks key
// (strip build/hash suffixes, split camelCase / PascalCase, normalize separators).
// Google entries omit this.
DisplayName string `json:"displayName"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Files respjson.Field
Type respjson.Field
Category respjson.Field
DisplayName respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r WebExtractStyleguideResponseStyleguideFontLink) RawJSON() string { return r.JSON.raw }
func (r *WebExtractStyleguideResponseStyleguideFontLink) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Shadow styles used on the website
type WebExtractStyleguideResponseStyleguideShadows struct {
Inner string `json:"inner" api:"required"`
Lg string `json:"lg" api:"required"`
Md string `json:"md" api:"required"`
Sm string `json:"sm" api:"required"`
Xl string `json:"xl" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Inner respjson.Field
Lg respjson.Field
Md respjson.Field
Sm respjson.Field
Xl respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r WebExtractStyleguideResponseStyleguideShadows) RawJSON() string { return r.JSON.raw }
func (r *WebExtractStyleguideResponseStyleguideShadows) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Typography styles used on the website
type WebExtractStyleguideResponseStyleguideTypography struct {
// Heading styles
Headings WebExtractStyleguideResponseStyleguideTypographyHeadings `json:"headings" api:"required"`
P WebExtractStyleguideResponseStyleguideTypographyP `json:"p"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Headings respjson.Field
P respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r WebExtractStyleguideResponseStyleguideTypography) RawJSON() string { return r.JSON.raw }
func (r *WebExtractStyleguideResponseStyleguideTypography) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Heading styles
type WebExtractStyleguideResponseStyleguideTypographyHeadings struct {
H1 WebExtractStyleguideResponseStyleguideTypographyHeadingsH1 `json:"h1"`
H2 WebExtractStyleguideResponseStyleguideTypographyHeadingsH2 `json:"h2"`
H3 WebExtractStyleguideResponseStyleguideTypographyHeadingsH3 `json:"h3"`
H4 WebExtractStyleguideResponseStyleguideTypographyHeadingsH4 `json:"h4"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
H1 respjson.Field
H2 respjson.Field
H3 respjson.Field
H4 respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r WebExtractStyleguideResponseStyleguideTypographyHeadings) RawJSON() string { return r.JSON.raw }
func (r *WebExtractStyleguideResponseStyleguideTypographyHeadings) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type WebExtractStyleguideResponseStyleguideTypographyHeadingsH1 struct {
// Full ordered font list from resolved computed font-family
FontFallbacks []string `json:"fontFallbacks" api:"required"`
// Primary face (first family in the computed stack)
FontFamily string `json:"fontFamily" api:"required"`
FontSize string `json:"fontSize" api:"required"`
FontWeight float64 `json:"fontWeight" api:"required"`
LetterSpacing string `json:"letterSpacing" api:"required"`
LineHeight string `json:"lineHeight" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
FontFallbacks respjson.Field
FontFamily respjson.Field
FontSize respjson.Field
FontWeight respjson.Field
LetterSpacing respjson.Field
LineHeight respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r WebExtractStyleguideResponseStyleguideTypographyHeadingsH1) RawJSON() string {
return r.JSON.raw
}
func (r *WebExtractStyleguideResponseStyleguideTypographyHeadingsH1) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)