@getanyapi/sdk 0.16.1 → 0.17.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.
package/dist/index.cjs CHANGED
@@ -33,12 +33,16 @@ __export(index_exports, {
33
33
  BlueskyNamespace: () => BlueskyNamespace,
34
34
  BookingNamespace: () => BookingNamespace,
35
35
  CoinmarketcapNamespace: () => CoinmarketcapNamespace,
36
+ CompanyEnrichmentNamespace: () => CompanyEnrichmentNamespace,
37
+ CompanySearchNamespace: () => CompanySearchNamespace,
36
38
  CongressNamespace: () => CongressNamespace,
37
39
  ConnectionError: () => ConnectionError,
38
40
  DexscreenerNamespace: () => DexscreenerNamespace,
39
41
  DouyinNamespace: () => DouyinNamespace,
40
42
  EbayNamespace: () => EbayNamespace,
43
+ EmailFindingNamespace: () => EmailFindingNamespace,
41
44
  EmailNamespace: () => EmailNamespace,
45
+ EmailVerificationNamespace: () => EmailVerificationNamespace,
42
46
  FacebookNamespace: () => FacebookNamespace,
43
47
  FiverrNamespace: () => FiverrNamespace,
44
48
  GithubNamespace: () => GithubNamespace,
@@ -53,8 +57,11 @@ __export(index_exports, {
53
57
  InsufficientBalanceError: () => InsufficientBalanceError,
54
58
  LinkedinNamespace: () => LinkedinNamespace,
55
59
  MapsNamespace: () => MapsNamespace,
60
+ MobilePhoneNamespace: () => MobilePhoneNamespace,
56
61
  NotFoundError: () => NotFoundError,
57
62
  PandaexpressNamespace: () => PandaexpressNamespace,
63
+ PeopleSearchNamespace: () => PeopleSearchNamespace,
64
+ PersonEnrichmentNamespace: () => PersonEnrichmentNamespace,
58
65
  PersonNamespace: () => PersonNamespace,
59
66
  PinterestNamespace: () => PinterestNamespace,
60
67
  PlaystoreNamespace: () => PlaystoreNamespace,
@@ -64,6 +71,7 @@ __export(index_exports, {
64
71
  RedditNamespace: () => RedditNamespace,
65
72
  RedfinNamespace: () => RedfinNamespace,
66
73
  RednoteNamespace: () => RednoteNamespace,
74
+ RequestPendingError: () => RequestPendingError,
67
75
  ResultNotFoundError: () => ResultNotFoundError,
68
76
  SecNamespace: () => SecNamespace,
69
77
  SemrushNamespace: () => SemrushNamespace,
@@ -138,6 +146,13 @@ var ConnectionError = class extends AnyAPIError {
138
146
  };
139
147
  var TimeoutError = class extends AnyAPIError {
140
148
  };
149
+ var RequestPendingError = class extends TimeoutError {
150
+ durableRequestId;
151
+ constructor(requestId) {
152
+ super(`request is still running; resume with requests.get or requests.wait: ${requestId}`, 0, requestId);
153
+ this.durableRequestId = requestId;
154
+ }
155
+ };
141
156
  var REQUEST_ID_HEADERS = ["x-anyapi-request-id", "x-request-id"];
142
157
  function requestIdOf(headers) {
143
158
  for (const name of REQUEST_ID_HEADERS) {
@@ -695,9 +710,36 @@ var AnyAPI = class {
695
710
  * generated `AnyAPI` subclass adds typed literal-slug overloads on top (SPEC 2.1); this
696
711
  * base signature is the fallback that returns RunResult<unknown> for an unknown slug.
697
712
  */
698
- run(slug, input, options) {
713
+ async run(slug, input, options) {
714
+ const body = JSON.stringify(input ?? {});
715
+ const startedAt = Date.now();
716
+ const response = await this.request(
717
+ "POST",
718
+ buildUrl(this.baseUrl, slug, options),
719
+ {
720
+ body,
721
+ timeoutMs: options?.timeoutMs ?? this.timeoutMs,
722
+ maxRetries: options?.maxRetries ?? this.maxRetries,
723
+ maxInProgressWaitMs: options?.maxInProgressWaitMs ?? this.maxInProgressWaitMs,
724
+ ...options?.idempotencyKey !== void 0 ? { idempotencyKey: options.idempotencyKey } : {},
725
+ ...options?.signal ? { signal: options.signal } : {},
726
+ accept202: true
727
+ }
728
+ );
729
+ if (!isRequestSnapshot(response)) return response;
730
+ return this.waitRequest(response.requestId, {
731
+ initial: response,
732
+ timeoutMs: Math.max(
733
+ 0,
734
+ (options?.timeoutMs ?? this.timeoutMs) - (Date.now() - startedAt)
735
+ ),
736
+ ...options?.signal ? { signal: options.signal } : {}
737
+ });
738
+ }
739
+ /** Start durable work. A same-key completed replay returns its terminal result immediately. */
740
+ async start(slug, input, options) {
699
741
  const body = JSON.stringify(input ?? {});
700
- return this.request(
742
+ const response = await this.request(
701
743
  "POST",
702
744
  buildUrl(this.baseUrl, slug, options),
703
745
  {
@@ -706,8 +748,62 @@ var AnyAPI = class {
706
748
  maxRetries: options?.maxRetries ?? this.maxRetries,
707
749
  maxInProgressWaitMs: options?.maxInProgressWaitMs ?? this.maxInProgressWaitMs,
708
750
  ...options?.idempotencyKey !== void 0 ? { idempotencyKey: options.idempotencyKey } : {},
709
- ...options?.signal ? { signal: options.signal } : {}
751
+ ...options?.signal ? { signal: options.signal } : {},
752
+ headers: { Prefer: "respond-async" },
753
+ accept202: true
754
+ }
755
+ );
756
+ return response;
757
+ }
758
+ requests = {
759
+ get: (requestId) => this.getRequest(requestId),
760
+ wait: (requestId, options) => this.waitRequest(requestId, options)
761
+ };
762
+ getRequest(requestId, options) {
763
+ return this.httpGet(
764
+ `/v1/requests/${encodeURIComponent(requestId)}`,
765
+ options
766
+ );
767
+ }
768
+ async waitRequest(requestId, options) {
769
+ const timeoutMs = options?.timeoutMs ?? this.timeoutMs;
770
+ const deadline = Date.now() + timeoutMs;
771
+ const inspect = async () => {
772
+ const remaining = deadline - Date.now();
773
+ if (remaining <= 0) throw new RequestPendingError(requestId);
774
+ try {
775
+ return await this.getRequest(requestId, {
776
+ timeoutMs: remaining,
777
+ ...options?.signal ? { signal: options.signal } : {}
778
+ });
779
+ } catch (error) {
780
+ if (error instanceof TimeoutError)
781
+ throw new RequestPendingError(requestId);
782
+ throw error;
710
783
  }
784
+ };
785
+ let snapshot = options?.initial ?? await inspect();
786
+ while (snapshot.status === "queued" || snapshot.status === "running") {
787
+ const waitMs = Math.max(1, snapshot.retryAfterSeconds ?? 2) * 1e3;
788
+ if (Date.now() + waitMs > deadline)
789
+ throw new RequestPendingError(requestId);
790
+ await sleep(waitMs, options?.signal);
791
+ snapshot = await inspect();
792
+ }
793
+ if (snapshot.status === "succeeded" && snapshot.result)
794
+ return snapshot.result;
795
+ if (snapshot.resultExpired)
796
+ throw new AnyAPIError(
797
+ "request result expired",
798
+ 410,
799
+ requestId,
800
+ "result_expired"
801
+ );
802
+ throw new AnyAPIError(
803
+ `request ended with ${snapshot.error?.code ?? snapshot.status}`,
804
+ 502,
805
+ requestId,
806
+ snapshot.error?.code
711
807
  );
712
808
  }
713
809
  /** Current wallet balance in USD. GET /v1/balance. See SPEC 2.7. */
@@ -750,10 +846,11 @@ var AnyAPI = class {
750
846
  return mapCatalogDetail(raw);
751
847
  }
752
848
  /** Internal GET against the gateway with the same auth/retry/error machinery. */
753
- httpGet(path) {
849
+ httpGet(path, options) {
754
850
  return this.request("GET", `${this.gatewayBaseUrl}${path}`, {
755
- timeoutMs: this.timeoutMs,
756
- maxRetries: this.maxRetries
851
+ timeoutMs: options?.timeoutMs ?? this.timeoutMs,
852
+ maxRetries: this.maxRetries,
853
+ ...options?.signal ? { signal: options.signal } : {}
757
854
  });
758
855
  }
759
856
  /**
@@ -770,6 +867,7 @@ var AnyAPI = class {
770
867
  if (this.apiKey) {
771
868
  headers["Authorization"] = `Bearer ${this.apiKey}`;
772
869
  }
870
+ Object.assign(headers, opts.headers);
773
871
  const billedPost = method === "POST" && opts.body !== void 0;
774
872
  if (billedPost && this.idempotency === "auto") {
775
873
  const key = opts.idempotencyKey ?? generateIdempotencyKey();
@@ -816,7 +914,7 @@ var AnyAPI = class {
816
914
  throw connErr;
817
915
  }
818
916
  const requestId = requestIdOf(response.headers);
819
- if (response.status === 200) {
917
+ if (response.status === 200 || opts.accept202 && response.status === 202) {
820
918
  const text = await response.text();
821
919
  try {
822
920
  return JSON.parse(text);
@@ -830,7 +928,9 @@ var AnyAPI = class {
830
928
  }
831
929
  const body = await response.text().catch(() => "");
832
930
  const { message, code } = messageFromBody(body, response.status);
833
- const retryAfterMs = parseRetryAfterMs(response.headers.get("retry-after"));
931
+ const retryAfterMs = parseRetryAfterMs(
932
+ response.headers.get("retry-after")
933
+ );
834
934
  if (response.status === 429 && attempt < opts.maxRetries) {
835
935
  const delay = retryAfterMs !== void 0 ? Math.min(retryAfterMs, RETRY_MAX_DELAY_MS) : backoffDelay(attempt);
836
936
  await sleep(delay, opts.signal);
@@ -860,6 +960,9 @@ var AnyAPI = class {
860
960
  return this.timeoutMs;
861
961
  }
862
962
  };
963
+ function isRequestSnapshot(value) {
964
+ return "requestId" in value && "status" in value;
965
+ }
863
966
 
864
967
  // src/core/types.ts
865
968
  var OUTPUT_NOT_RETAINED = "the run output was not retained: this response is an idempotent replay whose stored payload has expired or was too large to store, so only the run metadata came back. Re-run the request without the idempotency key (or with a fresh one) to fetch the data again.";
@@ -1360,6 +1463,71 @@ var CoinmarketcapNamespace = class {
1360
1463
  }
1361
1464
  };
1362
1465
 
1466
+ // src/generated/platforms/company_enrichment.ts
1467
+ var CompanyEnrichmentNamespace = class {
1468
+ constructor(_core) {
1469
+ this._core = _core;
1470
+ }
1471
+ _core;
1472
+ /**
1473
+ * Company Enrichment - Crustdata v3
1474
+ *
1475
+ * Enrich a company by domain, name, LinkedIn URL, or Crustdata identifier.
1476
+ *
1477
+ * Price: $0.0972 per request.
1478
+ */
1479
+ crustdataV3(input, options) {
1480
+ return this._core.run("company_enrichment.crustdata_v3", input, options);
1481
+ }
1482
+ };
1483
+
1484
+ // src/generated/platforms/company_search.ts
1485
+ var CompanySearchNamespace = class {
1486
+ constructor(_core) {
1487
+ this._core = _core;
1488
+ }
1489
+ _core;
1490
+ /**
1491
+ * Company Search - AI Ark
1492
+ *
1493
+ * Search companies by name, lookalike domains, account filters, and saved-list filters.
1494
+ *
1495
+ * Price: $0 per request plus $0.0024 per result (maximum $0.24).
1496
+ *
1497
+ * @example
1498
+ * const res = await client.companySearch.aiArk({ name: "OpenAI", page: 0, size: 1 });
1499
+ */
1500
+ aiArk(input, options) {
1501
+ return this._core.run("company_search.ai_ark", input, options);
1502
+ }
1503
+ /**
1504
+ * Company Search - Crustdata v3
1505
+ *
1506
+ * Search companies by structured filters with cursor pagination.
1507
+ *
1508
+ * Price: $0 per request plus $0.048 per result (maximum $48).
1509
+ */
1510
+ crustdataV3(input, options) {
1511
+ return this._core.run("company_search.crustdata_v3", input, options);
1512
+ }
1513
+ /**
1514
+ * Iterate every result of Company Search - Crustdata v3 across pages.
1515
+ *
1516
+ * Yields items directly; call `.pages()` on the return value to walk whole
1517
+ * result pages instead (each carries its own costUsd).
1518
+ */
1519
+ iterCrustdataV3(input, options) {
1520
+ return paginate(
1521
+ this._core,
1522
+ "company_search.crustdata_v3",
1523
+ input,
1524
+ "companies",
1525
+ false,
1526
+ options
1527
+ );
1528
+ }
1529
+ };
1530
+
1363
1531
  // src/generated/platforms/congress.ts
1364
1532
  var CongressNamespace = class {
1365
1533
  constructor(_core) {
@@ -1543,6 +1711,78 @@ var EmailNamespace = class {
1543
1711
  }
1544
1712
  };
1545
1713
 
1714
+ // src/generated/platforms/email_finding.ts
1715
+ var EmailFindingNamespace = class {
1716
+ constructor(_core) {
1717
+ this._core = _core;
1718
+ }
1719
+ _core;
1720
+ /**
1721
+ * Email Finding - DropLeads
1722
+ *
1723
+ * Find a professional email from a person's name and company domain or company name.
1724
+ *
1725
+ * Price: $0.0312 per request.
1726
+ *
1727
+ * @example
1728
+ * const res = await client.emailFinding.dropleads({ firstName: "Tim", lastName: "Zheng", companyDomain: "apollo.io" });
1729
+ */
1730
+ dropleads(input, options) {
1731
+ return this._core.run("email_finding.dropleads", input, options);
1732
+ }
1733
+ /**
1734
+ * Email Finding - Icypeas
1735
+ *
1736
+ * Find a professional email from a person and company through the durable Request lifecycle.
1737
+ *
1738
+ * Price: $0.0168 per request.
1739
+ */
1740
+ icypeas(input, options) {
1741
+ return this._core.run("email_finding.icypeas", input, options);
1742
+ }
1743
+ };
1744
+
1745
+ // src/generated/platforms/email_verification.ts
1746
+ var EmailVerificationNamespace = class {
1747
+ constructor(_core) {
1748
+ this._core = _core;
1749
+ }
1750
+ _core;
1751
+ /**
1752
+ * Email Verification - Allegrow
1753
+ *
1754
+ * Validate an email address and return its deliverability verdict and mailbox signals.
1755
+ *
1756
+ * Price: $0.0144 per request.
1757
+ *
1758
+ * @example
1759
+ * const res = await client.emailVerification.allegrow({ email: "tim@apollo.io" });
1760
+ */
1761
+ allegrow(input, options) {
1762
+ return this._core.run("email_verification.allegrow", input, options);
1763
+ }
1764
+ /**
1765
+ * Email Verification - BounceBan
1766
+ *
1767
+ * Verify an email address, including catch-all handling. Completion uses the durable Request lifecycle; a negative verdict is a successful result.
1768
+ *
1769
+ * Price: $0.0072 per request.
1770
+ */
1771
+ bounceban(input, options) {
1772
+ return this._core.run("email_verification.bounceban", input, options);
1773
+ }
1774
+ /**
1775
+ * Email Verification - Icypeas
1776
+ *
1777
+ * Verify an email address. A valid negative verdict is a successful, billable result.
1778
+ *
1779
+ * Price: $0.0024 per request.
1780
+ */
1781
+ icypeas(input, options) {
1782
+ return this._core.run("email_verification.icypeas", input, options);
1783
+ }
1784
+ };
1785
+
1546
1786
  // src/generated/platforms/facebook.ts
1547
1787
  var FacebookNamespace = class {
1548
1788
  constructor(_core) {
@@ -3455,6 +3695,37 @@ var MapsNamespace = class {
3455
3695
  }
3456
3696
  };
3457
3697
 
3698
+ // src/generated/platforms/mobile_phone.ts
3699
+ var MobilePhoneNamespace = class {
3700
+ constructor(_core) {
3701
+ this._core = _core;
3702
+ }
3703
+ _core;
3704
+ /**
3705
+ * Mobile Phone - AI Ark
3706
+ *
3707
+ * Find a person's mobile phone from a LinkedIn URL or from a domain and full name.
3708
+ *
3709
+ * Price: $0.084 per request.
3710
+ *
3711
+ * @example
3712
+ * const res = await client.mobilePhone.aiArk({ linkedinUrl: "https://www.linkedin.com/in/tim-zheng" });
3713
+ */
3714
+ aiArk(input, options) {
3715
+ return this._core.run("mobile_phone.ai_ark", input, options);
3716
+ }
3717
+ /**
3718
+ * Mobile Phone - LeadMagic
3719
+ *
3720
+ * Find a person's mobile phone from a profile URL or email. No-match responses are not billed.
3721
+ *
3722
+ * Price: $0.2016 per request.
3723
+ */
3724
+ leadmagic(input, options) {
3725
+ return this._core.run("mobile_phone.leadmagic", input, options);
3726
+ }
3727
+ };
3728
+
3458
3729
  // src/generated/platforms/pandaexpress.ts
3459
3730
  var PandaexpressNamespace = class {
3460
3731
  constructor(_core) {
@@ -3502,6 +3773,37 @@ var PandaexpressNamespace = class {
3502
3773
  }
3503
3774
  };
3504
3775
 
3776
+ // src/generated/platforms/people_search.ts
3777
+ var PeopleSearchNamespace = class {
3778
+ constructor(_core) {
3779
+ this._core = _core;
3780
+ }
3781
+ _core;
3782
+ /**
3783
+ * People Search - AI Ark
3784
+ *
3785
+ * Search professional profiles with account, contact, and saved-list filters.
3786
+ *
3787
+ * Price: $0 per request plus $0.0084 per result (maximum $0.84).
3788
+ *
3789
+ * @example
3790
+ * const res = await client.peopleSearch.aiArk({ page: 0, size: 1 });
3791
+ */
3792
+ aiArk(input, options) {
3793
+ return this._core.run("people_search.ai_ark", input, options);
3794
+ }
3795
+ /**
3796
+ * People Search - Crustdata v3
3797
+ *
3798
+ * Find up to 100 professional profiles by company domain and title keywords.
3799
+ *
3800
+ * Price: $0.144 per request.
3801
+ */
3802
+ crustdataV3(input, options) {
3803
+ return this._core.run("people_search.crustdata_v3", input, options);
3804
+ }
3805
+ };
3806
+
3505
3807
  // src/generated/platforms/person.ts
3506
3808
  var PersonNamespace = class {
3507
3809
  constructor(_core) {
@@ -3523,6 +3825,24 @@ var PersonNamespace = class {
3523
3825
  }
3524
3826
  };
3525
3827
 
3828
+ // src/generated/platforms/person_enrichment.ts
3829
+ var PersonEnrichmentNamespace = class {
3830
+ constructor(_core) {
3831
+ this._core = _core;
3832
+ }
3833
+ _core;
3834
+ /**
3835
+ * Person Enrichment - Aviato
3836
+ *
3837
+ * Enrich a person from an Aviato or LinkedIn identifier, LinkedIn URL, or email.
3838
+ *
3839
+ * Price: $0.084 per request.
3840
+ */
3841
+ aviato(input, options) {
3842
+ return this._core.run("person_enrichment.aviato", input, options);
3843
+ }
3844
+ };
3845
+
3526
3846
  // src/generated/platforms/pinterest.ts
3527
3847
  var PinterestNamespace = class {
3528
3848
  constructor(_core) {
@@ -6143,6 +6463,20 @@ var AnyAPI2 = class extends AnyAPI {
6143
6463
  this._core
6144
6464
  );
6145
6465
  }
6466
+ /**
6467
+ * Typed methods for the company_enrichment platform.
6468
+ */
6469
+ get companyEnrichment() {
6470
+ return this._namespaces["companyEnrichment"] ??= new CompanyEnrichmentNamespace(this._core);
6471
+ }
6472
+ /**
6473
+ * Typed methods for the company_search platform.
6474
+ */
6475
+ get companySearch() {
6476
+ return this._namespaces["companySearch"] ??= new CompanySearchNamespace(
6477
+ this._core
6478
+ );
6479
+ }
6146
6480
  /**
6147
6481
  * Typed methods for the congress platform.
6148
6482
  */
@@ -6183,6 +6517,20 @@ var AnyAPI2 = class extends AnyAPI {
6183
6517
  this._core
6184
6518
  );
6185
6519
  }
6520
+ /**
6521
+ * Typed methods for the email_finding platform.
6522
+ */
6523
+ get emailFinding() {
6524
+ return this._namespaces["emailFinding"] ??= new EmailFindingNamespace(
6525
+ this._core
6526
+ );
6527
+ }
6528
+ /**
6529
+ * Typed methods for the email_verification platform.
6530
+ */
6531
+ get emailVerification() {
6532
+ return this._namespaces["emailVerification"] ??= new EmailVerificationNamespace(this._core);
6533
+ }
6186
6534
  /**
6187
6535
  * Typed methods for the facebook platform.
6188
6536
  */
@@ -6287,6 +6635,14 @@ var AnyAPI2 = class extends AnyAPI {
6287
6635
  this._core
6288
6636
  );
6289
6637
  }
6638
+ /**
6639
+ * Typed methods for the mobile_phone platform.
6640
+ */
6641
+ get mobilePhone() {
6642
+ return this._namespaces["mobilePhone"] ??= new MobilePhoneNamespace(
6643
+ this._core
6644
+ );
6645
+ }
6290
6646
  /**
6291
6647
  * Typed methods for the pandaexpress platform.
6292
6648
  */
@@ -6295,6 +6651,14 @@ var AnyAPI2 = class extends AnyAPI {
6295
6651
  this._core
6296
6652
  );
6297
6653
  }
6654
+ /**
6655
+ * Typed methods for the people_search platform.
6656
+ */
6657
+ get peopleSearch() {
6658
+ return this._namespaces["peopleSearch"] ??= new PeopleSearchNamespace(
6659
+ this._core
6660
+ );
6661
+ }
6298
6662
  /**
6299
6663
  * Typed methods for the person platform.
6300
6664
  */
@@ -6303,6 +6667,12 @@ var AnyAPI2 = class extends AnyAPI {
6303
6667
  this._core
6304
6668
  );
6305
6669
  }
6670
+ /**
6671
+ * Typed methods for the person_enrichment platform.
6672
+ */
6673
+ get personEnrichment() {
6674
+ return this._namespaces["personEnrichment"] ??= new PersonEnrichmentNamespace(this._core);
6675
+ }
6306
6676
  /**
6307
6677
  * Typed methods for the pinterest platform.
6308
6678
  */
@@ -6559,12 +6929,16 @@ var AnyAPI2 = class extends AnyAPI {
6559
6929
  BlueskyNamespace,
6560
6930
  BookingNamespace,
6561
6931
  CoinmarketcapNamespace,
6932
+ CompanyEnrichmentNamespace,
6933
+ CompanySearchNamespace,
6562
6934
  CongressNamespace,
6563
6935
  ConnectionError,
6564
6936
  DexscreenerNamespace,
6565
6937
  DouyinNamespace,
6566
6938
  EbayNamespace,
6939
+ EmailFindingNamespace,
6567
6940
  EmailNamespace,
6941
+ EmailVerificationNamespace,
6568
6942
  FacebookNamespace,
6569
6943
  FiverrNamespace,
6570
6944
  GithubNamespace,
@@ -6579,8 +6953,11 @@ var AnyAPI2 = class extends AnyAPI {
6579
6953
  InsufficientBalanceError,
6580
6954
  LinkedinNamespace,
6581
6955
  MapsNamespace,
6956
+ MobilePhoneNamespace,
6582
6957
  NotFoundError,
6583
6958
  PandaexpressNamespace,
6959
+ PeopleSearchNamespace,
6960
+ PersonEnrichmentNamespace,
6584
6961
  PersonNamespace,
6585
6962
  PinterestNamespace,
6586
6963
  PlaystoreNamespace,
@@ -6590,6 +6967,7 @@ var AnyAPI2 = class extends AnyAPI {
6590
6967
  RedditNamespace,
6591
6968
  RedfinNamespace,
6592
6969
  RednoteNamespace,
6970
+ RequestPendingError,
6593
6971
  ResultNotFoundError,
6594
6972
  SecNamespace,
6595
6973
  SemrushNamespace,