diff --git a/src/csm/createEditUrl.ts b/src/csm/createEditUrl.ts index 4a458478..8bc361c1 100644 --- a/src/csm/createEditUrl.ts +++ b/src/csm/createEditUrl.ts @@ -7,8 +7,6 @@ import type {CreateEditUrlOptions, EditIntentUrl, StudioBaseUrl} from './types' export function createEditUrl(options: CreateEditUrlOptions): `${StudioBaseUrl}${EditIntentUrl}` { const { baseUrl, - projectId, - dataset, workspace: _workspace = 'default', tool: _tool = 'default', id: _id, @@ -19,12 +17,6 @@ export function createEditUrl(options: CreateEditUrlOptions): `${StudioBaseUrl}$ if (!baseUrl) { throw new Error('baseUrl is required') } - if (!projectId) { - throw new Error('projectId is required') - } - if (!dataset) { - throw new Error('dataset is required') - } if (!path) { throw new Error('path is required') } @@ -46,8 +38,6 @@ export function createEditUrl(options: CreateEditUrlOptions): `${StudioBaseUrl}$ // @TODO Using searchParams as a temporary workaround until `@sanity/overlays` can decode state from the path reliably const searchParams = new URLSearchParams({ baseUrl, - projectId, - dataset, id, type, path: stringifiedPath, diff --git a/src/csm/resolveEditInfo.ts b/src/csm/resolveEditInfo.ts index 17a67808..845472ce 100644 --- a/src/csm/resolveEditInfo.ts +++ b/src/csm/resolveEditInfo.ts @@ -34,11 +34,9 @@ export function resolveEditInfo(options: ResolveEditInfoOptions): CreateEditUrlO typeof options.studioUrl === 'function' ? options.studioUrl(sourceDoc) : options.studioUrl, ) if (!baseUrl) return undefined - const {_id, _type, _dataset = options.projectId, _projectId = options.dataset} = sourceDoc + const {_id, _type} = sourceDoc return { baseUrl, - projectId: _projectId, - dataset: _dataset, workspace, tool, id: _id, diff --git a/src/csm/resolveEditUrl.ts b/src/csm/resolveEditUrl.ts index f2d917bf..637b281f 100644 --- a/src/csm/resolveEditUrl.ts +++ b/src/csm/resolveEditUrl.ts @@ -7,12 +7,10 @@ import type {ResolveEditUrlOptions} from './types' export function resolveEditUrl( options: ResolveEditUrlOptions, ): ReturnType | undefined { - const {projectId, dataset, resultSourceMap, studioUrl} = options + const {resultSourceMap, studioUrl} = options const resultPath = studioPathToJsonPath(options.resultPath) const editInfo = resolveEditInfo({ - projectId, - dataset, resultPath, resultSourceMap, studioUrl, diff --git a/src/csm/types.ts b/src/csm/types.ts index 49ab6d38..85c2d1dc 100644 --- a/src/csm/types.ts +++ b/src/csm/types.ts @@ -63,8 +63,6 @@ export type EditIntentUrl = `/intent/edit/id=${string};type=${string};path=${str /** @internal */ export interface CreateEditUrlOptions { baseUrl: string - projectId: string - dataset: string workspace?: string tool?: string id: string @@ -73,8 +71,7 @@ export interface CreateEditUrlOptions { } /** @alpha */ -export interface ResolveEditInfoOptions - extends Pick { +export interface ResolveEditInfoOptions { studioUrl: StudioUrl | ResolveStudioUrl resultSourceMap: ContentSourceMap resultPath: ContentSourceMapParsedPath diff --git a/src/stega/SanityStegaClient.ts b/src/stega/SanityStegaClient.ts index a60e5a87..1f54bb8c 100644 --- a/src/stega/SanityStegaClient.ts +++ b/src/stega/SanityStegaClient.ts @@ -127,11 +127,7 @@ export class ObservableSanityStegaClient extends ObservableSanityClient { .pipe( map((res: Any) => { const {result: _result, resultSourceMap} = res as RawQueryResponse - const {projectId, dataset} = this.config() - const result = stegaEncodeSourceMap(_result, resultSourceMap, this.stegaConfig, { - projectId, - dataset, - }) + const result = stegaEncodeSourceMap(_result, resultSourceMap, this.stegaConfig) return originalFilterResponse ? result : {...res, result} }), ) @@ -255,11 +251,7 @@ export class SanityStegaClient extends SanityClient { ) .then((res: Any) => { const {result: _result, resultSourceMap} = res as RawQueryResponse - const {projectId, dataset} = this.config() - const result = stegaEncodeSourceMap(_result, resultSourceMap, this.stegaConfig, { - projectId, - dataset, - }) + const result = stegaEncodeSourceMap(_result, resultSourceMap, this.stegaConfig) return originalFilterResponse ? result : {...res, result} }) } diff --git a/src/stega/stegaEncodeSourceMap.ts b/src/stega/stegaEncodeSourceMap.ts index 55b7f271..f2483928 100644 --- a/src/stega/stegaEncodeSourceMap.ts +++ b/src/stega/stegaEncodeSourceMap.ts @@ -20,7 +20,6 @@ export function stegaEncodeSourceMap( result: Result, resultSourceMap: ContentSourceMap | undefined, config: InitializedStegaConfig, - clientConfig: {projectId: string | undefined; dataset: string | undefined}, ): Result { const {filter, vercelStegaCombineSkip, logger, enabled} = config if (!enabled) { @@ -49,14 +48,6 @@ export function stegaEncodeSourceMap( skipped: [], } - const {projectId, dataset} = clientConfig - if (!projectId) { - throw new Error('Missing projectId') - } - if (!dataset) { - throw new Error('Missing dataset') - } - const resultWithStega = encodeIntoResult( result, resultSourceMap, @@ -93,12 +84,7 @@ export function stegaEncodeSourceMap( : config.studioUrl!, ) if (!baseUrl) return value - const { - _id: id, - _type: type, - _dataset = clientConfig.projectId, - _projectId = clientConfig.dataset, - } = sourceDocument + const {_id: id, _type: type} = sourceDocument return vercelStegaCombine( value, @@ -106,8 +92,6 @@ export function stegaEncodeSourceMap( origin: 'sanity.io', href: createEditUrl({ baseUrl, - projectId: _projectId!, - dataset: _dataset!, workspace, tool, id, diff --git a/test/csm/createEditUrl.test.ts b/test/csm/createEditUrl.test.ts index 9cd37829..36bbe20f 100644 --- a/test/csm/createEditUrl.test.ts +++ b/test/csm/createEditUrl.test.ts @@ -4,8 +4,6 @@ import {createEditUrl} from '../../src/csm/createEditUrl' import {parseJsonPath} from '../../src/csm/jsonPath' const baseUrl = 'https://test.sanity.studio' -const projectId = 'abc123' -const dataset = 'production' const workspace = 'staging' const tool = 'content' const id = 'drafts.homepage' @@ -16,24 +14,22 @@ const cases = [ context: {baseUrl, workspace, tool, id, type}, path: parseJsonPath("$['foo'][?(@._key=='section-1')][0]['baz'][?(@._key=='section-2')]"), expected: - 'https://test.sanity.studio/staging/content/intent/edit/id=homepage;type=page;path=foo[_key=="section-1"][0].baz[_key=="section-2"]?baseUrl=https://test.sanity.studio&projectId=abc123&dataset=production&id=homepage&type=page&path=foo[_key=="section-1"][0].baz[_key=="section-2"]&workspace=staging&tool=content', + 'https://test.sanity.studio/staging/content/intent/edit/id=homepage;type=page;path=foo[_key=="section-1"][0].baz[_key=="section-2"]?baseUrl=https://test.sanity.studio&id=homepage&type=page&path=foo[_key=="section-1"][0].baz[_key=="section-2"]&workspace=staging&tool=content', }, { context: {baseUrl: '/', id, type}, path: parseJsonPath("$['foo'][?(@._key=='section-1')][0]"), expected: - '/intent/edit/id=homepage;type=page;path=foo[_key=="section-1"][0]?baseUrl=/&projectId=abc123&dataset=production&id=homepage&type=page&path=foo[_key=="section-1"][0]', + '/intent/edit/id=homepage;type=page;path=foo[_key=="section-1"][0]?baseUrl=/&id=homepage&type=page&path=foo[_key=="section-1"][0]', }, { context: {baseUrl: '/', workspace, tool, id, type}, path: parseJsonPath("$['foo'][?(@._key=='section-1')][0]"), expected: - '/staging/content/intent/edit/id=homepage;type=page;path=foo[_key=="section-1"][0]?baseUrl=/&projectId=abc123&dataset=production&id=homepage&type=page&path=foo[_key=="section-1"][0]&workspace=staging&tool=content', + '/staging/content/intent/edit/id=homepage;type=page;path=foo[_key=="section-1"][0]?baseUrl=/&id=homepage&type=page&path=foo[_key=="section-1"][0]&workspace=staging&tool=content', }, ] test.each(cases)('$expected', ({context, path, expected}) => { - expect(decodeURIComponent(createEditUrl({projectId, dataset, ...context, path}))).toEqual( - expected, - ) + expect(decodeURIComponent(createEditUrl({...context, path}))).toEqual(expected) }) diff --git a/test/csm/resolveEditUrl.test.ts b/test/csm/resolveEditUrl.test.ts index dff5e6dd..8fb90a0d 100644 --- a/test/csm/resolveEditUrl.test.ts +++ b/test/csm/resolveEditUrl.test.ts @@ -1,8 +1,6 @@ import {type ContentSourceMap, resolveEditUrl} from '@sanity/client/csm' import {expect, test} from 'vitest' -const projectId = 'abc123' -const dataset = 'production' const mock = { query: '{\n "products": *[_type == "product" && defined(slug.current)]{\n _id,\n title,\n description,\n slug,\n "media": media[0]\n },\n "siteSettings": *[_id == "siteSettings"][0]{\n title,\n copyrightText\n }\n}', @@ -503,19 +501,19 @@ const cases = [ path: 'products[0].title', studioUrl: 'https://test.sanity.studio', expected: - 'https://test.sanity.studio/intent/edit/id=462efcc6-3c8b-47c6-8474-5544e1a4acde;type=product;path=title?baseUrl=https://test.sanity.studio&projectId=production&dataset=abc123&id=462efcc6-3c8b-47c6-8474-5544e1a4acde&type=product&path=title', + 'https://test.sanity.studio/intent/edit/id=462efcc6-3c8b-47c6-8474-5544e1a4acde;type=product;path=title?baseUrl=https://test.sanity.studio&id=462efcc6-3c8b-47c6-8474-5544e1a4acde&type=product&path=title', }, { path: 'products[0].media.alt', studioUrl: '/', expected: - '/intent/edit/id=462efcc6-3c8b-47c6-8474-5544e1a4acde;type=product;path=media[_key=="cee5fbb69da2"].alt?baseUrl=/&projectId=production&dataset=abc123&id=462efcc6-3c8b-47c6-8474-5544e1a4acde&type=product&path=media[_key=="cee5fbb69da2"].alt', + '/intent/edit/id=462efcc6-3c8b-47c6-8474-5544e1a4acde;type=product;path=media[_key=="cee5fbb69da2"].alt?baseUrl=/&id=462efcc6-3c8b-47c6-8474-5544e1a4acde&type=product&path=media[_key=="cee5fbb69da2"].alt', }, { path: 'products[0].description[0].children[0].text', studioUrl: '/', expected: - '/intent/edit/id=462efcc6-3c8b-47c6-8474-5544e1a4acde;type=product;path=description[0].children[0].text?baseUrl=/&projectId=production&dataset=abc123&id=462efcc6-3c8b-47c6-8474-5544e1a4acde&type=product&path=description[0].children[0].text', + '/intent/edit/id=462efcc6-3c8b-47c6-8474-5544e1a4acde;type=product;path=description[0].children[0].text?baseUrl=/&id=462efcc6-3c8b-47c6-8474-5544e1a4acde&type=product&path=description[0].children[0].text', }, ] @@ -524,8 +522,6 @@ test.each(cases)('resolveEditUrl $path', ({path, studioUrl, expected}) => { expect( decodeURIComponent( resolveEditUrl({ - projectId, - dataset, studioUrl, resultSourceMap, resultPath: path, diff --git a/test/stega/client.test.ts b/test/stega/client.test.ts index 9a9b7302..9e80fe1e 100644 --- a/test/stega/client.test.ts +++ b/test/stega/client.test.ts @@ -99,18 +99,18 @@ describe('@sanity/client/stega', async () => { expect(vercelStegaSplit(res[0].title).cleaned).toBe(result[0].title) expect(vercelStegaDecode(res[0].title)).toMatchInlineSnapshot(` { - "href": "/studio/intent/edit/id=njgNkngskjg;type=beer;path=title?baseUrl=%2Fstudio&projectId=foo&dataset=bf1942&id=njgNkngskjg&type=beer&path=title", + "href": "/studio/intent/edit/id=njgNkngskjg;type=beer;path=title?baseUrl=%2Fstudio&id=njgNkngskjg&type=beer&path=title", "origin": "sanity.io", } `) expect(vercelStegaDecodeAll(JSON.stringify(res))).toMatchInlineSnapshot(` [ { - "href": "/studio/intent/edit/id=njgNkngskjg;type=beer;path=title?baseUrl=%2Fstudio&projectId=foo&dataset=bf1942&id=njgNkngskjg&type=beer&path=title", + "href": "/studio/intent/edit/id=njgNkngskjg;type=beer;path=title?baseUrl=%2Fstudio&id=njgNkngskjg&type=beer&path=title", "origin": "sanity.io", }, { - "href": "/studio/intent/edit/id=njgNkngskjg;type=beer;path=country?baseUrl=%2Fstudio&projectId=foo&dataset=bf1942&id=njgNkngskjg&type=beer&path=country", + "href": "/studio/intent/edit/id=njgNkngskjg;type=beer;path=country?baseUrl=%2Fstudio&id=njgNkngskjg&type=beer&path=country", "origin": "sanity.io", }, ] diff --git a/test/stega/stegaEncodeSourceMap.test.ts b/test/stega/stegaEncodeSourceMap.test.ts index 0465b1ea..29eb9c4e 100644 --- a/test/stega/stegaEncodeSourceMap.test.ts +++ b/test/stega/stegaEncodeSourceMap.test.ts @@ -5,8 +5,6 @@ import {defaultStegaConfig} from '../../src/stega/config' import {stegaEncodeSourceMap} from '../../src/stega/stegaEncodeSourceMap' import type {ContentSourceMap, Logger} from '../../src/stega/types' -const projectId = 'abc123' -const dataset = 'production' const mock = { query: '{\n "products": *[_type == "product" && defined(slug.current)]{\n _id,\n title,\n description,\n slug,\n "media": media[0]\n },\n "siteSettings": *[_id == "siteSettings"][0]{\n title,\n copyrightText\n }\n}', @@ -517,18 +515,13 @@ test.each(cases)('resolveEditUrl $studioUrl', ({studioUrl}) => { log: vi.fn(), table: vi.fn(), } satisfies Logger - const encoded = stegaEncodeSourceMap( - mock.result, - mock.resultSourceMap, - { - enabled: true, - studioUrl, - filter: defaultStegaConfig.filter!, - vercelStegaCombineSkip: defaultStegaConfig.vercelStegaCombineSkip!, - logger, - }, - {projectId, dataset}, - ) + const encoded = stegaEncodeSourceMap(mock.result, mock.resultSourceMap, { + enabled: true, + studioUrl, + filter: defaultStegaConfig.filter!, + vercelStegaCombineSkip: defaultStegaConfig.vercelStegaCombineSkip!, + logger, + }) expect( vercelStegaDecodeAll(JSON.stringify(encoded)).map( ({href}: any) => decodeURIComponent(href).split('?')[0],