@getanyapi/sdk 0.16.1 → 0.18.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.
package/dist/index.js CHANGED
@@ -40,6 +40,13 @@ var ConnectionError = class extends AnyAPIError {
40
40
  };
41
41
  var TimeoutError = class extends AnyAPIError {
42
42
  };
43
+ var RequestPendingError = class extends TimeoutError {
44
+ durableRequestId;
45
+ constructor(requestId) {
46
+ super(`request is still running; resume with requests.get or requests.wait: ${requestId}`, 0, requestId);
47
+ this.durableRequestId = requestId;
48
+ }
49
+ };
43
50
  var REQUEST_ID_HEADERS = ["x-anyapi-request-id", "x-request-id"];
44
51
  function requestIdOf(headers) {
45
52
  for (const name of REQUEST_ID_HEADERS) {
@@ -597,9 +604,36 @@ var AnyAPI = class {
597
604
  * generated `AnyAPI` subclass adds typed literal-slug overloads on top (SPEC 2.1); this
598
605
  * base signature is the fallback that returns RunResult<unknown> for an unknown slug.
599
606
  */
600
- run(slug, input, options) {
607
+ async run(slug, input, options) {
608
+ const body = JSON.stringify(input ?? {});
609
+ const startedAt = Date.now();
610
+ const response = await this.request(
611
+ "POST",
612
+ buildUrl(this.baseUrl, slug, options),
613
+ {
614
+ body,
615
+ timeoutMs: options?.timeoutMs ?? this.timeoutMs,
616
+ maxRetries: options?.maxRetries ?? this.maxRetries,
617
+ maxInProgressWaitMs: options?.maxInProgressWaitMs ?? this.maxInProgressWaitMs,
618
+ ...options?.idempotencyKey !== void 0 ? { idempotencyKey: options.idempotencyKey } : {},
619
+ ...options?.signal ? { signal: options.signal } : {},
620
+ accept202: true
621
+ }
622
+ );
623
+ if (!isRequestSnapshot(response)) return response;
624
+ return this.waitRequest(response.requestId, {
625
+ initial: response,
626
+ timeoutMs: Math.max(
627
+ 0,
628
+ (options?.timeoutMs ?? this.timeoutMs) - (Date.now() - startedAt)
629
+ ),
630
+ ...options?.signal ? { signal: options.signal } : {}
631
+ });
632
+ }
633
+ /** Start durable work. A same-key completed replay returns its terminal result immediately. */
634
+ async start(slug, input, options) {
601
635
  const body = JSON.stringify(input ?? {});
602
- return this.request(
636
+ const response = await this.request(
603
637
  "POST",
604
638
  buildUrl(this.baseUrl, slug, options),
605
639
  {
@@ -608,9 +642,63 @@ var AnyAPI = class {
608
642
  maxRetries: options?.maxRetries ?? this.maxRetries,
609
643
  maxInProgressWaitMs: options?.maxInProgressWaitMs ?? this.maxInProgressWaitMs,
610
644
  ...options?.idempotencyKey !== void 0 ? { idempotencyKey: options.idempotencyKey } : {},
611
- ...options?.signal ? { signal: options.signal } : {}
645
+ ...options?.signal ? { signal: options.signal } : {},
646
+ headers: { Prefer: "respond-async" },
647
+ accept202: true
612
648
  }
613
649
  );
650
+ return response;
651
+ }
652
+ requests = {
653
+ get: (requestId) => this.getRequest(requestId),
654
+ wait: (requestId, options) => this.waitRequest(requestId, options)
655
+ };
656
+ getRequest(requestId, options) {
657
+ return this.httpGet(
658
+ `/v1/requests/${encodeURIComponent(requestId)}`,
659
+ options
660
+ );
661
+ }
662
+ async waitRequest(requestId, options) {
663
+ const timeoutMs = options?.timeoutMs ?? this.timeoutMs;
664
+ const deadline = Date.now() + timeoutMs;
665
+ const inspect = async () => {
666
+ const remaining = deadline - Date.now();
667
+ if (remaining <= 0) throw new RequestPendingError(requestId);
668
+ try {
669
+ return await this.getRequest(requestId, {
670
+ timeoutMs: remaining,
671
+ ...options?.signal ? { signal: options.signal } : {}
672
+ });
673
+ } catch (error) {
674
+ if (error instanceof TimeoutError)
675
+ throw new RequestPendingError(requestId);
676
+ throw error;
677
+ }
678
+ };
679
+ let snapshot = options?.initial ?? await inspect();
680
+ while (snapshot.status === "queued" || snapshot.status === "running") {
681
+ const waitMs = Math.max(1, snapshot.retryAfterSeconds ?? 2) * 1e3;
682
+ if (Date.now() + waitMs > deadline)
683
+ throw new RequestPendingError(requestId);
684
+ await sleep(waitMs, options?.signal);
685
+ snapshot = await inspect();
686
+ }
687
+ if (snapshot.status === "succeeded" && snapshot.result)
688
+ return snapshot.result;
689
+ if (snapshot.resultExpired)
690
+ throw new AnyAPIError(
691
+ "request result expired",
692
+ 410,
693
+ requestId,
694
+ "result_expired"
695
+ );
696
+ throw new AnyAPIError(
697
+ `request ended with ${snapshot.error?.code ?? snapshot.status}`,
698
+ 502,
699
+ requestId,
700
+ snapshot.error?.code
701
+ );
614
702
  }
615
703
  /** Current wallet balance in USD. GET /v1/balance. See SPEC 2.7. */
616
704
  balance() {
@@ -652,10 +740,11 @@ var AnyAPI = class {
652
740
  return mapCatalogDetail(raw);
653
741
  }
654
742
  /** Internal GET against the gateway with the same auth/retry/error machinery. */
655
- httpGet(path) {
743
+ httpGet(path, options) {
656
744
  return this.request("GET", `${this.gatewayBaseUrl}${path}`, {
657
- timeoutMs: this.timeoutMs,
658
- maxRetries: this.maxRetries
745
+ timeoutMs: options?.timeoutMs ?? this.timeoutMs,
746
+ maxRetries: this.maxRetries,
747
+ ...options?.signal ? { signal: options.signal } : {}
659
748
  });
660
749
  }
661
750
  /**
@@ -672,6 +761,7 @@ var AnyAPI = class {
672
761
  if (this.apiKey) {
673
762
  headers["Authorization"] = `Bearer ${this.apiKey}`;
674
763
  }
764
+ Object.assign(headers, opts.headers);
675
765
  const billedPost = method === "POST" && opts.body !== void 0;
676
766
  if (billedPost && this.idempotency === "auto") {
677
767
  const key = opts.idempotencyKey ?? generateIdempotencyKey();
@@ -718,7 +808,7 @@ var AnyAPI = class {
718
808
  throw connErr;
719
809
  }
720
810
  const requestId = requestIdOf(response.headers);
721
- if (response.status === 200) {
811
+ if (response.status === 200 || opts.accept202 && response.status === 202) {
722
812
  const text = await response.text();
723
813
  try {
724
814
  return JSON.parse(text);
@@ -732,7 +822,9 @@ var AnyAPI = class {
732
822
  }
733
823
  const body = await response.text().catch(() => "");
734
824
  const { message, code } = messageFromBody(body, response.status);
735
- const retryAfterMs = parseRetryAfterMs(response.headers.get("retry-after"));
825
+ const retryAfterMs = parseRetryAfterMs(
826
+ response.headers.get("retry-after")
827
+ );
736
828
  if (response.status === 429 && attempt < opts.maxRetries) {
737
829
  const delay = retryAfterMs !== void 0 ? Math.min(retryAfterMs, RETRY_MAX_DELAY_MS) : backoffDelay(attempt);
738
830
  await sleep(delay, opts.signal);
@@ -762,6 +854,9 @@ var AnyAPI = class {
762
854
  return this.timeoutMs;
763
855
  }
764
856
  };
857
+ function isRequestSnapshot(value) {
858
+ return "requestId" in value && "status" in value;
859
+ }
765
860
 
766
861
  // src/core/types.ts
767
862
  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.";
@@ -1262,6 +1357,71 @@ var CoinmarketcapNamespace = class {
1262
1357
  }
1263
1358
  };
1264
1359
 
1360
+ // src/generated/platforms/company_enrichment.ts
1361
+ var CompanyEnrichmentNamespace = class {
1362
+ constructor(_core) {
1363
+ this._core = _core;
1364
+ }
1365
+ _core;
1366
+ /**
1367
+ * Company Enrichment - Crustdata v3
1368
+ *
1369
+ * Enrich a company by domain, name, LinkedIn URL, or Crustdata identifier.
1370
+ *
1371
+ * Price: $0.0972 per request.
1372
+ */
1373
+ crustdataV3(input, options) {
1374
+ return this._core.run("company_enrichment.crustdata_v3", input, options);
1375
+ }
1376
+ };
1377
+
1378
+ // src/generated/platforms/company_search.ts
1379
+ var CompanySearchNamespace = class {
1380
+ constructor(_core) {
1381
+ this._core = _core;
1382
+ }
1383
+ _core;
1384
+ /**
1385
+ * Company Search - AI Ark
1386
+ *
1387
+ * Search companies by name, lookalike domains, account filters, and saved-list filters.
1388
+ *
1389
+ * Price: $0 per request plus $0.0024 per result (maximum $0.24).
1390
+ *
1391
+ * @example
1392
+ * const res = await client.companySearch.aiArk({ name: "OpenAI", page: 0, size: 1 });
1393
+ */
1394
+ aiArk(input, options) {
1395
+ return this._core.run("company_search.ai_ark", input, options);
1396
+ }
1397
+ /**
1398
+ * Company Search - Crustdata v3
1399
+ *
1400
+ * Search companies by structured filters with cursor pagination.
1401
+ *
1402
+ * Price: $0 per request plus $0.048 per result (maximum $48).
1403
+ */
1404
+ crustdataV3(input, options) {
1405
+ return this._core.run("company_search.crustdata_v3", input, options);
1406
+ }
1407
+ /**
1408
+ * Iterate every result of Company Search - Crustdata v3 across pages.
1409
+ *
1410
+ * Yields items directly; call `.pages()` on the return value to walk whole
1411
+ * result pages instead (each carries its own costUsd).
1412
+ */
1413
+ iterCrustdataV3(input, options) {
1414
+ return paginate(
1415
+ this._core,
1416
+ "company_search.crustdata_v3",
1417
+ input,
1418
+ "companies",
1419
+ false,
1420
+ options
1421
+ );
1422
+ }
1423
+ };
1424
+
1265
1425
  // src/generated/platforms/congress.ts
1266
1426
  var CongressNamespace = class {
1267
1427
  constructor(_core) {
@@ -1445,6 +1605,84 @@ var EmailNamespace = class {
1445
1605
  }
1446
1606
  };
1447
1607
 
1608
+ // src/generated/platforms/email_finding.ts
1609
+ var EmailFindingNamespace = class {
1610
+ constructor(_core) {
1611
+ this._core = _core;
1612
+ }
1613
+ _core;
1614
+ /**
1615
+ * Email Finding - DropLeads
1616
+ *
1617
+ * Find a professional email from a person's name and company domain or company name.
1618
+ *
1619
+ * Price: $0.0312 per request.
1620
+ *
1621
+ * @example
1622
+ * const res = await client.emailFinding.dropleads({ firstName: "Tim", lastName: "Zheng", companyDomain: "apollo.io" });
1623
+ */
1624
+ dropleads(input, options) {
1625
+ return this._core.run("email_finding.dropleads", input, options);
1626
+ }
1627
+ /**
1628
+ * Email Finding - Icypeas
1629
+ *
1630
+ * Find a professional email from a person and company through the durable Request lifecycle.
1631
+ *
1632
+ * Price: $0.0168 per request.
1633
+ *
1634
+ * @example
1635
+ * const res = await client.emailFinding.icypeas({ domainOrCompany: "apollo.io", firstname: "Tim", lastname: "Zheng" });
1636
+ */
1637
+ icypeas(input, options) {
1638
+ return this._core.run("email_finding.icypeas", input, options);
1639
+ }
1640
+ };
1641
+
1642
+ // src/generated/platforms/email_verification.ts
1643
+ var EmailVerificationNamespace = class {
1644
+ constructor(_core) {
1645
+ this._core = _core;
1646
+ }
1647
+ _core;
1648
+ /**
1649
+ * Email Verification - Allegrow
1650
+ *
1651
+ * Validate an email address and return its deliverability verdict and mailbox signals.
1652
+ *
1653
+ * Price: $0.0144 per request.
1654
+ *
1655
+ * @example
1656
+ * const res = await client.emailVerification.allegrow({ email: "tim@apollo.io" });
1657
+ */
1658
+ allegrow(input, options) {
1659
+ return this._core.run("email_verification.allegrow", input, options);
1660
+ }
1661
+ /**
1662
+ * Email Verification - BounceBan
1663
+ *
1664
+ * Verify an email address, including catch-all handling. Completion uses the durable Request lifecycle; a negative verdict is a successful result.
1665
+ *
1666
+ * Price: $0.0072 per request.
1667
+ *
1668
+ * @example
1669
+ * const res = await client.emailVerification.bounceban({ email: "tim@apollo.io", mode: "regular" });
1670
+ */
1671
+ bounceban(input, options) {
1672
+ return this._core.run("email_verification.bounceban", input, options);
1673
+ }
1674
+ /**
1675
+ * Email Verification - Icypeas
1676
+ *
1677
+ * Verify an email address. A valid negative verdict is a successful, billable result.
1678
+ *
1679
+ * Price: $0.0024 per request.
1680
+ */
1681
+ icypeas(input, options) {
1682
+ return this._core.run("email_verification.icypeas", input, options);
1683
+ }
1684
+ };
1685
+
1448
1686
  // src/generated/platforms/facebook.ts
1449
1687
  var FacebookNamespace = class {
1450
1688
  constructor(_core) {
@@ -3357,6 +3595,37 @@ var MapsNamespace = class {
3357
3595
  }
3358
3596
  };
3359
3597
 
3598
+ // src/generated/platforms/mobile_phone.ts
3599
+ var MobilePhoneNamespace = class {
3600
+ constructor(_core) {
3601
+ this._core = _core;
3602
+ }
3603
+ _core;
3604
+ /**
3605
+ * Mobile Phone - AI Ark
3606
+ *
3607
+ * Find a person's mobile phone from a LinkedIn URL or from a domain and full name.
3608
+ *
3609
+ * Price: $0.084 per request.
3610
+ *
3611
+ * @example
3612
+ * const res = await client.mobilePhone.aiArk({ linkedinUrl: "https://www.linkedin.com/in/tim-zheng" });
3613
+ */
3614
+ aiArk(input, options) {
3615
+ return this._core.run("mobile_phone.ai_ark", input, options);
3616
+ }
3617
+ /**
3618
+ * Mobile Phone - LeadMagic
3619
+ *
3620
+ * Find a person's mobile phone from a profile URL or email. No-match responses are not billed.
3621
+ *
3622
+ * Price: $0.2016 per request.
3623
+ */
3624
+ leadmagic(input, options) {
3625
+ return this._core.run("mobile_phone.leadmagic", input, options);
3626
+ }
3627
+ };
3628
+
3360
3629
  // src/generated/platforms/pandaexpress.ts
3361
3630
  var PandaexpressNamespace = class {
3362
3631
  constructor(_core) {
@@ -3404,6 +3673,37 @@ var PandaexpressNamespace = class {
3404
3673
  }
3405
3674
  };
3406
3675
 
3676
+ // src/generated/platforms/people_search.ts
3677
+ var PeopleSearchNamespace = class {
3678
+ constructor(_core) {
3679
+ this._core = _core;
3680
+ }
3681
+ _core;
3682
+ /**
3683
+ * People Search - AI Ark
3684
+ *
3685
+ * Search professional profiles with account, contact, and saved-list filters.
3686
+ *
3687
+ * Price: $0 per request plus $0.0084 per result (maximum $0.84).
3688
+ *
3689
+ * @example
3690
+ * const res = await client.peopleSearch.aiArk({ page: 0, size: 1 });
3691
+ */
3692
+ aiArk(input, options) {
3693
+ return this._core.run("people_search.ai_ark", input, options);
3694
+ }
3695
+ /**
3696
+ * People Search - Crustdata v3
3697
+ *
3698
+ * Find up to 100 professional profiles by company domain and title keywords.
3699
+ *
3700
+ * Price: $0.144 per request.
3701
+ */
3702
+ crustdataV3(input, options) {
3703
+ return this._core.run("people_search.crustdata_v3", input, options);
3704
+ }
3705
+ };
3706
+
3407
3707
  // src/generated/platforms/person.ts
3408
3708
  var PersonNamespace = class {
3409
3709
  constructor(_core) {
@@ -3425,6 +3725,24 @@ var PersonNamespace = class {
3425
3725
  }
3426
3726
  };
3427
3727
 
3728
+ // src/generated/platforms/person_enrichment.ts
3729
+ var PersonEnrichmentNamespace = class {
3730
+ constructor(_core) {
3731
+ this._core = _core;
3732
+ }
3733
+ _core;
3734
+ /**
3735
+ * Person Enrichment - Aviato
3736
+ *
3737
+ * Enrich a person from an Aviato or LinkedIn identifier, LinkedIn URL, or email.
3738
+ *
3739
+ * Price: $0.084 per request.
3740
+ */
3741
+ aviato(input, options) {
3742
+ return this._core.run("person_enrichment.aviato", input, options);
3743
+ }
3744
+ };
3745
+
3428
3746
  // src/generated/platforms/pinterest.ts
3429
3747
  var PinterestNamespace = class {
3430
3748
  constructor(_core) {
@@ -5132,12 +5450,12 @@ var TwitterNamespace = class {
5132
5450
  /**
5133
5451
  * X / Twitter Post Replies
5134
5452
  *
5135
- * Fetch the replies to any X (Twitter) post URL as structured records: author, text, and engagement.
5453
+ * Fetch the replies to any X (Twitter) post URL as structured records: author, text, and engagement. An empty result is valid and does not assert whether the target post exists.
5136
5454
  *
5137
- * Price: $0.00018 per request plus $0.00018 per result (maximum $0.00666).
5455
+ * Price: $0.00075 per request.
5138
5456
  *
5139
5457
  * @example
5140
- * const res = await client.twitter.replies({ url: "https://x.com/jack/status/20", limit: 3 });
5458
+ * const res = await client.twitter.replies({ url: "https://x.com/jack/status/20" });
5141
5459
  */
5142
5460
  replies(input, options) {
5143
5461
  return this._core.run("twitter.replies", input, options);
@@ -5171,6 +5489,19 @@ var TwitterNamespace = class {
5171
5489
  options
5172
5490
  );
5173
5491
  }
5492
+ /**
5493
+ * X / Twitter Tweet Thread
5494
+ *
5495
+ * Resolve the linear self-thread containing an X (Twitter) post, from its root through the author's linked continuations. This excludes replies from other users.
5496
+ *
5497
+ * Price: $0.005 per request.
5498
+ *
5499
+ * @example
5500
+ * const res = await client.twitter.thread({ url: "https://x.com/SpaceX/status/1732824684683784516" });
5501
+ */
5502
+ thread(input, options) {
5503
+ return this._core.run("twitter.thread", input, options);
5504
+ }
5174
5505
  /**
5175
5506
  * X / Twitter Trends
5176
5507
  *
@@ -6045,6 +6376,20 @@ var AnyAPI2 = class extends AnyAPI {
6045
6376
  this._core
6046
6377
  );
6047
6378
  }
6379
+ /**
6380
+ * Typed methods for the company_enrichment platform.
6381
+ */
6382
+ get companyEnrichment() {
6383
+ return this._namespaces["companyEnrichment"] ??= new CompanyEnrichmentNamespace(this._core);
6384
+ }
6385
+ /**
6386
+ * Typed methods for the company_search platform.
6387
+ */
6388
+ get companySearch() {
6389
+ return this._namespaces["companySearch"] ??= new CompanySearchNamespace(
6390
+ this._core
6391
+ );
6392
+ }
6048
6393
  /**
6049
6394
  * Typed methods for the congress platform.
6050
6395
  */
@@ -6085,6 +6430,20 @@ var AnyAPI2 = class extends AnyAPI {
6085
6430
  this._core
6086
6431
  );
6087
6432
  }
6433
+ /**
6434
+ * Typed methods for the email_finding platform.
6435
+ */
6436
+ get emailFinding() {
6437
+ return this._namespaces["emailFinding"] ??= new EmailFindingNamespace(
6438
+ this._core
6439
+ );
6440
+ }
6441
+ /**
6442
+ * Typed methods for the email_verification platform.
6443
+ */
6444
+ get emailVerification() {
6445
+ return this._namespaces["emailVerification"] ??= new EmailVerificationNamespace(this._core);
6446
+ }
6088
6447
  /**
6089
6448
  * Typed methods for the facebook platform.
6090
6449
  */
@@ -6189,6 +6548,14 @@ var AnyAPI2 = class extends AnyAPI {
6189
6548
  this._core
6190
6549
  );
6191
6550
  }
6551
+ /**
6552
+ * Typed methods for the mobile_phone platform.
6553
+ */
6554
+ get mobilePhone() {
6555
+ return this._namespaces["mobilePhone"] ??= new MobilePhoneNamespace(
6556
+ this._core
6557
+ );
6558
+ }
6192
6559
  /**
6193
6560
  * Typed methods for the pandaexpress platform.
6194
6561
  */
@@ -6197,6 +6564,14 @@ var AnyAPI2 = class extends AnyAPI {
6197
6564
  this._core
6198
6565
  );
6199
6566
  }
6567
+ /**
6568
+ * Typed methods for the people_search platform.
6569
+ */
6570
+ get peopleSearch() {
6571
+ return this._namespaces["peopleSearch"] ??= new PeopleSearchNamespace(
6572
+ this._core
6573
+ );
6574
+ }
6200
6575
  /**
6201
6576
  * Typed methods for the person platform.
6202
6577
  */
@@ -6205,6 +6580,12 @@ var AnyAPI2 = class extends AnyAPI {
6205
6580
  this._core
6206
6581
  );
6207
6582
  }
6583
+ /**
6584
+ * Typed methods for the person_enrichment platform.
6585
+ */
6586
+ get personEnrichment() {
6587
+ return this._namespaces["personEnrichment"] ??= new PersonEnrichmentNamespace(this._core);
6588
+ }
6208
6589
  /**
6209
6590
  * Typed methods for the pinterest platform.
6210
6591
  */
@@ -6460,12 +6841,16 @@ export {
6460
6841
  BlueskyNamespace,
6461
6842
  BookingNamespace,
6462
6843
  CoinmarketcapNamespace,
6844
+ CompanyEnrichmentNamespace,
6845
+ CompanySearchNamespace,
6463
6846
  CongressNamespace,
6464
6847
  ConnectionError,
6465
6848
  DexscreenerNamespace,
6466
6849
  DouyinNamespace,
6467
6850
  EbayNamespace,
6851
+ EmailFindingNamespace,
6468
6852
  EmailNamespace,
6853
+ EmailVerificationNamespace,
6469
6854
  FacebookNamespace,
6470
6855
  FiverrNamespace,
6471
6856
  GithubNamespace,
@@ -6480,8 +6865,11 @@ export {
6480
6865
  InsufficientBalanceError,
6481
6866
  LinkedinNamespace,
6482
6867
  MapsNamespace,
6868
+ MobilePhoneNamespace,
6483
6869
  NotFoundError,
6484
6870
  PandaexpressNamespace,
6871
+ PeopleSearchNamespace,
6872
+ PersonEnrichmentNamespace,
6485
6873
  PersonNamespace,
6486
6874
  PinterestNamespace,
6487
6875
  PlaystoreNamespace,
@@ -6491,6 +6879,7 @@ export {
6491
6879
  RedditNamespace,
6492
6880
  RedfinNamespace,
6493
6881
  RednoteNamespace,
6882
+ RequestPendingError,
6494
6883
  ResultNotFoundError,
6495
6884
  SecNamespace,
6496
6885
  SemrushNamespace,