@signaliz/sdk 1.0.29 → 1.0.30

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
@@ -380,89 +380,51 @@ var Signaliz = class {
380
380
  this.client = new HttpClient(config);
381
381
  }
382
382
  async findEmail(params) {
383
- const data = await this.client.post("api/v1/find-email", compact({
384
- company_domain: params.companyDomain,
385
- full_name: params.fullName,
386
- first_name: params.firstName,
387
- last_name: params.lastName,
388
- linkedin_url: params.linkedinUrl,
389
- company_name: params.companyName,
390
- skip_cache: params.skipCache
391
- }));
392
- const email = typeof data.email === "string" && data.email.trim() ? data.email.trim() : null;
393
- const found = Boolean(email) && data.found !== false;
394
- const verificationStatus = data.verification_status ?? data.status ?? "unknown";
395
- const rawFreshness = String(data.verification_freshness ?? "").toLowerCase();
396
- const verificationFreshness = rawFreshness === "fresh" || rawFreshness === "stale" ? rawFreshness : "unknown";
397
- const needsReverification = data.needs_reverification === true || verificationFreshness === "stale";
398
- const explicitlyNotSendSafe = data.verified_for_sending === false || needsReverification;
399
- const verified = !explicitlyNotSendSafe && (data.email_verified === true || data.verified_for_sending === true || ["valid", "deliverable"].includes(String(verificationStatus).toLowerCase()));
400
- const verificationAgeDays = typeof data.verification_age_days === "number" && Number.isFinite(data.verification_age_days) ? data.verification_age_days : null;
401
- return {
402
- success: data.success !== false && found,
403
- found,
404
- email,
405
- firstName: data.first_name,
406
- lastName: data.last_name,
407
- confidence: data.confidence ?? data.confidence_score ?? (verified ? 1 : 0),
408
- verificationStatus,
409
- isVerified: verified,
410
- isVerifiedForSending: !needsReverification && data.verified_for_sending === true,
411
- isCatchAll: data.email_is_catch_all === true || data.is_catch_all === true,
412
- verificationFreshness,
413
- verificationAgeDays,
414
- verifiedAt: typeof data.verified_at === "string" ? data.verified_at : null,
415
- needsReverification,
416
- providerUsed: data.provider_used ?? data.provider ?? data.email_source ?? data.source ?? "unknown",
417
- error: found ? void 0 : data.error ?? "No verified email found",
418
- errorCode: found ? void 0 : data.error_code ?? "EMAIL_NOT_FOUND",
419
- raw: data
420
- };
383
+ const data = await this.client.post("api/v1/find-email", findEmailRequestBody(params));
384
+ return normalizeFindEmailResult(data);
421
385
  }
422
386
  async findEmails(params, options) {
423
- return runBatch(params, (item) => this.findEmail(item), options);
387
+ validateBatchSize(params);
388
+ const startedAt = Date.now();
389
+ const round = await this.runCoreBatchRound(
390
+ "api/v1/find-email",
391
+ params.map((item, index) => ({ index, request: findEmailRequestBody(item) })),
392
+ options
393
+ );
394
+ return finalizeCoreBatch(
395
+ params.length,
396
+ startedAt,
397
+ round,
398
+ (item) => normalizeFindEmailResult(item.raw)
399
+ );
424
400
  }
425
401
  async verifyEmail(email, options) {
426
402
  const data = await this.client.post("api/v1/verify-email", {
427
403
  email,
428
404
  skip_cache: options?.skipCache
429
405
  });
430
- const verificationStatus = String(data.verification_status ?? "").toLowerCase();
431
- const verified = data.email_verified === true || ["valid", "deliverable"].includes(verificationStatus);
432
- return {
433
- email: data.email ?? email,
434
- isValid: data.is_valid ?? data.valid ?? verified,
435
- isDeliverable: data.is_deliverable ?? data.deliverable ?? verified,
436
- isCatchAll: data.is_catch_all ?? data.catch_all ?? data.diagnostics?.is_catch_all ?? false,
437
- confidenceScore: data.confidence_score ?? data.confidence ?? data.diagnostics?.confidence_score ?? (verified ? 1 : 0),
438
- provider: data.provider,
439
- verificationSource: data.verification_source,
440
- raw: data
441
- };
406
+ return normalizeVerifyEmailResult(email, data);
442
407
  }
