@gscdump/sdk 0.37.7 → 0.38.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/README.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  Consumer SDK for hosted gscdump.com integrations.
4
4
 
5
+ > The descriptor-driven HTTP client and ticketed realtime state machine are
6
+ > exported from `@gscdump/sdk/v1`. Existing root HTTP/realtime clients remain
7
+ > legacy compatibility surfaces during the release and cutover overlap; the
8
+ > legacy socket client still sends a long-lived key in its first frame and must
9
+ > not be used for a v1 browser integration. See the
10
+ > [v1 contract](../../docs/hosted-api-v1.md).
11
+
5
12
  This package is for partner applications that consume gscdump.com APIs,
6
13
  webhooks, and realtime events. Callers inject the HTTP transport and auth they
7
14
  want to use; route construction stays inside the hosted adapter.
@@ -18,6 +25,22 @@ const gscdump = createGscdumpClient({
18
25
  const { sites } = await gscdump.getUserSites(userId)
19
26
  ```
20
27
 
28
+ The initial v1 slice uses a server-held Bearer credential and exposes both a
29
+ generic operation executor and four convenience methods:
30
+
31
+ ```ts
32
+ import { createGscdumpV1Client } from '@gscdump/sdk/v1'
33
+
34
+ const gscdump = createGscdumpV1Client({
35
+ credential: () => process.env.GSCDUMP_API_KEY!,
36
+ fetch,
37
+ })
38
+
39
+ const lifecycle = await gscdump.getUserLifecycle({
40
+ params: { userId: 'u_01' },
41
+ })
42
+ ```
43
+
21
44
  ## Scope
22
45
 
23
46
  - Partner user lifecycle
@@ -28,10 +51,17 @@ const { sites } = await gscdump.getUserSites(userId)
28
51
  - Webhook receiver contracts and HMAC verification helpers
29
52
  - Shared request/response types re-exported from `@gscdump/contracts`
30
53
 
31
- Analyzer Source dispatch, browser DuckDB-WASM boot, R2 parquet attach, and
32
- Nuxt composables remain in `@gscdump/nuxt`. Nuxt apps should install
33
- `@gscdump/nuxt` for dashboard reads; that layer uses
34
- `createAnalyticsClient()` internally.
54
+ Analyzer Source dispatch, browser DuckDB-WASM boot, and R2 parquet attach are
55
+ separate engine/Nuxt concerns. A Nuxt app can consume the hosted SDK through
56
+ its own query layer; the current consumer uses `nuxt-use-query` rather than
57
+ making the public API depend on `@gscdump/nuxt`.
58
+
59
+ For v1, a Nuxt consumer keeps `user_key` and `partner_key` credentials on its
60
+ server and exposes proxy paths that retain the upstream surface and major
61
+ (for example `/api/gscdump/analytics/v1/...`). Browser realtime receives only
62
+ a single-use ticket. Every semantic event's `changes[]` maps to one ordered,
63
+ awaited query-cache effect; unsafe resync purges the whole host-owned cache
64
+ scope and primary-reseeds it before the SDK advances its cursor or ACKs.
35
65
 
36
66
  ## Boundary
37
67
 
@@ -42,7 +72,8 @@ Belongs here:
42
72
 
43
73
  - request/response types and schemas for partner apps
44
74
  - route builders and pluggable HTTP clients
45
- - websocket client and event schemas
75
+ - ticketed websocket client, replay/resync state, and event schemas
76
+ - awaited realtime apply/resync hooks; a rejected effect never advances ACK
46
77
  - webhook header constants, event schemas, parsing, normalization, and signature
47
78
  verification for receivers
48
79
 
@@ -54,6 +85,7 @@ Does not belong here:
54
85
  - generating or storing production webhook secrets
55
86
  - creating production webhook delivery IDs or envelopes
56
87
  - partner subscription filtering for outgoing deliveries
88
+ - Durable Object stream storage, replay retention, or outbox dispatch
57
89
 
58
90
  ## Webhooks
59
91
 
package/dist/index.d.mts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { query_d_exports } from "./_chunks/query.mjs";
2
2
  import { Result } from "gscdump/result";
3
3
  import { AddPartnerTeamMemberParams, AnalyticsClient, AnalyticsClient as AnalyticsClient$1, BackfillRange, BackfillResponse, BindPartnerSiteTeamParams, BuilderState, BulkRegisterPartnerSiteResult, BulkRegisterPartnerSitesParams, BulkRegisterPartnerSitesResponse, CANONICAL_WEBHOOK_EVENTS, CanonicalWebhookEventType, CreatePartnerTeamParams, CreateWebhookEnvelopeOptions, DataDetailOptions, DataQueryOptions, DeletePartnerUserResponse, GscComparisonFilter, GscdumpAnalysisParams, GscdumpAnalysisPreset, GscdumpAnalysisResponse, GscdumpAnalysisSourcesResponse, GscdumpAvailableSite, GscdumpCanonicalMismatchesResponse, GscdumpDataDetailResponse, GscdumpDataResponse, GscdumpDataRow, GscdumpDateRangeParams, GscdumpIndexPercentResponse, GscdumpIndexingDiagnosticsResponse, GscdumpIndexingResponse, GscdumpIndexingUrlStatus, GscdumpIndexingUrlsResponse, GscdumpKeywordSparklinesParams, GscdumpKeywordSparklinesResponse, GscdumpMeta, GscdumpPageTrendParams, GscdumpPageTrendResponse, GscdumpPermissionRecovery, GscdumpQueryTrendParams, GscdumpQueryTrendResponse, GscdumpSiteRegistration, GscdumpSitemap, GscdumpSitemapChangesResponse, GscdumpSitemapHistory, GscdumpSitemapsResponse, GscdumpSyncStatusResponse, GscdumpSyncStatusResponse as GscdumpSyncStatusResponse$1, GscdumpTeamMemberRow, GscdumpTeamRow, GscdumpTopAssociationParams, GscdumpTopAssociationResponse, GscdumpTotals, GscdumpUserRegistration, GscdumpUserSettings, GscdumpUserSite, GscdumpUserSite as GscdumpUserSite$1, GscdumpUserStatus, GscdumpUserTokenUpdate, IndexingDiagnosticsParams, IndexingUrlsParams, InspectionHistoryResponse, InspectionIndex, PartnerClient, PartnerClient as PartnerClient$1, PartnerLifecycleAccount, PartnerLifecycleResponse, PartnerLifecycleResponse as PartnerLifecycleResponse$1, PartnerLifecycleSite, PartnerLifecycleSite as PartnerLifecycleSite$1, PartnerRealtimeEvent, PartnerRealtimeEvent as PartnerRealtimeEvent$1, PartnerRealtimeEventType, PartnerRealtimeMessage, PartnerRealtimeMessage as PartnerRealtimeMessage$1, PartnerWebhookData, PartnerWebhookHeaders, PartnerWebhookHeaders as PartnerWebhookHeaders$1, RealtimeAuthFailedEvent, RealtimeAuthRequiredMessage, RealtimeConnectedMessage, RealtimeEnrichmentCompleteEvent, RealtimeErrorMessage, RealtimeJobFailedEvent, RealtimeNeedsReauthEvent, RealtimePongMessage, RealtimeSiteAddedEvent, RealtimeSiteRemovedEvent, RealtimeSubscribedMessage, RealtimeSyncCompleteEvent, RealtimeSyncFailedEvent, RealtimeSyncJobCompleteEvent, RealtimeSyncProgressEvent, RealtimeSyncSiteCompleteEvent, RegisterPartnerSiteParams, RegisterPartnerUserParams, RollupEnvelope, UpdatePartnerUserTokensParams, VALID_WEBHOOK_EVENTS, WEBHOOK_CONTRACT_VERSION, WEBHOOK_CONTRACT_VERSION_HEADER, WEBHOOK_DELIVERY_HEADER, WEBHOOK_EVENT_HEADER, WEBHOOK_SIGNATURE_HEADER, WEBHOOK_TIMESTAMP_HEADER, WebhookEnvelope, WebhookEnvelope as WebhookEnvelope$1, WebhookEventType, WhoamiResponse } from "@gscdump/contracts";
4
+ import { ZodTypeAny } from "zod";
4
5
  import { ActionSource } from "@gscdump/analysis";
5
6
  import { AnalysisTool } from "@gscdump/engine/analysis-types";
6
7
  export * from "@gscdump/contracts";
@@ -127,7 +128,7 @@ interface GscAnalyzerDefinition<TComponent = unknown> {
127
128
  capabilities?: GscAnalyzerCapabilities<TComponent>;
128
129
  }
129
130
  type GscAnalyzerDefinitionWithCapability<K extends GscAnalyzerCapability, TComponent = unknown> = GscAnalyzerDefinition<TComponent> & {
130
- capabilities: { [P in K]: NonNullable<GscAnalyzerCapabilities<TComponent>[P]> };
131
+ capabilities: { [P in K]: NonNullable<GscAnalyzerCapabilities<TComponent>[P]>; };
131
132
  };
132
133
  declare function defineGscAnalyzer<TComponent = unknown>(def: GscAnalyzerDefinition<TComponent>): GscAnalyzerDefinition<TComponent>;
133
134
  interface DailyAnonInput {
package/dist/query.d.mts CHANGED
@@ -1 +1,2 @@
1
+ import "./_chunks/query.mjs";
1
2
  export * from "gscdump/query";
@@ -0,0 +1,187 @@
1
+ import { GscdumpV1ErrorEnvelope, RealtimeV1Cursor, RealtimeV1Event, RealtimeV1StreamHead, RealtimeV1StreamId, createGscdumpV1Protocol } from "@gscdump/contracts/v1";
2
+ import { ZodTypeAny, z } from "zod";
3
+ type MaybePromise$1<T> = T | Promise<T>;
4
+ type ValueOf<T> = T[keyof T];
5
+ type ValueOfUnion<T> = T extends unknown ? ValueOf<T> : never;
6
+ type GscdumpV1ProtocolShape = ReturnType<typeof createGscdumpV1Protocol>;
7
+ type GscdumpV1Surface = ValueOf<GscdumpV1ProtocolShape['surfaces']>;
8
+ type GscdumpV1OperationRegistry = GscdumpV1Surface['operations'];
9
+ type GscdumpV1Operation = ValueOfUnion<GscdumpV1OperationRegistry>;
10
+ type GscdumpV1OperationId = GscdumpV1Operation['id'];
11
+ type OperationById<TId extends GscdumpV1OperationId> = Extract<GscdumpV1Operation, {
12
+ id: TId;
13
+ }>;
14
+ type SchemaInput<TSchema> = TSchema extends ZodTypeAny ? z.input<TSchema> : never;
15
+ type SchemaOutput<TSchema> = TSchema extends ZodTypeAny ? z.output<TSchema> : never;
16
+ type RequiredLocation<TKey extends string, TSchema> = TSchema extends ZodTypeAny ? { [K in TKey]: SchemaInput<TSchema>; } : { [K in TKey]?: never; };
17
+ type OptionalLocation<TKey extends string, TSchema> = TSchema extends ZodTypeAny ? { [K in TKey]?: SchemaInput<TSchema>; } : { [K in TKey]?: never; };
18
+ type GscdumpV1OperationInput<TId extends GscdumpV1OperationId> = RequiredLocation<'params', OperationById<TId>['request']['params']> & RequiredLocation<'query', OperationById<TId>['request']['query']> & OptionalLocation<'headers', OperationById<TId>['request']['headers']> & RequiredLocation<'body', OperationById<TId>['request']['body']>;
19
+ type OperationResponseSchema<TId extends GscdumpV1OperationId> = ValueOf<OperationById<TId>['responses']> extends (infer TResponse) ? TResponse extends {
20
+ client: infer TClient extends ZodTypeAny;
21
+ } ? TClient : never : never;
22
+ type GscdumpV1OperationResponse<TId extends GscdumpV1OperationId> = SchemaOutput<OperationResponseSchema<TId>>;
23
+ type GscdumpV1CredentialResolver = string | (() => MaybePromise$1<string>);
24
+ type GscdumpV1HeadersResolver = HeadersInit | (() => MaybePromise$1<HeadersInit>);
25
+ interface GscdumpV1RetryOptions {
26
+ /** Total attempts, including the initial request. Defaults to 3 and is capped at 5. */
27
+ maxAttempts?: number;
28
+ /** Deterministic exponential-backoff base. Defaults to 250 ms. */
29
+ baseDelayMs?: number;
30
+ /** Backoff ceiling. Defaults to 2 seconds. Retry-After can exceed this ceiling. */
31
+ maxDelayMs?: number;
32
+ }
33
+ interface CreateGscdumpV1ClientOptions {
34
+ /**
35
+ * Root replacing the contract's `/api` segment. Direct calls default to
36
+ * `https://gscdump.com/api`; a same-origin proxy can use `/api/_gscdump`.
37
+ */
38
+ apiRoot?: string;
39
+ credential: GscdumpV1CredentialResolver;
40
+ fetch?: typeof fetch;
41
+ headers?: GscdumpV1HeadersResolver;
42
+ retry?: GscdumpV1RetryOptions;
43
+ }
44
+ interface GscdumpV1ExecuteOptions {
45
+ signal?: AbortSignal;
46
+ requestId?: string;
47
+ idempotencyKey?: string;
48
+ }
49
+ type GscdumpV1SdkErrorCode = GscdumpV1ErrorEnvelope['error']['code'] | 'aborted' | 'credential_resolution' | 'network_error' | 'protocol_error' | 'request_validation' | 'response_validation';
50
+ interface GscdumpV1ErrorOptions {
51
+ code: GscdumpV1SdkErrorCode;
52
+ message: string;
53
+ status?: number;
54
+ requestId?: string;
55
+ retryable: boolean;
56
+ details: Record<string, unknown>;
57
+ cause?: unknown;
58
+ }
59
+ /** One stable, tagged failure shape for validation, transport, and API errors. */
60
+ declare class GscdumpV1Error extends Error {
61
+ readonly tag: "GscdumpV1Error";
62
+ readonly code: GscdumpV1SdkErrorCode;
63
+ readonly status?: number;
64
+ readonly requestId?: string;
65
+ readonly retryable: boolean;
66
+ readonly details: Record<string, unknown>;
67
+ readonly cause?: unknown;
68
+ constructor(options: GscdumpV1ErrorOptions);
69
+ }
70
+ declare function isGscdumpV1Error(error: unknown): error is GscdumpV1Error;
71
+ interface GscdumpV1Client {
72
+ execute: <TId extends GscdumpV1OperationId>(operation: TId, input: GscdumpV1OperationInput<TId>, options?: GscdumpV1ExecuteOptions) => Promise<GscdumpV1OperationResponse<TId>>;
73
+ getUserLifecycle: (input: GscdumpV1OperationInput<'partner.users.lifecycle.get'>, options?: GscdumpV1ExecuteOptions) => Promise<GscdumpV1OperationResponse<'partner.users.lifecycle.get'>>;
74
+ queryAnalyticsRows: (input: GscdumpV1OperationInput<'analytics.rows.query'>, options?: GscdumpV1ExecuteOptions) => Promise<GscdumpV1OperationResponse<'analytics.rows.query'>>;
75
+ getRealtimeStreamHead: (input?: GscdumpV1OperationInput<'realtime.stream.head.get'>, options?: GscdumpV1ExecuteOptions) => Promise<GscdumpV1OperationResponse<'realtime.stream.head.get'>>;
76
+ createRealtimeTicket: (input: GscdumpV1OperationInput<'realtime.tickets.create'>, options?: GscdumpV1ExecuteOptions) => Promise<GscdumpV1OperationResponse<'realtime.tickets.create'>>;
77
+ }
78
+ /** Create one framework-neutral client whose behavior is driven by the v1 registry. */
79
+ declare function createGscdumpV1Client(options: CreateGscdumpV1ClientOptions): GscdumpV1Client;
80
+ type MaybePromise<T> = T | Promise<T>;
81
+ declare const GSCDUMP_REALTIME_V1_SDK_VERSION: "0.37.7";
82
+ type GscdumpRealtimeV1TransportState = 'idle' | 'ticketing' | 'connecting' | 'handshaking' | 'replaying' | 'live' | 'waiting' | 'stopped' | 'terminal';
83
+ type GscdumpRealtimeV1Freshness = 'unknown' | 'stale' | 'applying' | 'fresh' | 'resyncing' | 'degraded';
84
+ type GscdumpRealtimeV1ErrorCode = 'cursor_store_failed' | 'effect_failed' | 'heartbeat_stale' | 'integration_failed' | 'protocol_error' | 'resync_failed' | 'runtime_unavailable' | 'socket_error' | 'ticket_invalid' | 'ticket_provider_failed' | 'upgrade_rejected';
85
+ interface GscdumpRealtimeV1ErrorOptions {
86
+ code: GscdumpRealtimeV1ErrorCode;
87
+ message: string;
88
+ retryable: boolean;
89
+ terminal: boolean;
90
+ details?: Record<string, unknown>;
91
+ cause?: unknown;
92
+ }
93
+ declare class GscdumpRealtimeV1Error extends Error {
94
+ readonly tag: "GscdumpRealtimeV1Error";
95
+ readonly code: GscdumpRealtimeV1ErrorCode;
96
+ readonly retryable: boolean;
97
+ readonly terminal: boolean;
98
+ readonly details: Record<string, unknown>;
99
+ readonly cause?: unknown;
100
+ constructor(options: GscdumpRealtimeV1ErrorOptions);
101
+ }
102
+ interface GscdumpRealtimeV1CursorStore {
103
+ load: () => MaybePromise<RealtimeV1Cursor | null>;
104
+ save: (cursor: RealtimeV1Cursor) => MaybePromise<void>;
105
+ }
106
+ interface GscdumpRealtimeV1SocketLike {
107
+ readonly readyState: number;
108
+ readonly protocol: string;
109
+ onopen: ((event: unknown) => void) | null;
110
+ onmessage: ((event: {
111
+ data: unknown;
112
+ }) => void) | null;
113
+ onerror: ((event: unknown) => void) | null;
114
+ onclose: ((event: {
115
+ code?: number;
116
+ reason?: string;
117
+ wasClean?: boolean;
118
+ }) => void) | null;
119
+ send: (data: string) => void;
120
+ close: (code?: number, reason?: string) => void;
121
+ }
122
+ interface GscdumpRealtimeV1Runtime {
123
+ createSocket: (url: string, protocols: readonly string[]) => GscdumpRealtimeV1SocketLike;
124
+ setTimeout: (handler: () => void, ms: number) => unknown;
125
+ clearTimeout: (handle: unknown) => void;
126
+ random: () => number;
127
+ now: () => number;
128
+ }
129
+ type GscdumpRealtimeV1ResyncReason = 'cursor_expired' | 'retention_gap' | 'sequence_gap' | 'stream_mismatch' | 'initial_cursor_missing' | 'effect_application_failed';
130
+ interface GscdumpRealtimeV1ResyncRequest {
131
+ reason: GscdumpRealtimeV1ResyncReason;
132
+ source: 'server' | 'client';
133
+ streamId: RealtimeV1StreamId;
134
+ previousCursor: RealtimeV1Cursor | null;
135
+ resumeAfter: RealtimeV1Cursor;
136
+ failedEvent?: RealtimeV1Event;
137
+ cause?: unknown;
138
+ }
139
+ interface GscdumpRealtimeV1Snapshot {
140
+ transport: GscdumpRealtimeV1TransportState;
141
+ freshness: GscdumpRealtimeV1Freshness;
142
+ attempt: number;
143
+ streamId: RealtimeV1StreamId | null;
144
+ cursor: RealtimeV1Cursor | null;
145
+ head: RealtimeV1StreamHead | null;
146
+ error: GscdumpRealtimeV1Error | null;
147
+ }
148
+ type GscdumpRealtimeV1Observation = {
149
+ type: 'state';
150
+ state: GscdumpRealtimeV1Snapshot;
151
+ } | {
152
+ type: 'event';
153
+ event: RealtimeV1Event;
154
+ cursor: RealtimeV1Cursor | null;
155
+ } | {
156
+ type: 'error';
157
+ error: GscdumpRealtimeV1Error;
158
+ state: GscdumpRealtimeV1Snapshot;
159
+ } | {
160
+ type: 'advisory';
161
+ code: 'unknown_event' | 'unknown_resource' | 'unsupported_event_version';
162
+ event: RealtimeV1Event;
163
+ };
164
+ interface CreateGscdumpRealtimeV1ClientOptions {
165
+ /** Called for every connection attempt. A ticket is never reused. */
166
+ ticketProvider: () => MaybePromise<unknown>;
167
+ /** Required correctness effect for each contiguous durable event. */
168
+ applyEvent: (event: RealtimeV1Event) => Promise<void>;
169
+ /** Required full authoritative reseed used whenever replay is unsafe. */
170
+ resync: (request: GscdumpRealtimeV1ResyncRequest) => Promise<void>;
171
+ cursorStore?: GscdumpRealtimeV1CursorStore;
172
+ /** One isolated callback for state, event, advisory, and error observations. */
173
+ onObservation?: (observation: GscdumpRealtimeV1Observation) => unknown;
174
+ runtime?: GscdumpRealtimeV1Runtime;
175
+ sdkVersion?: string;
176
+ }
177
+ interface GscdumpRealtimeV1Client {
178
+ start: () => Promise<void>;
179
+ stop: () => void;
180
+ getSnapshot: () => GscdumpRealtimeV1Snapshot;
181
+ }
182
+ /**
183
+ * Own the v1 cursor/ACK correctness state machine. Framework adapters provide
184
+ * required effects; they never need to reproduce transport ordering rules.
185
+ */
186
+ declare function createGscdumpRealtimeV1Client(options: CreateGscdumpRealtimeV1ClientOptions): GscdumpRealtimeV1Client;
187
+ export { type CreateGscdumpRealtimeV1ClientOptions, type CreateGscdumpV1ClientOptions, GSCDUMP_REALTIME_V1_SDK_VERSION, type GscdumpRealtimeV1Client, type GscdumpRealtimeV1CursorStore, GscdumpRealtimeV1Error, type GscdumpRealtimeV1ErrorCode, type GscdumpRealtimeV1ErrorOptions, type GscdumpRealtimeV1Freshness, type GscdumpRealtimeV1Observation, type GscdumpRealtimeV1ResyncReason, type GscdumpRealtimeV1ResyncRequest, type GscdumpRealtimeV1Runtime, type GscdumpRealtimeV1Snapshot, type GscdumpRealtimeV1SocketLike, type GscdumpRealtimeV1TransportState, type GscdumpV1Client, type GscdumpV1CredentialResolver, GscdumpV1Error, type GscdumpV1ErrorOptions, type GscdumpV1ExecuteOptions, type GscdumpV1HeadersResolver, type GscdumpV1Operation, type GscdumpV1OperationId, type GscdumpV1OperationInput, type GscdumpV1OperationResponse, type GscdumpV1RetryOptions, type GscdumpV1SdkErrorCode, createGscdumpRealtimeV1Client, createGscdumpV1Client, isGscdumpV1Error };