gscdump 0.17.0 → 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.d.mts CHANGED
@@ -346,6 +346,24 @@ declare function batchInspectUrls(client: GoogleSearchConsoleClient, siteUrl: st
346
346
  concurrency?: number;
347
347
  onProgress?: (result: InspectUrlResult, index: number, total: number) => void;
348
348
  }): Promise<InspectUrlResult[]>;
349
+ interface OAuthTokens {
350
+ accessToken: string;
351
+ /** Unix seconds. */
352
+ expiresAt: number;
353
+ }
354
+ /**
355
+ * Exchange a refresh token for an access token. Retries transient network
356
+ * failures; surfaces HTTP failures (invalid_grant, etc.) immediately as
357
+ * `GscApiError` so callers can mark the refresh token as bad.
358
+ */
359
+ declare function refreshAccessToken(refreshToken: string, clientId: string, clientSecret: string): Promise<OAuthTokens>;
360
+ /**
361
+ * Exchange an authorization code (from the OAuth consent redirect) for
362
+ * access + refresh tokens. Same retry / surface model as `refreshAccessToken`.
363
+ */
364
+ declare function exchangeAuthCode(code: string, clientId: string, clientSecret: string, redirectUri: string): Promise<OAuthTokens & {
365
+ refreshToken?: string;
366
+ }>;
349
367
  /**
350
368
  * Fetches all sites the authenticated user has access to in Google Search Console.
351
369
  */