443
408
  async verifyEmails(emails, options) {
444
- return runBatch(emails, (email) => this.verifyEmail(email, { skipCache: options?.skipCache }), options);
409
+ validateBatchSize(emails);
410
+ const startedAt = Date.now();
411
+ const round = await this.runCoreBatchRound(
412
+ "api/v1/verify-email",
413
+ emails.map((email, index) => ({
414
+ index,
415
+ request: { email, skip_cache: options?.skipCache }
416
+ })),
417
+ options
418
+ );
419
+ return finalizeCoreBatch(
420
+ emails.length,
421
+ startedAt,
422
+ round,
423
+ (item) => normalizeVerifyEmailResult(emails[item.index], item.raw)
424
+ );
445
425
  }
446
426
  async enrichCompanySignals(params) {
447
- const online = params.online ?? true;
448
- const request = compact({
449
- signal_run_id: params.signalRunId,
450
- company_domain: params.companyDomain,
451
- company_name: params.companyName,
452
- research_prompt: params.researchPrompt,
453
- signal_types: params.signalTypes,
454
- target_signal_count: params.targetSignalCount,
455
- lookback_days: params.lookbackDays,
456
- online,
457
- enable_deep_search: params.enableDeepSearch ?? online,
458
- enable_outreach_intelligence: params.enableOutreachIntelligence,
459
- enable_predictive_intelligence: params.enablePredictiveIntelligence,
460
- skip_cache: params.skipCache,
461
- // REST always returns a resumable run instead of holding the connection;
462
- // waitForResult controls this SDK's polling loop below.
463
- wait_for_result: false,
464
- max_wait_ms: params.maxWaitMs
465
- });
427
+ const request = companySignalRequestBody(params);
466
428
  let data = await this.client.post("api/v1/company-signals", request);
467
429
  if (params.waitForResult !== false && data.run_id && isPendingSignalResponse(data)) {
468
430
  const maxWaitMs = Math.max(1e3, params.maxWaitMs ?? 20 * 6e4);
@@ -490,47 +452,68 @@ var Signaliz = class {
490
452
  throw new Error(`Company signal enrichment ${data.run_id} did not complete within ${maxWaitMs}ms`);
491
453
  }
492
454
  }
493
- return {
494
- success: data.success ?? true,
495
- status: data.status,
496
- signalRunId: data.signal_run_id ?? data.run_id,
497
- company: {
498
- name: data.company?.name ?? params.companyName ?? null,
499
- domain: data.company?.domain ?? params.companyDomain ?? null
500
- },
501
- signals: (data.signals ?? []).map((signal) => {
502
- const metadata = signal.metadata && typeof signal.metadata === "object" && !Array.isArray(signal.metadata) ? signal.metadata : void 0;
503
- return {
504
- id: signal.id,
505
- title: signal.title ?? "",
506
- type: signal.type ?? signal.signal_type ?? "unknown",
507
- content: signal.content ?? signal.description ?? "",
508
- date: signal.date ?? signal.detected_at ?? null,
509
- datePrecision: signal.date_precision,
510
- sourceUrl: signal.source_url ?? signal.url ?? null,
511
- sourceType: signal.source_type,
512
- sourceProvenance: signal.source_provenance,
513
- confidence: signal.confidence ?? signal.confidence_score ?? null,
514
- entityConfidence: signal.entity_confidence ?? metadata?.entity_confidence ?? null,
515
- signalFamily: signal.signal_family,
516
- eventType: signal.signal_event_type,
517
- eventLabel: signal.signal_event_label,
518
- classification: signal.signal_classification ?? null,
519
- derived: signal.derived === true,
520
- evidencePublishedDate: signal.evidence_published_date ?? metadata?.evidence_published_date ?? null,
521
- signalFeedSource: signal.signal_feed_source ?? metadata?.signal_feed_source,
522
- metadata
523
- };
524
- }),
525
- signalCount: data.signal_count ?? data.total_signals ?? data.signals?.length ?? 0,
526
- intelligence: data.intelligence ?? null,
527
- credits: data.credits,
528
- metadata: data.metadata,
529
- raw: data
530
- };
455
+ return normalizeCompanySignalResult(params, data);
531
456
  }
