@sanity/client 7.11.1 → 7.11.2-audience-decide.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.
@@ -699,6 +699,10 @@ export declare interface ClientConfig {
699
699
  * @defaultValue 'published'
700
700
  */
701
701
  perspective?: ClientPerspective
702
+ /**
703
+ * Parameters to pass to Sanity Decide for personalisation
704
+ */
705
+ decideParameters?: DecideParameters
702
706
  apiHost?: string
703
707
  /**
704
708
  @remarks
@@ -1226,6 +1230,12 @@ export declare type DatasetsResponse = {
1226
1230
  tags: string[]
1227
1231
  }[]
1228
1232
 
1233
+ /** @public */
1234
+ export declare interface DecideParameters {
1235
+ audience: string | string[]
1236
+ [key: string]: unknown
1237
+ }
1238
+
1229
1239
  /**
1230
1240
  * Deletes the published version of a document and optionally some (likely all known) draft versions.
1231
1241
  * If any draft version exists that is not specified for deletion this is an error.
@@ -2018,6 +2028,21 @@ export declare type ImageDescriptionOperation = {
2018
2028
  }
2019
2029
  )
2020
2030
 
2031
+ /** @public */
2032
+ export declare type ImportReleaseAction =
2033
+ | {
2034
+ actionType: 'sanity.action.release.import'
2035
+ attributes: IdentifiedSanityDocumentStub
2036
+ releaseId: string
2037
+ ifExists: 'fail' | 'ignore' | 'replace'
2038
+ }
2039
+ | {
2040
+ actionType: 'sanity.action.release.import'
2041
+ document: IdentifiedSanityDocumentStub
2042
+ releaseId: string
2043
+ ifExists: 'fail' | 'ignore' | 'replace'
2044
+ }
2045
+
2021
2046
  /** @public */
2022
2047
  export declare interface InitializedClientConfig extends ClientConfig {
2023
2048
  apiHost: string
@@ -4296,6 +4321,8 @@ export declare interface QueryParams {
4296
4321
  /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
4297
4322
  cache?: 'next' extends keyof RequestInit ? never : any
4298
4323
  /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
4324
+ decideParameters?: never
4325
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
4299
4326
  filterResponse?: never
4300
4327
  /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
4301
4328
  headers?: never
@@ -4407,6 +4434,7 @@ export declare type ReleaseAction =
4407
4434
  | ScheduleReleaseAction
4408
4435
  | UnscheduleReleaseAction
4409
4436
  | DeleteReleaseAction
4437
+ | ImportReleaseAction
4410
4438
 
4411
4439
  /** @public */
4412
4440
  export declare type ReleaseCardinality = 'many' | 'one' | undefined
@@ -4807,6 +4835,7 @@ export declare interface RequestObservableOptions extends Omit<RequestOptions, '
4807
4835
  returnQuery?: boolean
4808
4836
  resultSourceMap?: boolean | 'withKeyArraySelector'
4809
4837
  perspective?: ClientPerspective
4838
+ decideParameters?: DecideParameters
4810
4839
  lastLiveEventId?: string
4811
4840
  cacheMode?: 'noStale'
4812
4841
  }
@@ -4842,6 +4871,7 @@ export declare interface ResponseEvent<T = unknown> {
4842
4871
  /** @public */
4843
4872
  export declare interface ResponseQueryOptions extends RequestOptions {
4844
4873
  perspective?: ClientPerspective
4874
+ decideParameters?: DecideParameters
4845
4875
  resultSourceMap?: boolean | 'withKeyArraySelector'
4846
4876
  returnQuery?: boolean
4847
4877
  useCdn?: boolean
@@ -699,6 +699,10 @@ export declare interface ClientConfig {
699
699
  * @defaultValue 'published'
700
700
  */
701
701
  perspective?: ClientPerspective
702
+ /**
703
+ * Parameters to pass to Sanity Decide for personalisation
704
+ */
705
+ decideParameters?: DecideParameters
702
706
  apiHost?: string
703
707
  /**
704
708
  @remarks
@@ -1226,6 +1230,12 @@ export declare type DatasetsResponse = {
1226
1230
  tags: string[]
1227
1231
  }[]
1228
1232
 
1233
+ /** @public */
1234
+ export declare interface DecideParameters {
1235
+ audience: string | string[]
1236
+ [key: string]: unknown
1237
+ }
1238
+
1229
1239
  /**
1230
1240
  * Deletes the published version of a document and optionally some (likely all known) draft versions.
1231
1241
  * If any draft version exists that is not specified for deletion this is an error.
@@ -2018,6 +2028,21 @@ export declare type ImageDescriptionOperation = {
2018
2028
  }
2019
2029
  )
2020
2030
 
2031
+ /** @public */
2032
+ export declare type ImportReleaseAction =
2033
+ | {
2034
+ actionType: 'sanity.action.release.import'
2035
+ attributes: IdentifiedSanityDocumentStub
2036
+ releaseId: string
2037
+ ifExists: 'fail' | 'ignore' | 'replace'
2038
+ }
2039
+ | {
2040
+ actionType: 'sanity.action.release.import'
2041
+ document: IdentifiedSanityDocumentStub
2042
+ releaseId: string
2043
+ ifExists: 'fail' | 'ignore' | 'replace'
2044
+ }
2045
+
2021
2046
  /** @public */
2022
2047
  export declare interface InitializedClientConfig extends ClientConfig {
2023
2048
  apiHost: string
@@ -4296,6 +4321,8 @@ export declare interface QueryParams {
4296
4321
  /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
4297
4322
  cache?: 'next' extends keyof RequestInit ? never : any
4298
4323
  /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
4324
+ decideParameters?: never
4325
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
4299
4326
  filterResponse?: never
4300
4327
  /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
4301
4328
  headers?: never
@@ -4407,6 +4434,7 @@ export declare type ReleaseAction =
4407
4434
  | ScheduleReleaseAction
4408
4435
  | UnscheduleReleaseAction
4409
4436
  | DeleteReleaseAction
4437
+ | ImportReleaseAction
4410
4438
 
4411
4439
  /** @public */
4412
4440
  export declare type ReleaseCardinality = 'many' | 'one' | undefined
@@ -4807,6 +4835,7 @@ export declare interface RequestObservableOptions extends Omit<RequestOptions, '
4807
4835
  returnQuery?: boolean
4808
4836
  resultSourceMap?: boolean | 'withKeyArraySelector'
4809
4837
  perspective?: ClientPerspective
4838
+ decideParameters?: DecideParameters
4810
4839
  lastLiveEventId?: string
4811
4840
  cacheMode?: 'noStale'
4812
4841
  }
@@ -4842,6 +4871,7 @@ export declare interface ResponseEvent<T = unknown> {
4842
4871
  /** @public */
4843
4872
  export declare interface ResponseQueryOptions extends RequestOptions {
4844
4873
  perspective?: ClientPerspective
4874
+ decideParameters?: DecideParameters
4845
4875
  resultSourceMap?: boolean | 'withKeyArraySelector'
4846
4876
  returnQuery?: boolean
4847
4877
  useCdn?: boolean
package/dist/stega.d.cts CHANGED
@@ -699,6 +699,10 @@ export declare interface ClientConfig {
699
699
  * @defaultValue 'published'
700
700
  */
701
701
  perspective?: ClientPerspective
702
+ /**
703
+ * Parameters to pass to Sanity Decide for personalisation
704
+ */
705
+ decideParameters?: DecideParameters
702
706
  apiHost?: string
703
707
  /**
704
708
  @remarks
@@ -1226,6 +1230,12 @@ export declare type DatasetsResponse = {
1226
1230
  tags: string[]
1227
1231
  }[]
1228
1232
 
1233
+ /** @public */
1234
+ export declare interface DecideParameters {
1235
+ audience: string | string[]
1236
+ [key: string]: unknown
1237
+ }
1238
+
1229
1239
  /**
1230
1240
  * Deletes the published version of a document and optionally some (likely all known) draft versions.
1231
1241
  * If any draft version exists that is not specified for deletion this is an error.
@@ -2018,6 +2028,21 @@ export declare type ImageDescriptionOperation = {
2018
2028
  }
2019
2029
  )
2020
2030
 
2031
+ /** @public */
2032
+ export declare type ImportReleaseAction =
2033
+ | {
2034
+ actionType: 'sanity.action.release.import'
2035
+ attributes: IdentifiedSanityDocumentStub
2036
+ releaseId: string
2037
+ ifExists: 'fail' | 'ignore' | 'replace'
2038
+ }
2039
+ | {
2040
+ actionType: 'sanity.action.release.import'
2041
+ document: IdentifiedSanityDocumentStub
2042
+ releaseId: string
2043
+ ifExists: 'fail' | 'ignore' | 'replace'
2044
+ }
2045
+
2021
2046
  /** @public */
2022
2047
  export declare interface InitializedClientConfig extends ClientConfig {
2023
2048
  apiHost: string
@@ -4296,6 +4321,8 @@ export declare interface QueryParams {
4296
4321
  /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
4297
4322
  cache?: 'next' extends keyof RequestInit ? never : any
4298
4323
  /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
4324
+ decideParameters?: never
4325
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
4299
4326
  filterResponse?: never
4300
4327
  /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
4301
4328
  headers?: never
@@ -4407,6 +4434,7 @@ export declare type ReleaseAction =
4407
4434
  | ScheduleReleaseAction
4408
4435
  | UnscheduleReleaseAction
4409
4436
  | DeleteReleaseAction
4437
+ | ImportReleaseAction
4410
4438
 
4411
4439
  /** @public */
4412
4440
  export declare type ReleaseCardinality = 'many' | 'one' | undefined
@@ -4807,6 +4835,7 @@ export declare interface RequestObservableOptions extends Omit<RequestOptions, '
4807
4835
  returnQuery?: boolean
4808
4836
  resultSourceMap?: boolean | 'withKeyArraySelector'
4809
4837
  perspective?: ClientPerspective
4838
+ decideParameters?: DecideParameters
4810
4839
  lastLiveEventId?: string
4811
4840
  cacheMode?: 'noStale'
4812
4841
  }
@@ -4842,6 +4871,7 @@ export declare interface ResponseEvent<T = unknown> {
4842
4871
  /** @public */
4843
4872
  export declare interface ResponseQueryOptions extends RequestOptions {
4844
4873
  perspective?: ClientPerspective
4874
+ decideParameters?: DecideParameters
4845
4875
  resultSourceMap?: boolean | 'withKeyArraySelector'
4846
4876
  returnQuery?: boolean
4847
4877
  useCdn?: boolean
package/dist/stega.d.ts CHANGED
@@ -699,6 +699,10 @@ export declare interface ClientConfig {
699
699
  * @defaultValue 'published'
700
700
  */
701
701
  perspective?: ClientPerspective
702
+ /**
703
+ * Parameters to pass to Sanity Decide for personalisation
704
+ */
705
+ decideParameters?: DecideParameters
702
706
  apiHost?: string
703
707
  /**
704
708
  @remarks
@@ -1226,6 +1230,12 @@ export declare type DatasetsResponse = {
1226
1230
  tags: string[]
1227
1231
  }[]
1228
1232
 
1233
+ /** @public */
1234
+ export declare interface DecideParameters {
1235
+ audience: string | string[]
1236
+ [key: string]: unknown
1237
+ }
1238
+
1229
1239
  /**
1230
1240
  * Deletes the published version of a document and optionally some (likely all known) draft versions.
1231
1241
  * If any draft version exists that is not specified for deletion this is an error.
@@ -2018,6 +2028,21 @@ export declare type ImageDescriptionOperation = {
2018
2028
  }
2019
2029
  )
2020
2030
 
2031
+ /** @public */
2032
+ export declare type ImportReleaseAction =
2033
+ | {
2034
+ actionType: 'sanity.action.release.import'
2035
+ attributes: IdentifiedSanityDocumentStub
2036
+ releaseId: string
2037
+ ifExists: 'fail' | 'ignore' | 'replace'
2038
+ }
2039
+ | {
2040
+ actionType: 'sanity.action.release.import'
2041
+ document: IdentifiedSanityDocumentStub
2042
+ releaseId: string
2043
+ ifExists: 'fail' | 'ignore' | 'replace'
2044
+ }
2045
+
2021
2046
  /** @public */
2022
2047
  export declare interface InitializedClientConfig extends ClientConfig {
2023
2048
  apiHost: string
@@ -4296,6 +4321,8 @@ export declare interface QueryParams {
4296
4321
  /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
4297
4322
  cache?: 'next' extends keyof RequestInit ? never : any
4298
4323
  /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
4324
+ decideParameters?: never
4325
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
4299
4326
  filterResponse?: never
4300
4327
  /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
4301
4328
  headers?: never
@@ -4407,6 +4434,7 @@ export declare type ReleaseAction =
4407
4434
  | ScheduleReleaseAction
4408
4435
  | UnscheduleReleaseAction
4409
4436
  | DeleteReleaseAction
4437
+ | ImportReleaseAction
4410
4438
 
4411
4439
  /** @public */
4412
4440
  export declare type ReleaseCardinality = 'many' | 'one' | undefined
@@ -4807,6 +4835,7 @@ export declare interface RequestObservableOptions extends Omit<RequestOptions, '
4807
4835
  returnQuery?: boolean
4808
4836
  resultSourceMap?: boolean | 'withKeyArraySelector'
4809
4837
  perspective?: ClientPerspective
4838
+ decideParameters?: DecideParameters
4810
4839
  lastLiveEventId?: string
4811
4840
  cacheMode?: 'noStale'
4812
4841
  }
@@ -4842,6 +4871,7 @@ export declare interface ResponseEvent<T = unknown> {
4842
4871
  /** @public */
4843
4872
  export declare interface ResponseQueryOptions extends RequestOptions {
4844
4873
  perspective?: ClientPerspective
4874
+ decideParameters?: DecideParameters
4845
4875
  resultSourceMap?: boolean | 'withKeyArraySelector'
4846
4876
  returnQuery?: boolean
4847
4877
  useCdn?: boolean
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/client",
3
- "version": "7.11.1",
3
+ "version": "7.11.2-audience-decide.1",
4
4
  "description": "Client for retrieving, creating and patching data from Sanity.io",
5
5
  "keywords": [
6
6
  "sanity",
@@ -44,6 +44,7 @@ import {
44
44
  printCreateVersionWithBaseIdWarning,
45
45
  printPreviewDraftsDeprecationWarning,
46
46
  } from '../warnings'
47
+ import {processDecideFields} from './decideResponseProcessor'
47
48
  import {encodeQueryString} from './encodeQueryString'
48
49
  import {ObservablePatch, Patch} from './patch'
49
50
  import {ObservableTransaction, Transaction} from './transaction'
@@ -97,6 +98,20 @@ export function _fetch<R, Q>(
97
98
  const mapResponse =
98
99
  options.filterResponse === false ? (res: Any) => res : (res: Any) => res.result
99
100
 
101
+ // Helper function to apply decide processing to response data
102
+ const processDecideResponse = (response: Any): Any => {
103
+ if (options.decideParameters && options.decideParameters.audience) {
104
+ // eslint-disable-next-line no-console
105
+ console.log('Processing response with decideParameters:', {
106
+ audience: options.decideParameters.audience,
107
+ decideParameters: options.decideParameters,
108
+ })
109
+ const processedData = processDecideFields(response, options.decideParameters)
110
+ return processedData
111
+ }
112
+ return response
113
+ }
114
+
100
115
  const {cache, next, ...opts} = {
101
116
  // Opt out of setting a `signal` on an internal `fetch` if one isn't provided.
102
117
  // This is necessary in React Server Components to avoid opting out of Request Memoization.
@@ -129,11 +144,12 @@ export function _fetch<R, Q>(
129
144
  (typeof import('../stega/stegaEncodeSourceMap'))['stegaEncodeSourceMap'],
130
145
  ]) => {
131
146
  const result = stegaEncodeSourceMap(res.result, res.resultSourceMap, stega)
132
- return mapResponse({...res, result})
147
+ const mappedResponse = mapResponse({...res, result})
148
+ return processDecideResponse(mappedResponse)
133
149
  },
134
150
  ),
135
151
  )
136
- : $request.pipe(map(mapResponse))
152
+ : $request.pipe(map(mapResponse), map(processDecideResponse))
137
153
  }
138
154
 
139
155
  /** @internal */
@@ -504,6 +520,7 @@ export function _dataRequest(
504
520
  tag,
505
521
  returnQuery,
506
522
  perspective: options.perspective,
523
+ decideParameters: options.decideParameters,
507
524
  resultSourceMap: options.resultSourceMap,
508
525
  lastLiveEventId: Array.isArray(lastLiveEventId) ? lastLiveEventId[0] : lastLiveEventId,
509
526
  cacheMode: cacheMode,
@@ -646,6 +663,31 @@ export function _requestObservable<R>(
646
663
  }
647
664
  }
648
665
 
666
+ // Process decideParameters
667
+ const decideParametersOption = options.decideParameters || config.decideParameters
668
+ if (decideParametersOption && typeof decideParametersOption === 'object') {
669
+ // eslint-disable-next-line no-console
670
+ console.log('DecideParameters received:', decideParametersOption)
671
+
672
+ // Add decide parameters to query string
673
+ const decideQueryParams = Object.keys(decideParametersOption).reduce(
674
+ (acc, key) => {
675
+ // Prefix decide parameters to avoid conflicts
676
+ acc[`decide.${key}`] = decideParametersOption[key]
677
+ return acc
678
+ },
679
+ {} as Record<string, unknown>,
680
+ )
681
+
682
+ // eslint-disable-next-line no-console
683
+ console.log('DecideParameters transformed to query params:', decideQueryParams)
684
+
685
+ options.query = {
686
+ ...options.query,
687
+ ...decideQueryParams,
688
+ }
689
+ }
690
+
649
691
  if (options.lastLiveEventId) {
650
692
  options.query = {...options.query, lastLiveEventId: options.lastLiveEventId}
651
693
  }
@@ -0,0 +1,114 @@
1
+ import type {DecideParameters} from '../types'
2
+
3
+ /**
4
+ * @internal
5
+ */
6
+ export interface DecideCondition {
7
+ audience: string
8
+ value: unknown
9
+ [key: string]: unknown
10
+ }
11
+
12
+ /**
13
+ * @internal
14
+ */
15
+ export interface DecideField {
16
+ default: unknown
17
+ conditions: DecideCondition[]
18
+ }
19
+
20
+ /**
21
+ * Checks if a value is a decide field with the expected structure
22
+ * @internal
23
+ */
24
+ export function isDecideField(value: unknown): value is DecideField {
25
+ return (
26
+ value != null &&
27
+ typeof value === 'object' &&
28
+ !Array.isArray(value) &&
29
+ 'default' in value &&
30
+ 'conditions' in value &&
31
+ Array.isArray(value.conditions)
32
+ )
33
+ }
34
+
35
+ /**
36
+ * Resolves a decide field based on the provided decide parameters
37
+ * @internal
38
+ */
39
+ export function resolveDecideField(
40
+ field: DecideField,
41
+ decideParameters: DecideParameters,
42
+ ): unknown {
43
+ const audience = decideParameters.audience
44
+
45
+ // Find matching condition for the audience
46
+ const matchingCondition = field.conditions.find((condition) => {
47
+ return Array.isArray(audience)
48
+ ? audience.includes(condition.audience)
49
+ : condition.audience === audience
50
+ })
51
+
52
+ // Return matching value or fall back to default
53
+ return matchingCondition ? matchingCondition.value : field.default
54
+ }
55
+
56
+ /**
57
+ * Recursively processes an object or array to resolve decide fields
58
+ * @internal
59
+ */
60
+ export function processObjectRecursively(
61
+ obj: unknown,
62
+ decideParameters: DecideParameters,
63
+ ): unknown {
64
+ // Handle null, undefined, or primitive values
65
+ if (obj === null || obj === undefined || typeof obj !== 'object') {
66
+ return obj
67
+ }
68
+
69
+ // Handle arrays
70
+ if (Array.isArray(obj)) {
71
+ return obj.map((item) => processObjectRecursively(item, decideParameters))
72
+ }
73
+
74
+ // Handle objects using reduce
75
+ return Object.entries(obj).reduce<Record<string, unknown>>((processed, [key, value]) => {
76
+ try {
77
+ if (isDecideField(value)) {
78
+ // Resolve decide field
79
+ processed[key] = resolveDecideField(value, decideParameters)
80
+ } else {
81
+ // Recursively process nested objects/arrays
82
+ processed[key] = processObjectRecursively(value, decideParameters)
83
+ }
84
+ } catch (error) {
85
+ // On error, preserve original value and continue
86
+ // eslint-disable-next-line no-console
87
+ console.warn(`Failed to process decide field '${key}':`, error)
88
+ processed[key] = value
89
+ }
90
+ return processed
91
+ }, {})
92
+ }
93
+
94
+ /**
95
+ * Main function to process decide fields in API response data
96
+ * @internal
97
+ */
98
+ export function processDecideFields(data: unknown, decideParameters: DecideParameters): unknown {
99
+ if (!decideParameters || !decideParameters.audience) {
100
+ return data
101
+ }
102
+
103
+ // eslint-disable-next-line no-console
104
+ console.log('Starting decide field processing with parameters:', decideParameters)
105
+
106
+ try {
107
+ return processObjectRecursively(data, decideParameters)
108
+ } catch (error) {
109
+ // On any processing error, return original data
110
+ // eslint-disable-next-line no-console
111
+ console.warn('Failed to process decide fields:', error)
112
+ return data
113
+ }
114
+ }
package/src/types.ts CHANGED
@@ -53,6 +53,12 @@ export type ClientPerspective =
53
53
  | 'raw'
54
54
  | StackablePerspective[]
55
55
 
56
+ /** @public */
57
+ export interface DecideParameters {
58
+ audience: string | string[]
59
+ [key: string]: unknown
60
+ }
61
+
56
62
  type ClientConfigResource =
57
63
  | {
58
64
  type: 'canvas'
@@ -89,6 +95,12 @@ export interface ClientConfig {
89
95
  * @defaultValue 'published'
90
96
  */
91
97
  perspective?: ClientPerspective
98
+
99
+ /**
100
+ * Parameters to pass to Sanity Decide for personalisation
101
+ */
102
+ decideParameters?: DecideParameters
103
+
92
104
  apiHost?: string
93
105
 
94
106
  /**
@@ -396,6 +408,7 @@ export interface RequestObservableOptions extends Omit<RequestOptions, 'url'> {
396
408
  returnQuery?: boolean
397
409
  resultSourceMap?: boolean | 'withKeyArraySelector'
398
410
  perspective?: ClientPerspective
411
+ decideParameters?: DecideParameters
399
412
  lastLiveEventId?: string
400
413
  cacheMode?: 'noStale'
401
414
  }
@@ -553,6 +566,8 @@ export interface QueryParams {
553
566
  /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
554
567
  cache?: 'next' extends keyof RequestInit ? never : any
555
568
  /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
569
+ decideParameters?: never
570
+ /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
556
571
  filterResponse?: never
557
572
  /** @deprecated you're using a fetch option as a GROQ parameter, this is likely a mistake */
558
573
  headers?: never
@@ -622,6 +637,7 @@ export type ReleaseAction =
622
637
  | ScheduleReleaseAction
623
638
  | UnscheduleReleaseAction
624
639
  | DeleteReleaseAction
640
+ | ImportReleaseAction
625
641
 
626
642
  /** @public */
627
643
  export type VersionAction =
@@ -642,6 +658,21 @@ export type Action =
642
658
  | VersionAction
643
659
  | ReleaseAction
644
660
 
661
+ /** @public */
662
+ export type ImportReleaseAction =
663
+ | {
664
+ actionType: 'sanity.action.release.import'
665
+ attributes: IdentifiedSanityDocumentStub
666
+ releaseId: string
667
+ ifExists: 'fail' | 'ignore' | 'replace'
668
+ }
669
+ | {
670
+ actionType: 'sanity.action.release.import'
671
+ document: IdentifiedSanityDocumentStub
672
+ releaseId: string
673
+ ifExists: 'fail' | 'ignore' | 'replace'
674
+ }
675
+
645
676
  /**
646
677
  * Creates a new release under the given id, with metadata.
647
678
  *
@@ -1215,6 +1246,7 @@ export interface ListenOptions {
1215
1246
  /** @public */
1216
1247
  export interface ResponseQueryOptions extends RequestOptions {
1217
1248
  perspective?: ClientPerspective
1249
+ decideParameters?: DecideParameters
1218
1250
  resultSourceMap?: boolean | 'withKeyArraySelector'
1219
1251
  returnQuery?: boolean
1220
1252
  useCdn?: boolean
@@ -2813,6 +2813,33 @@ ${selectionOpts}`);
2813
2813
  fetch: typeof overrides.fetch == "object" && typeof config.fetch == "object" ? { ...config.fetch, ...overrides.fetch } : overrides.fetch || config.fetch
2814
2814
  });
2815
2815
  }
2816
+ function isDecideField(value) {
2817
+ return value != null && typeof value == "object" && !Array.isArray(value) && "default" in value && "conditions" in value && Array.isArray(value.conditions);
2818
+ }
2819
+ function resolveDecideField(field, decideParameters) {
2820
+ const audience = decideParameters.audience, matchingCondition = field.conditions.find((condition) => Array.isArray(audience) ? audience.includes(condition.audience) : condition.audience === audience);
2821
+ return matchingCondition ? matchingCondition.value : field.default;
2822
+ }
2823
+ function processObjectRecursively(obj, decideParameters) {
2824
+ return obj == null || typeof obj != "object" ? obj : Array.isArray(obj) ? obj.map((item) => processObjectRecursively(item, decideParameters)) : Object.entries(obj).reduce((processed, [key, value]) => {
2825
+ try {
2826
+ isDecideField(value) ? processed[key] = resolveDecideField(value, decideParameters) : processed[key] = processObjectRecursively(value, decideParameters);
2827
+ } catch (error) {
2828
+ console.warn(`Failed to process decide field '${key}':`, error), processed[key] = value;
2829
+ }
2830
+ return processed;
2831
+ }, {});
2832
+ }
2833
+ function processDecideFields(data, decideParameters) {
2834
+ if (!decideParameters || !decideParameters.audience)
2835
+ return data;
2836
+ console.log("Starting decide field processing with parameters:", decideParameters);
2837
+ try {
2838
+ return processObjectRecursively(data, decideParameters);
2839
+ } catch (error) {
2840
+ return console.warn("Failed to process decide fields:", error), data;
2841
+ }
2842
+ }
2816
2843
  const encodeQueryString = ({
2817
2844
  query,
2818
2845
  params = {},
@@ -2837,7 +2864,10 @@ ${selectionOpts}`);
2837
2864
  const stega = "stega" in options ? {
2838
2865
  ..._stega || {},
2839
2866
  ...typeof options.stega == "boolean" ? { enabled: options.stega } : options.stega || {}
2840
- } : _stega, params = stega.enabled ? stegaClean(_params) : _params, mapResponse = options.filterResponse === false ? (res) => res : (res) => res.result, { cache, next, ...opts } = {
2867
+ } : _stega, params = stega.enabled ? stegaClean(_params) : _params, mapResponse = options.filterResponse === false ? (res) => res : (res) => res.result, processDecideResponse = (response) => options.decideParameters && options.decideParameters.audience ? (console.log("Processing response with decideParameters:", {
2868
+ audience: options.decideParameters.audience,
2869
+ decideParameters: options.decideParameters
2870
+ }), processDecideFields(response, options.decideParameters)) : response, { cache, next, ...opts } = {
2841
2871
  // Opt out of setting a `signal` on an internal `fetch` if one isn't provided.
2842
2872
  // This is necessary in React Server Components to avoid opting out of Request Memoization.
2843
2873
  useAbortSignal: typeof options.signal < "u",
@@ -2860,11 +2890,11 @@ ${selectionOpts}`);
2860
2890
  ),
2861
2891
  map(
2862
2892
  ([res, stegaEncodeSourceMap]) => {
2863
- const result = stegaEncodeSourceMap(res.result, res.resultSourceMap, stega);
2864
- return mapResponse({ ...res, result });
2893
+ const result = stegaEncodeSourceMap(res.result, res.resultSourceMap, stega), mappedResponse = mapResponse({ ...res, result });
2894
+ return processDecideResponse(mappedResponse);
2865
2895
  }
2866
2896
  )
2867
- ) : $request.pipe(map(mapResponse));
2897
+ ) : $request.pipe(map(mapResponse), map(processDecideResponse));
2868
2898
  }
2869
2899
  function _getDocument(client, httpRequest, id, opts = {}) {
2870
2900
  const docId = (() => {
@@ -3017,6 +3047,7 @@ ${selectionOpts}`);
3017
3047
  tag,
3018
3048
  returnQuery,
3019
3049
  perspective: options.perspective,
3050
+ decideParameters: options.decideParameters,
3020
3051
  resultSourceMap: options.resultSourceMap,
3021
3052
  lastLiveEventId: Array.isArray(lastLiveEventId) ? lastLiveEventId[0] : lastLiveEventId,
3022
3053
  cacheMode,
@@ -3061,7 +3092,20 @@ ${selectionOpts}`);
3061
3092
  perspective: Array.isArray(perspectiveOption) ? perspectiveOption.join(",") : perspectiveOption,
3062
3093
  ...options.query
3063
3094
  }, (Array.isArray(perspectiveOption) && perspectiveOption.length > 0 || // previewDrafts was renamed to drafts, but keep for backwards compat
3064
- perspectiveOption === "previewDrafts" || perspectiveOption === "drafts") && useCdn && (useCdn = false, printCdnPreviewDraftsWarning())), options.lastLiveEventId && (options.query = { ...options.query, lastLiveEventId: options.lastLiveEventId }), options.returnQuery === false && (options.query = { returnQuery: "false", ...options.query }), useCdn && options.cacheMode == "noStale" && (options.query = { cacheMode: "noStale", ...options.query });
3095
+ perspectiveOption === "previewDrafts" || perspectiveOption === "drafts") && useCdn && (useCdn = false, printCdnPreviewDraftsWarning()));
3096
+ const decideParametersOption = options.decideParameters || config.decideParameters;
3097
+ if (decideParametersOption && typeof decideParametersOption == "object") {
3098
+ console.log("DecideParameters received:", decideParametersOption);
3099
+ const decideQueryParams = Object.keys(decideParametersOption).reduce(
3100
+ (acc, key) => (acc[`decide.${key}`] = decideParametersOption[key], acc),
3101
+ {}
3102
+ );
3103
+ console.log("DecideParameters transformed to query params:", decideQueryParams), options.query = {
3104
+ ...options.query,
3105
+ ...decideQueryParams
3106
+ };
3107
+ }
3108
+ options.lastLiveEventId && (options.query = { ...options.query, lastLiveEventId: options.lastLiveEventId }), options.returnQuery === false && (options.query = { returnQuery: "false", ...options.query }), useCdn && options.cacheMode == "noStale" && (options.query = { cacheMode: "noStale", ...options.query });
3065
3109
  }
3066
3110
  const reqOptions = requestOptions(
3067
3111
  config,