@@ -485,6 +503,24 @@ declare const GSC_QUOTAS: {
485
503
  declare function classifyError(cause: unknown): GscError;
486
504
  /** Construct a storage-kind error from inside the analytics engine / adapters. */
487
505
  declare function storageError(message: string, cause?: unknown): GscError;
506
+ interface GscApiErrorInfo {
507
+ code: number;
508
+ message: string;
509
+ reason?: string;
510
+ status?: string;
511
+ }
512
+ declare function parseGoogleError(text: string, httpStatus?: number): GscApiErrorInfo;
513
+ declare class GscApiError extends Error {
514
+ info: GscApiErrorInfo;
515
+ constructor(message: string, info: GscApiErrorInfo);
516
+ }
517
+ /**
518
+ * Returns a handler that re-throws `unknown` as a `GscApiError` prefixed with
519
+ * `prefix`. Recognises `ofetch` `FetchError` (parses `err.data` as Google JSON
520
+ * via `parseGoogleError`); passes through existing `GscApiError`; re-throws
521
+ * anything else as-is.
522
+ */
523
+ declare function rethrowAsGscApiError(prefix: string): (err: unknown) => never;
488
524
  /**
489
525
  * String-matches an error against the signals Google returns when a token
490
526
  * has lost access to a property (revoked, downgraded, or never had it).
@@ -580,11 +616,67 @@ declare const INDEXING_ISSUE_FILTERS: {
580
616
  type IndexingIssueType = keyof typeof INDEXING_ISSUE_FILTERS;
581
617
  declare const INDEXING_ISSUE_LABELS: Record<IndexingIssueType, string>;
582
618
  declare const INDEXING_ISSUE_SEVERITY: Record<IndexingIssueType, 'error' | 'warning' | 'info'>;
619
+ interface GscPropertyCandidate {
620
+ siteUrl?: string | null;
621
+ permissionLevel?: string | null;
622
+ }
623
+ declare function isVerifiedGscProperty(property?: GscPropertyCandidate | null): boolean;
624
+ declare function isVerifiedGscPermission(level: string | null | undefined): boolean;
625
+ /**
626
+ * Does `propertyUrl` cover `targetDomain`? Matches sc-domain (exact or
627
+ * subdomain) and URL-prefix (host equality) without scheme/www noise.
628
+ */
629
+ declare function gscPropertyMatchesTarget(targetDomain: string, propertyUrl: string | null | undefined): boolean;
630
+ /**
631
+ * Convenience: match `siteUrl` against `gscSiteUrl` directly (extracts the
632
+ * hostname from `siteUrl` first).
633
+ */
634
+ declare function matchGscSite(siteUrl: string | null | undefined, gscSiteUrl: string | null | undefined): boolean;
635
+ /**
636
+ * Pick the best GSC property for a hostname from a candidate list. "Best":
637
+ * 1. Verified Domain property (widest + readable)
638
+ * 2. Verified URL-prefix property (narrower + readable)
639
+ * 3. Unverified Domain property (returned as a fallback so callers can
640
+ * surface the verification gap to the user)
641
+ * 4. Unverified URL-prefix property (same caveat)
642
+ *
643
+ * Without this ranking, naively picking the first match would register an
644
+ * unverified property and leave the site stuck with zero data.
645
+ */
646
+ declare function pickBestGscProperty<T extends GscPropertyCandidate>(origin: string, availableSites: readonly T[]): T | undefined;
647
+ /**
648
+ * Richer best-property selection that also returns the matched domain and
649
+ * URL candidates separately, so callers can show "we matched on X domain
650
+ * property and Y URL-prefix property" diagnostics.
651
+ */
652
+ declare function findBestGscProperty<T extends GscPropertyCandidate>(targetDomain: string, properties: readonly T[]): {
653
+ matchedSite: T | null;
654
+ domainProperty: T | null;
655
+ urlProperty: T | null;
656
+ };
657
+ declare function findExactGscProperty<T extends GscPropertyCandidate>(propertyUrl: string, properties: readonly T[]): T | null;
658
+ declare function formatGscPropertyCandidates(candidates: ReadonlyArray<GscPropertyCandidate | null | undefined>): string;
583
659
  declare const INDEXING_DAILY_LIMIT = 2000;
584
660
  declare const INDEXING_EFFECTIVE_LIMIT = 1800;
585
661
  declare function hasGscReadScope(scopes: string | null | undefined): boolean;
586
662
  declare function hasGscWriteScope(scopes: string | null | undefined): boolean;
587
663
  declare function hasIndexingScope(scopes: string | null | undefined): boolean;
664
+ interface ParsedGscSiteUrl {
665
+ /** Original, canonical GSC property URL. */
666
+ label: string;
667
+ /** Bare hostname, stripped of protocol / sc-domain prefix / path. */
668
+ hostname: string;
669
+ /** Human-friendly label: scheme stripped, trailing slash trimmed, path retained. */
670
+ displayLabel: string;
671
+ propertyType: 'domain' | 'url-prefix';
672
+ isDomain: boolean;
673
+ }
674
+ declare function parseGscSiteUrl(siteUrl: string): ParsedGscSiteUrl;
675
+ /**
676
+ * Normalize a user-input URL/hostname into a canonical registration target.
677
+ * Returns lowercase hostname stripped of protocol, or null if unparseable.
678
+ */
679
+ declare function normalizeRegistrationTarget(inputUrl: string): string | null;
588
680
  declare const GSCDUMP_ONBOARDING_CONTRACT_VERSION: "2026-05-11";
589
681
  declare const GSCDUMP_REQUIRED_ANALYTICS_SCOPE: "https://www.googleapis.com/auth/webmasters.readonly";
590
682
  declare const GSCDUMP_OPTIONAL_INDEXING_SCOPE: "https://www.googleapis.com/auth/indexing";
@@ -716,4 +808,4 @@ interface FetchSitemapUrlsOptions extends DiscoverSitemapOptions {
716
808
  * `<loc>https://...</loc>` shape but doesn't validate the schema.
717
809
  */
718
810
  declare function fetchSitemapUrls(sitemapUrl: string, options?: FetchSitemapUrlsOptions): Promise<string[]>;
719
- export { AccountNextAction, AccountStatus, AnalyticsNextAction, AnalyticsStatus, ApiSite, ApiSitemap, ApiSitemapContent, Auth, AuthClient, AuthOptions, BackfillProgress, CallOptions, DAYS_PER_RANGE, DataRow, DimensionFilter, DimensionFilterGroup, DiscoverSitemapOptions, FetchSitemapUrlsOptions, GSCDUMP_ONBOARDING_CONTRACT_VERSION, GSCDUMP_OPTIONAL_INDEXING_SCOPE, GSCDUMP_REQUIRED_ANALYTICS_SCOPE, GSC_FINALIZED_LAG_DAYS, GSC_FRESHEST_LAG_DAYS, GSC_QUOTAS, GSC_RETENTION_MONTHS, GoogleSearchConsoleClient, GoogleSearchConsoleClientOptions, GscError, GscErrorKind, GscdumpApiOptions, INDEXING_DAILY_LIMIT, INDEXING_EFFECTIVE_LIMIT, INDEXING_ISSUE_FILTERS, INDEXING_ISSUE_LABELS, INDEXING_ISSUE_SEVERITY, IndexStatusResult, IndexingIssueType, IndexingMetadata, IndexingNextAction, IndexingNotificationType, IndexingResult, IndexingStatus, InspectUrlIndexResponse, InspectUrlResult, LifecycleError, LifecycleErrorCode, LifecycleProgress, LifecycleWebhookEnvelope, LifecycleWebhookEvent, MS_PER_DAY, MobileUsabilityResult, PartnerLifecycleAccount, PartnerLifecycleResponse, PartnerLifecycleSite, Period, PropertyNextAction, PropertyStatus, PublishUrlNotificationResponse, QuerySourceMode, RequiredNonNullable, ResolvedAnalyticsRange, RichResultsResult, SearchAnalyticsQuery, SearchAnalyticsResponse, Site, SiteAnalytics, SitemapNextAction, SitemapStatus, UrlInspectionResult, UrlNotificationMetadata, VerificationMethod, VerificationSite, VerificationSiteType, VerificationToken, VerificationWebResource, accountNextActions, accountStatuses, addDays, addSite, analyticsNextActions, analyticsStatuses, batchInspectUrls, batchRequestIndexing, classifyError, countDays, createAuth, createFetch, daysAgo, deleteSite, deleteSitemap, discoverSitemap, fetchSitemap, fetchSitemapUrls, fetchSitemaps, fetchSites, fetchSitesWithSitemaps, formatErrorForCli, generateGscDateRange, getBackfillProgress, getDateRange, getFreshestGscDate, getIndexingMetadata, getLatestGscDate, getNextDate, getOldestGscDate, getPendingDates, getPreviousDate, getPstDate, getVerificationToken, getVerifiedSite, googleSearchConsole, groupIntoRanges, gscdumpApi, hasGscReadScope, hasGscWriteScope, hasIndexingScope, hasOptionalIndexingScope, hasRequiredAnalyticsScope, indexingNextActions, indexingStatuses, inspectUrl, isPermissionDeniedError, isValidGscDate, lifecycleErrorCodes, lifecycleWebhookEvents, listVerifiedSites, parseGrantedScopes, progressBar, propertyNextActions, propertyStatuses, querySourceModes, requestIndexing, rowWithMetricDefaults, runSequentialBatch, siteUrlToVerificationSite, sitemapNextActions, sitemapStatuses, storageError, submitSitemap, toIsoDate, unverifySite, verificationMethodsFor, verifySite };
811
+ export { AccountNextAction, AccountStatus, AnalyticsNextAction, AnalyticsStatus, ApiSite, ApiSitemap, ApiSitemapContent, Auth, AuthClient, AuthOptions, BackfillProgress, CallOptions, DAYS_PER_RANGE, DataRow, DimensionFilter, DimensionFilterGroup, DiscoverSitemapOptions, FetchSitemapUrlsOptions, GSCDUMP_ONBOARDING_CONTRACT_VERSION, GSCDUMP_OPTIONAL_INDEXING_SCOPE, GSCDUMP_REQUIRED_ANALYTICS_SCOPE, GSC_FINALIZED_LAG_DAYS, GSC_FRESHEST_LAG_DAYS, GSC_QUOTAS, GSC_RETENTION_MONTHS, GoogleSearchConsoleClient, GoogleSearchConsoleClientOptions, GscApiError, GscApiErrorInfo, GscError, GscErrorKind, GscPropertyCandidate, GscdumpApiOptions, INDEXING_DAILY_LIMIT, INDEXING_EFFECTIVE_LIMIT, INDEXING_ISSUE_FILTERS, INDEXING_ISSUE_LABELS, INDEXING_ISSUE_SEVERITY, IndexStatusResult, IndexingIssueType, IndexingMetadata, IndexingNextAction, IndexingNotificationType, IndexingResult, IndexingStatus, InspectUrlIndexResponse, InspectUrlResult, LifecycleError, LifecycleErrorCode, LifecycleProgress, LifecycleWebhookEnvelope, LifecycleWebhookEvent, MS_PER_DAY, MobileUsabilityResult, OAuthTokens, ParsedGscSiteUrl, PartnerLifecycleAccount, PartnerLifecycleResponse, PartnerLifecycleSite, Period, PropertyNextAction, PropertyStatus, PublishUrlNotificationResponse, QuerySourceMode, RequiredNonNullable, ResolvedAnalyticsRange, RichResultsResult, SearchAnalyticsQuery, SearchAnalyticsResponse, Site, SiteAnalytics, SitemapNextAction, SitemapStatus, UrlInspectionResult, UrlNotificationMetadata, VerificationMethod, VerificationSite, VerificationSiteType, VerificationToken, VerificationWebResource, accountNextActions, accountStatuses, addDays, addSite, analyticsNextActions, analyticsStatuses, batchInspectUrls, batchRequestIndexing, classifyError, countDays, createAuth, createFetch, daysAgo, deleteSite, deleteSitemap, discoverSitemap, exchangeAuthCode, fetchSitemap, fetchSitemapUrls, fetchSitemaps, fetchSites, fetchSitesWithSitemaps, findBestGscProperty, findExactGscProperty, formatErrorForCli, formatGscPropertyCandidates, generateGscDateRange, getBackfillProgress, getDateRange, getFreshestGscDate, getIndexingMetadata, getLatestGscDate, getNextDate, getOldestGscDate, getPendingDates, getPreviousDate, getPstDate, getVerificationToken, getVerifiedSite, googleSearchConsole, groupIntoRanges, gscPropertyMatchesTarget, gscdumpApi, hasGscReadScope, hasGscWriteScope, hasIndexingScope, hasOptionalIndexingScope, hasRequiredAnalyticsScope, indexingNextActions, indexingStatuses, inspectUrl, isPermissionDeniedError, isValidGscDate, isVerifiedGscPermission, isVerifiedGscProperty, lifecycleErrorCodes, lifecycleWebhookEvents, listVerifiedSites, matchGscSite, normalizeRegistrationTarget, parseGoogleError, parseGrantedScopes, parseGscSiteUrl, pickBestGscProperty, progressBar, propertyNextActions, propertyStatuses, querySourceModes, refreshAccessToken, requestIndexing, rethrowAsGscApiError, rowWithMetricDefaults, runSequentialBatch, siteUrlToVerificationSite, sitemapNextActions, sitemapStatuses, storageError, submitSitemap, toIsoDate, unverifySite, verificationMethodsFor, verifySite };