532
457
  async enrichCompanies(companies, options) {
533
- return runBatch(companies, (company) => this.enrichCompanySignals(company), options);
458
+ validateBatchSize(companies);
459
+ const startedAt = Date.now();
460
+ const results = new Array(companies.length);
461
+ let pending = companies.map((params, index) => ({
462
+ index,
463
+ request: companySignalRequestBody(params)
464
+ }));
465
+ while (pending.length > 0) {
466
+ const round = await this.runCoreBatchRound("api/v1/company-signals", pending, options);
467
+ const taskByIndex = new Map(pending.map((task) => [task.index, task]));
468
+ const nextPending = [];
469
+ let nextDelayMs = 6e4;
470
+ for (const item of round) {
471
+ const params = companies[item.index];
472
+ const task = taskByIndex.get(item.index);
473
+ if (!item.success || !item.raw) {
474
+ results[item.index] = { index: item.index, success: false, error: item.error || "Company Signal batch request failed" };
475
+ continue;
476
+ }
477
+ if (!isPendingSignalResponse(item.raw) || params.waitForResult === false) {
478
+ results[item.index] = { index: item.index, success: true, data: normalizeCompanySignalResult(params, item.raw) };
479
+ continue;
480
+ }
481
+ const maxWaitMs = Math.max(1e3, params.maxWaitMs ?? 20 * 6e4);
482
+ if (Date.now() - startedAt >= maxWaitMs) {
483
+ results[item.index] = {
484
+ index: item.index,
485
+ success: false,
486
+ error: `Company signal enrichment ${item.raw.signal_run_id || item.raw.run_id || ""} did not complete within ${maxWaitMs}ms`
487
+ };
488
+ continue;
489
+ }
490
+ const signalRunId = item.raw.signal_run_id || item.raw.run_id;
491
+ if (!signalRunId) {
492
+ results[item.index] = { index: item.index, success: false, error: "Company signal enrichment is processing without a signal_run_id" };
493
+ continue;
494
+ }
495
+ nextDelayMs = Math.min(
496
+ nextDelayMs,
497
+ signalPollDelayMs(item.raw, params.pollIntervalMs),
498
+ maxWaitMs - (Date.now() - startedAt)
499
+ );
500
+ nextPending.push({
501
+ ...task,
502
+ request: { ...task.request, signal_run_id: signalRunId }
503
+ });
504
+ }
505
+ if (nextPending.length === 0) break;
506
+ await sleep2(Math.max(1, nextDelayMs));
507
+ pending = nextPending;
508
+ }
509
+ const succeeded = results.filter((item) => item.success).length;
510
+ return {
511
+ total: companies.length,
512
+ succeeded,
513
+ failed: companies.length - succeeded,
514
+ durationMs: Date.now() - startedAt,
515
+ results
516
+ };
534
517
  }
