@sanity/sdk 2.20.0 → 2.20.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/_exports/_internal.js +1 -1
- package/dist/index.js +1 -1
- package/dist/{telemetryManager-Bd3O8z2S.js → telemetryManager-w-AMXtmz.js} +2 -2
- package/dist/{telemetryManager-Bd3O8z2S.js.map → telemetryManager-w-AMXtmz.js.map} +1 -1
- package/dist/{version-DL2l07HG.js → version-ByqNiWrK.js} +2 -2
- package/dist/{version-DL2l07HG.js.map → version-ByqNiWrK.js.map} +1 -1
- package/package.json +4 -4
|
@@ -95,7 +95,7 @@ function initTelemetry(instance, projectId) {
|
|
|
95
95
|
projectId,
|
|
96
96
|
environment
|
|
97
97
|
}), Promise.all([
|
|
98
|
-
import("../telemetryManager-
|
|
98
|
+
import("../telemetryManager-w-AMXtmz.js").then((n) => n.t),
|
|
99
99
|
import("../clientStore-CMzJ7XhZ.js").then((n) => n.t),
|
|
100
100
|
import("../authStore-CWTAuieY.js").then((n) => n.n)
|
|
101
101
|
]).then(async ([{ createTelemetryManager }, { getClient }, { getTokenState }]) => {
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { A as defineStore, C as REQUEST_TAG_PREFIX, D as bindActionByResource, E
|
|
|
2
2
|
import { A as addComment, B as normalizeComment, C as getCommentThreadsState, D as resolveCommentThreads, F as removeCommentById, G as COMMENTS_API_VERSION, H as assertDatasetResource, I as restoreComments, K as setCleanupTimeout, L as rollbackCommentUpdate, M as clearPendingTransaction, N as getCommentsKey, O as resolveComments, P as receiveComment, R as setCommentCreateError, S as commentsStore, T as getCommentsState, U as getAddonDatasetState, V as toCommentFieldPath, W as provisionAddonDataset, _ as setUsersData, a as getQueryState, b as PROJECT_API_VERSION, c as getPerspectiveState, d as addSubscription, f as cancelRequest, g as removeSubscription, h as parseUsersKey, i as getQueryKey, j as applyCommentUpdate, k as toCommentsKeyParts, l as getActiveReleasesState, m as initializeRequest, n as transformProjectionToPreview, o as parseQueryKey, p as getUsersKey, q as insecureRandomId, r as PREVIEW_PROJECTION, s as resolveQuery, t as createGroqSearchFilter, u as getAllReleasesState, v as setUsersError, x as USERS_STATE_CLEAR_DELAY, y as updateLastLoadMoreRequest, z as setPendingTransaction } from "./createGroqSearchFilter-B0NdA-EP.js";
|
|
3
3
|
import { n as configureLogging$1, r as createLogger } from "./getEnv-76AjZd_f.js";
|
|
4
4
|
import { i as isDeepEqual, n as getClient, o as omitProperty, r as getClientState, s as pickProperties } from "./clientStore-CMzJ7XhZ.js";
|
|
5
|
-
import { t as CORE_SDK_VERSION } from "./version-
|
|
5
|
+
import { t as CORE_SDK_VERSION } from "./version-ByqNiWrK.js";
|
|
6
6
|
import { ClientError, CorsOriginError } from "@sanity/client";
|
|
7
7
|
import { EMPTY, NEVER, Observable, Subject, Subscription, asapScheduler, auditTime, catchError, combineLatest, concat, concatMap, debounceTime, defer, distinctUntilChanged, filter, first, firstValueFrom, from, fromEvent, groupBy, map, merge, mergeMap, of, pairwise, partition, race, retry, share, shareReplay, skip, startWith, switchMap, take, takeUntil, tap, throttle, throwError, timer, withLatestFrom } from "rxjs";
|
|
8
8
|
import { isKeySegment, isKeyedObject } from "@sanity/types";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-vyAXikos.js";
|
|
2
2
|
import { r as createLogger } from "./getEnv-76AjZd_f.js";
|
|
3
|
-
import { t as CORE_SDK_VERSION } from "./version-
|
|
3
|
+
import { t as CORE_SDK_VERSION } from "./version-ByqNiWrK.js";
|
|
4
4
|
import "@sanity/client";
|
|
5
5
|
import { createBatchedStore, defineEvent } from "@sanity/telemetry";
|
|
6
6
|
/** @internal */
|
|
@@ -124,4 +124,4 @@ function createTelemetryManager(options) {
|
|
|
124
124
|
}
|
|
125
125
|
export { telemetryManager_exports as t };
|
|
126
126
|
|
|
127
|
-
//# sourceMappingURL=telemetryManager-
|
|
127
|
+
//# sourceMappingURL=telemetryManager-w-AMXtmz.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telemetryManager-
|
|
1
|
+
{"version":3,"file":"telemetryManager-w-AMXtmz.js","names":[],"sources":["../src/telemetry/events.ts","../src/telemetry/telemetryManager.ts"],"sourcesContent":["import {defineEvent} from '@sanity/telemetry'\n\n/** @internal */\nexport const SDKSessionStarted = defineEvent<{\n version: string\n projectId: string\n perspective: string\n authMethod: string\n}>({\n name: 'SDK Session Started',\n version: 1,\n description: 'SDK instance created (environment is recorded in the event context)',\n})\n\n/** @internal */\nexport const SDKHookMounted = defineEvent<{\n hookName: string\n}>({\n name: 'SDK Hook Mounted',\n version: 1,\n description: 'An SDK hook was mounted for the first time in this session',\n})\n\n/** @internal */\nexport const SDKSessionEnded = defineEvent<{\n durationSeconds: number\n hooksUsed: string[]\n}>({\n name: 'SDK Session Ended',\n version: 1,\n description: 'SDK instance disposed (environment is recorded in the event context)',\n})\n\n/** @internal */\nexport const SDKError = defineEvent<{\n errorType: string\n hookName: string\n}>({\n name: 'SDK Error',\n version: 1,\n description: 'Runtime error caught in the SDK',\n})\n","import {type SanityClient} from '@sanity/client'\nimport {\n type ConsentStatus,\n createBatchedStore,\n type SessionId,\n type TelemetryEvent,\n type TelemetryLogger,\n type TelemetryStore,\n} from '@sanity/telemetry'\n\nimport {createLogger} from '../utils/logger'\nimport {CORE_SDK_VERSION} from '../version'\nimport {type TelemetryEnvironment} from './environment'\nimport {SDKError, SDKHookMounted, SDKSessionEnded, SDKSessionStarted} from './events'\n\nconst FLUSH_INTERVAL_MS = 30_000\nconst CONSENT_TAG = 'telemetry-consent.sdk'\nconst BATCH_TAG = 'telemetry.batch'\n\nconst log = createLogger('telemetry')\n\n/**\n * Manages telemetry for a single SDK instance.\n *\n * Wraps `@sanity/telemetry`'s batched store with SDK-specific concerns:\n * consent caching, session lifecycle events, and hook usage tracking.\n * The `environment` is captured at construction time and recorded in\n * the event context so downstream pipelines can distinguish dev and\n * production sessions.\n *\n * @internal\n */\nexport interface TelemetryManager {\n /**\n * Eagerly resolve and cache the user's consent status.\n * Returns true only when the user has explicitly opted in (`granted`).\n * Call this before logging any events to avoid buffering events that\n * will be dropped on the first flush.\n */\n checkConsent(): Promise<boolean>\n\n /** Log a \"SDK Session Started\" event */\n logSessionStarted(data: {projectId: string; perspective: string; authMethod: string}): void\n\n /** Log a \"SDK Hook Mounted\" event (deduplicated per hook name) */\n logHookFirstUsed(hookName: string): void\n\n /** Log a \"SDK Error\" event */\n logError(errorType: string, hookName: string): void\n\n /** Log a \"SDK Session Ended\" event and tear down the store */\n endSession(): void\n\n /** Tear down the store without logging a session-end event */\n dispose(): void\n\n /** The set of hook names used during this session */\n readonly hooksUsed: ReadonlySet<string>\n}\n\ninterface TelemetryManagerOptions {\n sessionId: string\n getClient: () => SanityClient\n projectId: string\n environment: TelemetryEnvironment\n}\n\n/**\n * Creates a telemetry manager for a single SDK instance session.\n *\n * The manager initializes a `createBatchedStore` from `@sanity/telemetry`,\n * caches the consent check for the lifetime of the session, and provides\n * typed methods for each SDK telemetry event.\n *\n * @internal\n */\nexport function createTelemetryManager(options: TelemetryManagerOptions): TelemetryManager {\n const {sessionId, getClient, projectId, environment} = options\n const startedAt = Date.now()\n const emittedHooks = new Set<string>()\n\n let cachedConsent: {status: ConsentStatus} | null = null\n\n const resolveConsent = async (): Promise<{status: ConsentStatus}> => {\n if (cachedConsent) return cachedConsent\n try {\n const client = getClient()\n const result = await client.request<{status: ConsentStatus}>({\n uri: '/intake/telemetry-status',\n tag: CONSENT_TAG,\n })\n cachedConsent = result\n } catch {\n cachedConsent = {status: 'undetermined'}\n }\n return cachedConsent\n }\n\n const enrichBatch = (batch: TelemetryEvent[]) =>\n batch.map((event) => {\n // Trace events (`trace.start` / `trace.log` / `trace.error` /\n // `trace.complete`) arrive with their own caller-provided `context`.\n // Log / userProperties events don't. Narrow via `in` so `event`\n // stays typed as `TelemetryEvent`, then merge so we don't drop the\n // trace context. SDK-owned fields below win on conflict.\n const existing =\n 'context' in event ? (event.context as Record<string, unknown> | undefined) : undefined\n return {\n ...event,\n context: {\n ...existing,\n version: CORE_SDK_VERSION,\n environment,\n origin: typeof window !== 'undefined' ? window.location.origin : 'node',\n },\n }\n })\n\n const sendEvents = async (batch: TelemetryEvent[]): Promise<unknown> => {\n const client = getClient()\n log.debug('sending event batch', {batchSize: batch.length, environment})\n return client.request({\n uri: '/intake/batch',\n method: 'POST',\n body: {projectId, batch: enrichBatch(batch)},\n tag: BATCH_TAG,\n })\n }\n\n const store: TelemetryStore<Record<string, unknown>> = createBatchedStore(\n sessionId as SessionId,\n {\n flushInterval: FLUSH_INTERVAL_MS,\n resolveConsent,\n sendEvents,\n },\n )\n\n const logger: TelemetryLogger<Record<string, unknown>> = store.logger\n\n return {\n async checkConsent() {\n const {status} = await resolveConsent()\n return status === 'granted'\n },\n\n logSessionStarted(data) {\n log.debug('event: SDK Session Started', {\n projectId: data.projectId,\n perspective: data.perspective,\n authMethod: data.authMethod,\n version: CORE_SDK_VERSION,\n environment,\n })\n logger.log(SDKSessionStarted, {\n version: CORE_SDK_VERSION,\n ...data,\n })\n },\n\n logHookFirstUsed(hookName: string) {\n if (emittedHooks.has(hookName)) return\n emittedHooks.add(hookName)\n log.debug('event: SDK Hook Mounted', {hookName})\n logger.log(SDKHookMounted, {hookName})\n },\n\n logError(errorType: string, hookName: string) {\n log.debug('event: SDK Error', {errorType, hookName})\n logger.log(SDKError, {errorType, hookName})\n },\n\n endSession() {\n const durationSeconds = Math.round((Date.now() - startedAt) / 1000)\n log.debug('event: SDK Session Ended', {\n durationSeconds,\n hooksUsed: [...emittedHooks],\n environment,\n })\n logger.log(SDKSessionEnded, {\n durationSeconds,\n hooksUsed: [...emittedHooks],\n })\n\n store.flush().catch(() => {\n // Best-effort flush on dispose; swallow errors\n })\n store.end()\n },\n\n dispose() {\n store.end()\n },\n\n get hooksUsed(): ReadonlySet<string> {\n return emittedHooks\n },\n }\n}\n"],"mappings":";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AC,WAAU,MAAM,eAAe;GACtC,OAAO,WAAW;EACpB;EAEA,kBAAkB,MAAM;GAQtB,AAPA,IAAI,MAAM,8BAA8B;IACtC,WAAW,KAAK;IAChB,aAAa,KAAK;IAClB,YAAY,KAAK;IACjB,SAAS;IACT;GACF,CAAC,GACD,OAAO,IAAI,mBAAmB;IAC5B,SAAS;IACT,GAAG;GACL,CAAC;EACH;EAEA,iBAAiB,UAAkB;GAC7B,aAAa,IAAI,QAAQ,MAC7B,aAAa,IAAI,QAAQ,GACzB,IAAI,MAAM,2BAA2B,EAAC,SAAQ,CAAC,GAC/C,OAAO,IAAI,gBAAgB,EAAC,SAAQ,CAAC;EACvC;EAEA,SAAS,WAAmB,UAAkB;GAE5C,AADA,IAAI,MAAM,oBAAoB;IAAC;IAAW;GAAQ,CAAC,GACnD,OAAO,IAAI,UAAU;IAAC;IAAW;GAAQ,CAAC;EAC5C;EAEA,aAAa;GACX,IAAM,kBAAkB,KAAK,OAAO,KAAK,IAAI,IAAI,aAAa,GAAI;GAclE,AAbA,IAAI,MAAM,4BAA4B;IACpC;IACA,WAAW,CAAC,GAAG,YAAY;IAC3B;GACF,CAAC,GACD,OAAO,IAAI,iBAAiB;IAC1B;IACA,WAAW,CAAC,GAAG,YAAY;GAC7B,CAAC,GAED,MAAM,MAAM,CAAC,CAAC,YAAY,CAE1B,CAAC,GACD,MAAM,IAAI;EACZ;EAEA,UAAU;GACR,MAAM,IAAI;EACZ;EAEA,IAAI,YAAiC;GACnC,OAAO;EACT;CACF;AACF"}
|
|
@@ -3,7 +3,7 @@ import { t as getEnv } from "./getEnv-76AjZd_f.js";
|
|
|
3
3
|
* This version is provided by pkg-utils at build time
|
|
4
4
|
* @internal
|
|
5
5
|
*/
|
|
6
|
-
const CORE_SDK_VERSION = getEnv("PKG_VERSION") || "2.20.
|
|
6
|
+
const CORE_SDK_VERSION = getEnv("PKG_VERSION") || "2.20.1-development";
|
|
7
7
|
export { CORE_SDK_VERSION as t };
|
|
8
8
|
|
|
9
|
-
//# sourceMappingURL=version-
|
|
9
|
+
//# sourceMappingURL=version-ByqNiWrK.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version-
|
|
1
|
+
{"version":3,"file":"version-ByqNiWrK.js","names":[],"sources":["../package.json","../src/version.ts"],"sourcesContent":["","import {version} from '../package.json'\nimport {getEnv} from './utils/getEnv'\n\n/**\n * This version is provided by pkg-utils at build time\n * @internal\n */\nexport const CORE_SDK_VERSION = getEnv('PKG_VERSION') || `${version}-development`\n"],"mappings":";;;;;ACOA,MAAa,mBAAmB,OAAO,aAAa,KAAK"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/sdk",
|
|
3
|
-
"version": "2.20.
|
|
3
|
+
"version": "2.20.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Sanity SDK",
|
|
6
6
|
"keywords": [
|
|
@@ -70,11 +70,11 @@
|
|
|
70
70
|
"typescript": "^6.0.3",
|
|
71
71
|
"vite": "^8.1.5",
|
|
72
72
|
"vitest": "^4.1.10",
|
|
73
|
+
"@repo/config-eslint": "0.0.0",
|
|
73
74
|
"@repo/config-test": "0.0.1",
|
|
74
|
-
"@repo/package.config": "0.0.1",
|
|
75
|
-
"@repo/tsconfig": "0.0.1",
|
|
76
75
|
"@repo/package.bundle": "3.82.0",
|
|
77
|
-
"@repo/
|
|
76
|
+
"@repo/tsconfig": "0.0.1",
|
|
77
|
+
"@repo/package.config": "0.0.1"
|
|
78
78
|
},
|
|
79
79
|
"browserslist": "extends @sanity/browserslist-config",
|
|
80
80
|
"scripts": {
|