535
518
  async signalToCopy(params) {
536
519
  const request = signalToCopyRequestBody(params);
@@ -553,22 +536,17 @@ var Signaliz = class {
553
536
  return normalizeSignalToCopyResult(data);
554
537
  }
555
538
  async createSignalCopyBatch(requests, options) {
556
- if (!Array.isArray(requests) || requests.length === 0) {
557
- throw new Error("Signaliz batch requests require at least one item");
558
- }
559
- if (requests.length > 5e3) {
560
- throw new Error(`Signaliz batch requests support at most 5,000 items; received ${requests.length}`);
561
- }
539
+ validateBatchSize(requests);
562
540
  const startedAt = Date.now();
563
541
  const chunks = [];
564
542
  for (let offset = 0; offset < requests.length; offset += 25) {
565
543
  chunks.push({ offset, requests: requests.slice(offset, offset + 25) });
566
544
  }
567
- const serverConcurrency = Math.min(10, options?.concurrency ?? 10);
545
+ const { serverConcurrency, chunkConcurrency } = batchConcurrencyPlan(options);
568
546
  const chunkBatch = await runBatch(
569
547
  chunks,
570
548
  (chunk) => this.runSignalCopyBatchChunk(chunk.requests, serverConcurrency),
571
- options
549
+ { concurrency: chunkConcurrency }
572
550
  );
573
551
  const results = new Array(requests.length);
574
552
  for (const chunkResult of chunkBatch.results) {
@@ -658,6 +636,50 @@ var Signaliz = class {
658
636
  }
659
637
  return results;
660
638
  }
639
+ async runCoreBatchRound(path, tasks, options) {
640
+ const { serverConcurrency, chunkConcurrency } = batchConcurrencyPlan(options);
641
+ const chunks = [];
642
+ for (let offset = 0; offset < tasks.length; offset += 25) {
643
+ chunks.push({ offset, tasks: tasks.slice(offset, offset + 25) });
644
+ }
645
+ const chunkBatch = await runBatch(chunks, async (chunk) => {
646
+ const data = await this.client.post(path, {
647
+ requests: chunk.tasks.map((task) => task.request),
648
+ concurrency: serverConcurrency
649
+ });
650
+ if (!Array.isArray(data.results) || data.results.length !== chunk.tasks.length) {
651
+ throw new Error(`${path} batch returned an invalid result count`);
652
+ }
653
+ if (data.results.some((row, index) => row.index !== index)) {
654
+ throw new Error(`${path} batch returned results out of order`);
655
+ }
656
+ return data.results;
657
+ }, { concurrency: chunkConcurrency });
658
+ const results = new Array(tasks.length);
659
+ for (const chunkResult of chunkBatch.results) {
660
+ const chunk = chunks[chunkResult.index];
661
+ if (!chunkResult.success || !chunkResult.data) {
662
+ for (let index = 0; index < chunk.tasks.length; index += 1) {
663
+ results[chunk.offset + index] = {
664
+ index: chunk.tasks[index].index,
665
+ success: false,
666
+ error: chunkResult.error || `${path} batch request failed`
667
+ };
668
+ }
669
+ continue;
670
+ }
671
+ for (let index = 0; index < chunkResult.data.length; index += 1) {
672
+ const raw = chunkResult.data[index];
673
+ results[chunk.offset + index] = {
674
+ index: chunk.tasks[index].index,
675
+ success: raw.success !== false,
676
+ raw,
677
+ error: raw.success === false ? raw.error || raw.message || raw.error_code || `${path} item failed` : void 0
678
+ };
679
+ }
680
+ }
681
+ return results;
682
+ }
661
683
  async listTools() {
662
684
  const result = await this.client.mcp("tools/list");
663
685
  return result.tools ?? [];
@@ -673,6 +695,172 @@ var Signaliz = class {
673
695
  function compact(input) {
674
696
  return Object.fromEntries(Object.entries(input).filter(([, value]) => value !== void 0));
675
697
  }
698
+ function findEmailRequestBody(params) {
699
+ return compact({
700
+ company_domain: params.companyDomain,
701
+ full_name: params.fullName,
702
+ first_name: params.firstName,
703
+ last_name: params.lastName,
704
+ linkedin_url: params.linkedinUrl,
705
+ company_name: params.companyName,
706
+ skip_cache: params.skipCache
707
+ });
708
+ }
709
+ function normalizeFindEmailResult(data) {
710
+ const email = typeof data.email === "string" && data.email.trim() ? data.email.trim() : null;
711
+ const found = Boolean(email) && data.found !== false;
712
+ const verificationStatus = data.verification_status ?? data.status ?? "unknown";
713
+ const rawFreshness = String(data.verification_freshness ?? "").toLowerCase();
714
+ const verificationFreshness = rawFreshness === "fresh" || rawFreshness === "stale" ? rawFreshness : "unknown";
715
+ const needsReverification = data.needs_reverification === true || verificationFreshness === "stale";
716
+ const explicitlyNotSendSafe = data.verified_for_sending === false || needsReverification;
717
+ const verified = !explicitlyNotSendSafe && (data.email_verified === true || data.verified_for_sending === true || ["valid", "deliverable"].includes(String(verificationStatus).toLowerCase()));
718
+ const verificationAgeDays = typeof data.verification_age_days === "number" && Number.isFinite(data.verification_age_days) ? data.verification_age_days : null;
719
+ return {
720
+ success: data.success !== false && found,
721
+ found,
722
+ email,
723
+ firstName: data.first_name,
724
+ lastName: data.last_name,
725
+ confidence: data.confidence ?? data.confidence_score ?? (verified ? 1 : 0),
726
+ verificationStatus,
727
+ isVerified: verified,
728
+ isVerifiedForSending: !needsReverification && data.verified_for_sending === true,
729
+ isCatchAll: data.email_is_catch_all === true || data.is_catch_all === true,
730
+ verificationFreshness,
731
+ verificationAgeDays,
732
+ verifiedAt: typeof data.verified_at === "string" ? data.verified_at : null,
733
+ needsReverification,
734
+ providerUsed: data.provider_used ?? data.provider ?? data.email_source ?? data.source ?? "unknown",
735
+ error: found ? void 0 : data.error ?? "No verified email found",
736
+ errorCode: found ? void 0 : data.error_code ?? "EMAIL_NOT_FOUND",
737
+ raw: data
738
+ };
739
+ }
740
+ function normalizeVerifyEmailResult(email, data) {
741
+ const verificationStatus = String(data.verification_status ?? "").toLowerCase();
742
+ const verified = data.email_verified === true || ["valid", "deliverable"].includes(verificationStatus);
743
+ return {
744
+ email: data.email ?? email,
745
+ isValid: data.is_valid ?? data.valid ?? verified,
746
+ isDeliverable: data.is_deliverable ?? data.deliverable ?? verified,
747
+ isCatchAll: data.email_is_catch_all ?? data.is_catch_all ?? data.catch_all ?? data.diagnostics?.is_catch_all ?? false,
748
+ confidenceScore: data.confidence_score ?? data.confidence ?? data.diagnostics?.confidence_score ?? (verified ? 1 : 0),
749
+ provider: data.provider,
750
+ verificationSource: data.verification_source,
751
+ raw: data
752
+ };
753
+ }
754
+ function companySignalRequestBody(params) {
755
+ const online = params.online ?? true;
756
+ return compact({
757
+ signal_run_id: params.signalRunId,
758
+ company_domain: params.companyDomain,
759
+ company_name: params.companyName,
760
+ research_prompt: params.researchPrompt,
761
+ signal_types: params.signalTypes,
762
+ target_signal_count: params.targetSignalCount,
763
+ lookback_days: params.lookbackDays,
764
+ online,
765
+ enable_deep_search: params.enableDeepSearch ?? online,
766
+ enable_outreach_intelligence: params.enableOutreachIntelligence,
767
+ enable_predictive_intelligence: params.enablePredictiveIntelligence,
768
+ skip_cache: params.skipCache,
769
+ // REST always returns a resumable run instead of holding the connection;
770
+ // waitForResult controls the SDK polling loop.
771
+ wait_for_result: false,
772
+ max_wait_ms: params.maxWaitMs
773
+ });
774
+ }
775
+ function normalizeCompanySignalResult(params, data) {
776
+ return {
777
+ success: data.success ?? true,
778
+ status: data.status,
779
+ signalRunId: data.signal_run_id ?? data.run_id,
780
+ company: {
781
+ name: data.company?.name ?? params.companyName ?? null,
782
+ domain: data.company?.domain ?? params.companyDomain ?? null
783
+ },
784
+ signals: (data.signals ?? []).map((signal) => {
785
+ const metadata = signal.metadata && typeof signal.metadata === "object" && !Array.isArray(signal.metadata) ? signal.metadata : void 0;
786
+ return {
787
+ id: signal.id,
788
+ title: signal.title ?? "",
789
+ type: signal.type ?? signal.signal_type ?? "unknown",
790
+ content: signal.content ?? signal.description ?? "",
791
+ date: signal.date ?? signal.detected_at ?? null,
792
+ datePrecision: signal.date_precision,
793
+ sourceUrl: signal.source_url ?? signal.url ?? null,
794
+ sourceType: signal.source_type,
795
+ sourceProvenance: signal.source_provenance,
796
+ confidence: signal.confidence ?? signal.confidence_score ?? null,
797
+ entityConfidence: signal.entity_confidence ?? metadata?.entity_confidence ?? null,
798
+ signalFamily: signal.signal_family,
799
+ eventType: signal.signal_event_type,
800
+ eventLabel: signal.signal_event_label,
801
+ classification: signal.signal_classification ?? null,
802
+ derived: signal.derived === true,
803
+ evidencePublishedDate: signal.evidence_published_date ?? metadata?.evidence_published_date ?? null,
804
+ signalFeedSource: signal.signal_feed_source ?? metadata?.signal_feed_source,
805
+ metadata
806
+ };
807
+ }),
808
+ signalCount: data.signal_count ?? data.total_signals ?? data.signals?.length ?? 0,
809
+ intelligence: data.intelligence ?? null,
810
+ credits: data.credits,
811
+ metadata: data.metadata,
812
+ raw: data
813
+ };
814
+ }
815
+ function validateBatchSize(items) {
816
+ if (!Array.isArray(items) || items.length === 0) {
817
+ throw new Error("Signaliz batch requests require at least one item");
818
+ }
819
+ if (items.length > 5e3) {
820
+ throw new Error(`Signaliz batch requests support at most 5,000 items; received ${items.length}`);
821
+ }
822
+ }
823
+ function validatedBatchConcurrency(options) {
824
+ const concurrency = options?.concurrency ?? 10;
825
+ if (!Number.isInteger(concurrency) || concurrency < 1 || concurrency > 50) {
826
+ throw new Error("Signaliz batch concurrency must be an integer between 1 and 50");
827
+ }
828
+ return concurrency;
829
+ }
830
+ function batchConcurrencyPlan(options) {
831
+ const concurrency = validatedBatchConcurrency(options);
832
+ const serverConcurrency = Math.min(10, concurrency);
833
+ return {
834
+ serverConcurrency,
835
+ chunkConcurrency: Math.max(1, Math.floor(concurrency / serverConcurrency))
836
+ };
837
+ }
838
+ function finalizeCoreBatch(total, startedAt, round, normalize) {
839
+ const results = new Array(total);
840
+ for (const item of round) {
841
+ if (!item.success || !item.raw) {
842
+ results[item.index] = { index: item.index, success: false, error: item.error || "Signaliz batch item failed" };
843
+ continue;
844
+ }
845
+ try {
846
+ results[item.index] = { index: item.index, success: true, data: normalize(item) };
847
+ } catch (error) {
848
+ results[item.index] = {
849
+ index: item.index,
850
+ success: false,
851
+ error: error instanceof Error ? error.message : String(error)
852
+ };
853
+ }
854
+ }
855
+ const succeeded = results.filter((item) => item.success).length;
856
+ return {
857
+ total,
858
+ succeeded,
859
+ failed: total - succeeded,
860
+ durationMs: Date.now() - startedAt,
861
+ results
862
+ };
863
+ }
676
864
  function signalToCopyRequestBody(params) {
677
865
  return compact({
678
866
  company_domain: params.companyDomain,
@@ -734,16 +922,8 @@ function sleep2(ms) {
734
922
  return new Promise((resolve) => setTimeout(resolve, ms));
735
923
  }
736
924
  async function runBatch(items, execute, options) {
737
- if (!Array.isArray(items) || items.length === 0) {
738
- throw new Error("Signaliz batch requests require at least one item");
739
- }
740
- if (items.length > 5e3) {
741
- throw new Error(`Signaliz batch requests support at most 5,000 items; received ${items.length}`);
742
- }
743
- const concurrency = options?.concurrency ?? 10;
744
- if (!Number.isInteger(concurrency) || concurrency < 1 || concurrency > 50) {
745
- throw new Error("Signaliz batch concurrency must be an integer between 1 and 50");
746
- }
925
+ validateBatchSize(items);
926
+ const concurrency = validatedBatchConcurrency(options);
747
927
  const startedAt = Date.now();
748
928
  const results = new Array(items.length);
749
929
  let nextIndex = 0;
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  Signaliz,
3
3
  SignalizError
4
- } from "./chunk-R4DIAP7P.mjs";
4
+ } from "./chunk-INM326KO.mjs";
5
5
  export {
6
6
  Signaliz,
7
7
  SignalizError