@sanity/client 6.18.2 → 6.19.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 +1 -1
- package/dist/index.browser.cjs +34 -2
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +224 -0
- package/dist/index.browser.d.ts +224 -0
- package/dist/index.browser.js +34 -2
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +35 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +224 -0
- package/dist/index.d.ts +224 -0
- package/dist/index.js +35 -3
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/src/SanityClient.ts +31 -0
- package/src/data/dataMethods.ts +31 -2
- package/src/http/errors.ts +11 -2
- package/src/types.ts +223 -0
- package/umd/sanityClient.js +34 -2
- package/umd/sanityClient.min.js +2 -2
package/dist/index.browser.d.cts
CHANGED
|
@@ -12,6 +12,35 @@ import {StudioUrl} from '@sanity/client/csm'
|
|
|
12
12
|
import {adapter as unstable__adapter} from 'get-it'
|
|
13
13
|
import {environment as unstable__environment} from 'get-it'
|
|
14
14
|
|
|
15
|
+
/** @public */
|
|
16
|
+
export declare type Action =
|
|
17
|
+
| CreateAction
|
|
18
|
+
| ReplaceDraftAction
|
|
19
|
+
| EditAction
|
|
20
|
+
| DeleteAction
|
|
21
|
+
| DiscardAction
|
|
22
|
+
| PublishAction
|
|
23
|
+
| UnpublishAction
|
|
24
|
+
|
|
25
|
+
/** @internal */
|
|
26
|
+
export declare interface ActionError {
|
|
27
|
+
error: {
|
|
28
|
+
type: 'actionError'
|
|
29
|
+
description: string
|
|
30
|
+
items?: ActionErrorItem[]
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** @internal */
|
|
35
|
+
export declare interface ActionErrorItem {
|
|
36
|
+
error: {
|
|
37
|
+
type: string
|
|
38
|
+
description: string
|
|
39
|
+
value?: unknown
|
|
40
|
+
}
|
|
41
|
+
index: number
|
|
42
|
+
}
|
|
43
|
+
|
|
15
44
|
/** @internal */
|
|
16
45
|
export declare type AllDocumentIdsMutationOptions = BaseMutationOptions & {
|
|
17
46
|
returnFirst: false
|
|
@@ -106,6 +135,13 @@ export declare type AuthProviderResponse = {
|
|
|
106
135
|
providers: AuthProvider[]
|
|
107
136
|
}
|
|
108
137
|
|
|
138
|
+
/** @internal */
|
|
139
|
+
export declare type BaseActionOptions = RequestOptions & {
|
|
140
|
+
transactionId?: string
|
|
141
|
+
skipCrossDatasetReferenceValidation?: boolean
|
|
142
|
+
dryRun?: boolean
|
|
143
|
+
}
|
|
144
|
+
|
|
109
145
|
/** @internal */
|
|
110
146
|
export declare type BaseMutationOptions = RequestOptions & {
|
|
111
147
|
visibility?: 'sync' | 'async' | 'deferred'
|
|
@@ -444,6 +480,29 @@ export declare interface ContentSourceMapValueMapping {
|
|
|
444
480
|
source: ContentSourceMapSource
|
|
445
481
|
}
|
|
446
482
|
|
|
483
|
+
/**
|
|
484
|
+
* Creates a new draft document. The published version of the document must not already exist.
|
|
485
|
+
* If the draft version of the document already exists the action will fail by default, but
|
|
486
|
+
* this can be adjusted to instead leave the existing document in place.
|
|
487
|
+
*
|
|
488
|
+
* @public
|
|
489
|
+
*/
|
|
490
|
+
export declare type CreateAction = {
|
|
491
|
+
actionType: 'sanity.action.document.create'
|
|
492
|
+
/**
|
|
493
|
+
* ID of the published document to create a draft for.
|
|
494
|
+
*/
|
|
495
|
+
publishedId: string
|
|
496
|
+
/**
|
|
497
|
+
* Document to create. Requires a `_type` property.
|
|
498
|
+
*/
|
|
499
|
+
attributes: IdentifiedSanityDocumentStub
|
|
500
|
+
/**
|
|
501
|
+
* ifExists controls what to do if the draft already exists
|
|
502
|
+
*/
|
|
503
|
+
ifExists: 'fail' | 'ignore'
|
|
504
|
+
}
|
|
505
|
+
|
|
447
506
|
/** @public */
|
|
448
507
|
export declare const createClient: (config: ClientConfig) => SanityClient
|
|
449
508
|
|
|
@@ -519,6 +578,29 @@ export declare type DatasetsResponse = {
|
|
|
519
578
|
tags: string[]
|
|
520
579
|
}[]
|
|
521
580
|
|
|
581
|
+
/**
|
|
582
|
+
* Deletes the published version of a document and optionally some (likely all known) draft versions.
|
|
583
|
+
* If any draft version exists that is not specified for deletion this is an error.
|
|
584
|
+
* If the purge flag is set then the document history is also deleted.
|
|
585
|
+
*
|
|
586
|
+
* @public
|
|
587
|
+
*/
|
|
588
|
+
export declare type DeleteAction = {
|
|
589
|
+
actionType: 'sanity.action.document.delete'
|
|
590
|
+
/**
|
|
591
|
+
* Published document ID to delete
|
|
592
|
+
*/
|
|
593
|
+
publishedId: string
|
|
594
|
+
/**
|
|
595
|
+
* Draft document ID to delete
|
|
596
|
+
*/
|
|
597
|
+
includeDrafts: string[]
|
|
598
|
+
/**
|
|
599
|
+
* Delete document history
|
|
600
|
+
*/
|
|
601
|
+
purge: boolean
|
|
602
|
+
}
|
|
603
|
+
|
|
522
604
|
/**
|
|
523
605
|
* @public
|
|
524
606
|
* @deprecated Use the named export `createClient` instead of the `default` export
|
|
@@ -526,6 +608,24 @@ export declare type DatasetsResponse = {
|
|
|
526
608
|
declare const deprecatedCreateClient: (config: ClientConfig) => SanityClient
|
|
527
609
|
export default deprecatedCreateClient
|
|
528
610
|
|
|
611
|
+
/**
|
|
612
|
+
* Delete the draft version of a document.
|
|
613
|
+
* It is an error if it does not exist. If the purge flag is set, the document history is also deleted.
|
|
614
|
+
*
|
|
615
|
+
* @public
|
|
616
|
+
*/
|
|
617
|
+
export declare type DiscardAction = {
|
|
618
|
+
actionType: 'sanity.action.document.discard'
|
|
619
|
+
/**
|
|
620
|
+
* Draft document ID to delete
|
|
621
|
+
*/
|
|
622
|
+
draftId: string
|
|
623
|
+
/**
|
|
624
|
+
* Delete document history
|
|
625
|
+
*/
|
|
626
|
+
purge: boolean
|
|
627
|
+
}
|
|
628
|
+
|
|
529
629
|
/**
|
|
530
630
|
* The listener has been told to explicitly disconnect and not reconnect.
|
|
531
631
|
* This is a rare situation, but may occur if the API knows reconnect attempts will fail,
|
|
@@ -540,6 +640,29 @@ export declare type DisconnectEvent = {
|
|
|
540
640
|
reason: string
|
|
541
641
|
}
|
|
542
642
|
|
|
643
|
+
/**
|
|
644
|
+
* Modifies an existing draft document.
|
|
645
|
+
* It applies the given patch to the document referenced by draftId.
|
|
646
|
+
* If there is no such document then one is created using the current state of the published version and then that is updated accordingly.
|
|
647
|
+
*
|
|
648
|
+
* @public
|
|
649
|
+
*/
|
|
650
|
+
export declare type EditAction = {
|
|
651
|
+
actionType: 'sanity.action.document.edit'
|
|
652
|
+
/**
|
|
653
|
+
* Draft document ID to edit
|
|
654
|
+
*/
|
|
655
|
+
draftId: string
|
|
656
|
+
/**
|
|
657
|
+
* Published document ID to create draft from, if draft does not exist
|
|
658
|
+
*/
|
|
659
|
+
publishedId: string
|
|
660
|
+
/**
|
|
661
|
+
* Patch operations to apply
|
|
662
|
+
*/
|
|
663
|
+
patch: PatchOperations
|
|
664
|
+
}
|
|
665
|
+
|
|
543
666
|
/** @public */
|
|
544
667
|
export declare interface ErrorProps {
|
|
545
668
|
message: string
|
|
@@ -803,6 +926,11 @@ export declare type Logger =
|
|
|
803
926
|
Pick<typeof console, 'debug' | 'error' | 'groupCollapsed' | 'groupEnd' | 'log' | 'table'>
|
|
804
927
|
>
|
|
805
928
|
|
|
929
|
+
/** @internal */
|
|
930
|
+
export declare interface MultipleActionResult {
|
|
931
|
+
transactionId: string
|
|
932
|
+
}
|
|
933
|
+
|
|
806
934
|
/** @internal */
|
|
807
935
|
export declare interface MultipleMutationResult {
|
|
808
936
|
transactionId: string
|
|
@@ -1592,6 +1720,16 @@ export declare class ObservableSanityClient {
|
|
|
1592
1720
|
transaction<R extends Record<string, Any> = Record<string, Any>>(
|
|
1593
1721
|
operations?: Mutation<R>[],
|
|
1594
1722
|
): ObservableTransaction
|
|
1723
|
+
/**
|
|
1724
|
+
* Perform action operations against the configured dataset
|
|
1725
|
+
*
|
|
1726
|
+
* @param operations - Action operation(s) to execute
|
|
1727
|
+
* @param options - Action options
|
|
1728
|
+
*/
|
|
1729
|
+
action(
|
|
1730
|
+
operations: Action | Action[],
|
|
1731
|
+
options?: BaseActionOptions,
|
|
1732
|
+
): Observable<SingleActionResult | MultipleActionResult>
|
|
1595
1733
|
/**
|
|
1596
1734
|
* Perform an HTTP request against the Sanity API
|
|
1597
1735
|
*
|
|
@@ -1795,6 +1933,35 @@ export declare class ProjectsClient {
|
|
|
1795
1933
|
getById(projectId: string): Promise<SanityProject>
|
|
1796
1934
|
}
|
|
1797
1935
|
|
|
1936
|
+
/**
|
|
1937
|
+
* Publishes a draft document.
|
|
1938
|
+
* If a published version of the document already exists this is replaced by the current draft document.
|
|
1939
|
+
* In either case the draft document is deleted.
|
|
1940
|
+
* The optional revision id parameters can be used for optimistic locking to ensure
|
|
1941
|
+
* that the draft and/or published versions of the document have not been changed by another client.
|
|
1942
|
+
*
|
|
1943
|
+
* @public
|
|
1944
|
+
*/
|
|
1945
|
+
export declare type PublishAction = {
|
|
1946
|
+
actionType: 'sanity.action.document.publish'
|
|
1947
|
+
/**
|
|
1948
|
+
* Draft document ID to publish
|
|
1949
|
+
*/
|
|
1950
|
+
draftId: string
|
|
1951
|
+
/**
|
|
1952
|
+
* Draft revision ID to match
|
|
1953
|
+
*/
|
|
1954
|
+
ifDraftRevisionId: string
|
|
1955
|
+
/**
|
|
1956
|
+
* Published document ID to replace
|
|
1957
|
+
*/
|
|
1958
|
+
publishedId: string
|
|
1959
|
+
/**
|
|
1960
|
+
* Published revision ID to match
|
|
1961
|
+
*/
|
|
1962
|
+
ifPublishedRevisionId: string
|
|
1963
|
+
}
|
|
1964
|
+
|
|
1798
1965
|
/** @public */
|
|
1799
1966
|
export declare type QueryOptions =
|
|
1800
1967
|
| FilteredResponseQueryOptions
|
|
@@ -1890,6 +2057,28 @@ export declare type ReconnectEvent = {
|
|
|
1890
2057
|
type: 'reconnect'
|
|
1891
2058
|
}
|
|
1892
2059
|
|
|
2060
|
+
/**
|
|
2061
|
+
* Replaces an existing draft document.
|
|
2062
|
+
* At least one of the draft or published versions of the document must exist.
|
|
2063
|
+
*
|
|
2064
|
+
* @public
|
|
2065
|
+
*/
|
|
2066
|
+
export declare type ReplaceDraftAction = {
|
|
2067
|
+
actionType: 'sanity.action.document.replaceDraft'
|
|
2068
|
+
/**
|
|
2069
|
+
* Draft document ID to replace, if it exists.
|
|
2070
|
+
*/
|
|
2071
|
+
draftId: string
|
|
2072
|
+
/**
|
|
2073
|
+
* Published document ID to create draft from, if draft does not exist
|
|
2074
|
+
*/
|
|
2075
|
+
publishedId: string
|
|
2076
|
+
/**
|
|
2077
|
+
* Document to create if it does not already exist. Requires `_id` and `_type` properties.
|
|
2078
|
+
*/
|
|
2079
|
+
attributes: IdentifiedSanityDocumentStub
|
|
2080
|
+
}
|
|
2081
|
+
|
|
1893
2082
|
/** @public */
|
|
1894
2083
|
export declare const requester: Requester
|
|
1895
2084
|
|
|
@@ -2421,6 +2610,17 @@ export declare class SanityClient {
|
|
|
2421
2610
|
transaction<R extends Record<string, Any> = Record<string, Any>>(
|
|
2422
2611
|
operations?: Mutation<R>[],
|
|
2423
2612
|
): Transaction
|
|
2613
|
+
/**
|
|
2614
|
+
* Perform action operations against the configured dataset
|
|
2615
|
+
* Returns a promise that resolves to the transaction result
|
|
2616
|
+
*
|
|
2617
|
+
* @param operations - Action operation(s) to execute
|
|
2618
|
+
* @param options - Action options
|
|
2619
|
+
*/
|
|
2620
|
+
action(
|
|
2621
|
+
operations: Action | Action[],
|
|
2622
|
+
options?: BaseActionOptions,
|
|
2623
|
+
): Promise<SingleActionResult | MultipleActionResult>
|
|
2424
2624
|
/**
|
|
2425
2625
|
* Perform a request against the Sanity API
|
|
2426
2626
|
* NOTE: Only use this for Sanity API endpoints, not for your own APIs!
|
|
@@ -2577,6 +2777,11 @@ export declare class ServerError extends Error {
|
|
|
2577
2777
|
constructor(res: Any)
|
|
2578
2778
|
}
|
|
2579
2779
|
|
|
2780
|
+
/** @internal */
|
|
2781
|
+
export declare interface SingleActionResult {
|
|
2782
|
+
transactionId: string
|
|
2783
|
+
}
|
|
2784
|
+
|
|
2580
2785
|
/** @internal */
|
|
2581
2786
|
export declare interface SingleMutationResult {
|
|
2582
2787
|
transactionId: string
|
|
@@ -2741,6 +2946,25 @@ export declare interface UnfilteredResponseWithoutQuery extends ResponseQueryOpt
|
|
|
2741
2946
|
returnQuery: false
|
|
2742
2947
|
}
|
|
2743
2948
|
|
|
2949
|
+
/**
|
|
2950
|
+
* Retract a published document.
|
|
2951
|
+
* If there is no draft version then this is created from the published version.
|
|
2952
|
+
* In either case the published version is deleted.
|
|
2953
|
+
*
|
|
2954
|
+
* @public
|
|
2955
|
+
*/
|
|
2956
|
+
export declare type UnpublishAction = {
|
|
2957
|
+
actionType: 'sanity.action.document.unpublish'
|
|
2958
|
+
/**
|
|
2959
|
+
* Draft document ID to replace the published document with
|
|
2960
|
+
*/
|
|
2961
|
+
draftId: string
|
|
2962
|
+
/**
|
|
2963
|
+
* Published document ID to delete
|
|
2964
|
+
*/
|
|
2965
|
+
publishedId: string
|
|
2966
|
+
}
|
|
2967
|
+
|
|
2744
2968
|
export {unstable__adapter}
|
|
2745
2969
|
|
|
2746
2970
|
export {unstable__environment}
|
package/dist/index.browser.d.ts
CHANGED
|
@@ -12,6 +12,35 @@ import {StudioUrl} from '@sanity/client/csm'
|
|
|
12
12
|
import {adapter as unstable__adapter} from 'get-it'
|
|
13
13
|
import {environment as unstable__environment} from 'get-it'
|
|
14
14
|
|
|
15
|
+
/** @public */
|
|
16
|
+
export declare type Action =
|
|
17
|
+
| CreateAction
|
|
18
|
+
| ReplaceDraftAction
|
|
19
|
+
| EditAction
|
|
20
|
+
| DeleteAction
|
|
21
|
+
| DiscardAction
|
|
22
|
+
| PublishAction
|
|
23
|
+
| UnpublishAction
|
|
24
|
+
|
|
25
|
+
/** @internal */
|
|
26
|
+
export declare interface ActionError {
|
|
27
|
+
error: {
|
|
28
|
+
type: 'actionError'
|
|
29
|
+
description: string
|
|
30
|
+
items?: ActionErrorItem[]
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** @internal */
|
|
35
|
+
export declare interface ActionErrorItem {
|
|
36
|
+
error: {
|
|
37
|
+
type: string
|
|
38
|
+
description: string
|
|
39
|
+
value?: unknown
|
|
40
|
+
}
|
|
41
|
+
index: number
|
|
42
|
+
}
|
|
43
|
+
|
|
15
44
|
/** @internal */
|
|
16
45
|
export declare type AllDocumentIdsMutationOptions = BaseMutationOptions & {
|
|
17
46
|
returnFirst: false
|
|
@@ -106,6 +135,13 @@ export declare type AuthProviderResponse = {
|
|
|
106
135
|
providers: AuthProvider[]
|
|
107
136
|
}
|
|
108
137
|
|
|
138
|
+
/** @internal */
|
|
139
|
+
export declare type BaseActionOptions = RequestOptions & {
|
|
140
|
+
transactionId?: string
|
|
141
|
+
skipCrossDatasetReferenceValidation?: boolean
|
|
142
|
+
dryRun?: boolean
|
|
143
|
+
}
|
|
144
|
+
|
|
109
145
|
/** @internal */
|
|
110
146
|
export declare type BaseMutationOptions = RequestOptions & {
|
|
111
147
|
visibility?: 'sync' | 'async' | 'deferred'
|
|
@@ -444,6 +480,29 @@ export declare interface ContentSourceMapValueMapping {
|
|
|
444
480
|
source: ContentSourceMapSource
|
|
445
481
|
}
|
|
446
482
|
|
|
483
|
+
/**
|
|
484
|
+
* Creates a new draft document. The published version of the document must not already exist.
|
|
485
|
+
* If the draft version of the document already exists the action will fail by default, but
|
|
486
|
+
* this can be adjusted to instead leave the existing document in place.
|
|
487
|
+
*
|
|
488
|
+
* @public
|
|
489
|
+
*/
|
|
490
|
+
export declare type CreateAction = {
|
|
491
|
+
actionType: 'sanity.action.document.create'
|
|
492
|
+
/**
|
|
493
|
+
* ID of the published document to create a draft for.
|
|
494
|
+
*/
|
|
495
|
+
publishedId: string
|
|
496
|
+
/**
|
|
497
|
+
* Document to create. Requires a `_type` property.
|
|
498
|
+
*/
|
|
499
|
+
attributes: IdentifiedSanityDocumentStub
|
|
500
|
+
/**
|
|
501
|
+
* ifExists controls what to do if the draft already exists
|
|
502
|
+
*/
|
|
503
|
+
ifExists: 'fail' | 'ignore'
|
|
504
|
+
}
|
|
505
|
+
|
|
447
506
|
/** @public */
|
|
448
507
|
export declare const createClient: (config: ClientConfig) => SanityClient
|
|
449
508
|
|
|
@@ -519,6 +578,29 @@ export declare type DatasetsResponse = {
|
|
|
519
578
|
tags: string[]
|
|
520
579
|
}[]
|
|
521
580
|
|
|
581
|
+
/**
|
|
582
|
+
* Deletes the published version of a document and optionally some (likely all known) draft versions.
|
|
583
|
+
* If any draft version exists that is not specified for deletion this is an error.
|
|
584
|
+
* If the purge flag is set then the document history is also deleted.
|
|
585
|
+
*
|
|
586
|
+
* @public
|
|
587
|
+
*/
|
|
588
|
+
export declare type DeleteAction = {
|
|
589
|
+
actionType: 'sanity.action.document.delete'
|
|
590
|
+
/**
|
|
591
|
+
* Published document ID to delete
|
|
592
|
+
*/
|
|
593
|
+
publishedId: string
|
|
594
|
+
/**
|
|
595
|
+
* Draft document ID to delete
|
|
596
|
+
*/
|
|
597
|
+
includeDrafts: string[]
|
|
598
|
+
/**
|
|
599
|
+
* Delete document history
|
|
600
|
+
*/
|
|
601
|
+
purge: boolean
|
|
602
|
+
}
|
|
603
|
+
|
|
522
604
|
/**
|
|
523
605
|
* @public
|
|
524
606
|
* @deprecated Use the named export `createClient` instead of the `default` export
|
|
@@ -526,6 +608,24 @@ export declare type DatasetsResponse = {
|
|
|
526
608
|
declare const deprecatedCreateClient: (config: ClientConfig) => SanityClient
|
|
527
609
|
export default deprecatedCreateClient
|
|
528
610
|
|
|
611
|
+
/**
|
|
612
|
+
* Delete the draft version of a document.
|
|
613
|
+
* It is an error if it does not exist. If the purge flag is set, the document history is also deleted.
|
|
614
|
+
*
|
|
615
|
+
* @public
|
|
616
|
+
*/
|
|
617
|
+
export declare type DiscardAction = {
|
|
618
|
+
actionType: 'sanity.action.document.discard'
|
|
619
|
+
/**
|
|
620
|
+
* Draft document ID to delete
|
|
621
|
+
*/
|
|
622
|
+
draftId: string
|
|
623
|
+
/**
|
|
624
|
+
* Delete document history
|
|
625
|
+
*/
|
|
626
|
+
purge: boolean
|
|
627
|
+
}
|
|
628
|
+
|
|
529
629
|
/**
|
|
530
630
|
* The listener has been told to explicitly disconnect and not reconnect.
|
|
531
631
|
* This is a rare situation, but may occur if the API knows reconnect attempts will fail,
|
|
@@ -540,6 +640,29 @@ export declare type DisconnectEvent = {
|
|
|
540
640
|
reason: string
|
|
541
641
|
}
|
|
542
642
|
|
|
643
|
+
/**
|
|
644
|
+
* Modifies an existing draft document.
|
|
645
|
+
* It applies the given patch to the document referenced by draftId.
|
|
646
|
+
* If there is no such document then one is created using the current state of the published version and then that is updated accordingly.
|
|
647
|
+
*
|
|
648
|
+
* @public
|
|
649
|
+
*/
|
|
650
|
+
export declare type EditAction = {
|
|
651
|
+
actionType: 'sanity.action.document.edit'
|
|
652
|
+
/**
|
|
653
|
+
* Draft document ID to edit
|
|
654
|
+
*/
|
|
655
|
+
draftId: string
|
|
656
|
+
/**
|
|
657
|
+
* Published document ID to create draft from, if draft does not exist
|
|
658
|
+
*/
|
|
659
|
+
publishedId: string
|
|
660
|
+
/**
|
|
661
|
+
* Patch operations to apply
|
|
662
|
+
*/
|
|
663
|
+
patch: PatchOperations
|
|
664
|
+
}
|
|
665
|
+
|
|
543
666
|
/** @public */
|
|
544
667
|
export declare interface ErrorProps {
|
|
545
668
|
message: string
|
|
@@ -803,6 +926,11 @@ export declare type Logger =
|
|
|
803
926
|
Pick<typeof console, 'debug' | 'error' | 'groupCollapsed' | 'groupEnd' | 'log' | 'table'>
|
|
804
927
|
>
|
|
805
928
|
|
|
929
|
+
/** @internal */
|
|
930
|
+
export declare interface MultipleActionResult {
|
|
931
|
+
transactionId: string
|
|
932
|
+
}
|
|
933
|
+
|
|
806
934
|
/** @internal */
|
|
807
935
|
export declare interface MultipleMutationResult {
|
|
808
936
|
transactionId: string
|
|
@@ -1592,6 +1720,16 @@ export declare class ObservableSanityClient {
|
|
|
1592
1720
|
transaction<R extends Record<string, Any> = Record<string, Any>>(
|
|
1593
1721
|
operations?: Mutation<R>[],
|
|
1594
1722
|
): ObservableTransaction
|
|
1723
|
+
/**
|
|
1724
|
+
* Perform action operations against the configured dataset
|
|
1725
|
+
*
|
|
1726
|
+
* @param operations - Action operation(s) to execute
|
|
1727
|
+
* @param options - Action options
|
|
1728
|
+
*/
|
|
1729
|
+
action(
|
|
1730
|
+
operations: Action | Action[],
|
|
1731
|
+
options?: BaseActionOptions,
|
|
1732
|
+
): Observable<SingleActionResult | MultipleActionResult>
|
|
1595
1733
|
/**
|
|
1596
1734
|
* Perform an HTTP request against the Sanity API
|
|
1597
1735
|
*
|
|
@@ -1795,6 +1933,35 @@ export declare class ProjectsClient {
|
|
|
1795
1933
|
getById(projectId: string): Promise<SanityProject>
|
|
1796
1934
|
}
|
|
1797
1935
|
|
|
1936
|
+
/**
|
|
1937
|
+
* Publishes a draft document.
|
|
1938
|
+
* If a published version of the document already exists this is replaced by the current draft document.
|
|
1939
|
+
* In either case the draft document is deleted.
|
|
1940
|
+
* The optional revision id parameters can be used for optimistic locking to ensure
|
|
1941
|
+
* that the draft and/or published versions of the document have not been changed by another client.
|
|
1942
|
+
*
|
|
1943
|
+
* @public
|
|
1944
|
+
*/
|
|
1945
|
+
export declare type PublishAction = {
|
|
1946
|
+
actionType: 'sanity.action.document.publish'
|
|
1947
|
+
/**
|
|
1948
|
+
* Draft document ID to publish
|
|
1949
|
+
*/
|
|
1950
|
+
draftId: string
|
|
1951
|
+
/**
|
|
1952
|
+
* Draft revision ID to match
|
|
1953
|
+
*/
|
|
1954
|
+
ifDraftRevisionId: string
|
|
1955
|
+
/**
|
|
1956
|
+
* Published document ID to replace
|
|
1957
|
+
*/
|
|
1958
|
+
publishedId: string
|
|
1959
|
+
/**
|
|
1960
|
+
* Published revision ID to match
|
|
1961
|
+
*/
|
|
1962
|
+
ifPublishedRevisionId: string
|
|
1963
|
+
}
|
|
1964
|
+
|
|
1798
1965
|
/** @public */
|
|
1799
1966
|
export declare type QueryOptions =
|
|
1800
1967
|
| FilteredResponseQueryOptions
|
|
@@ -1890,6 +2057,28 @@ export declare type ReconnectEvent = {
|
|
|
1890
2057
|
type: 'reconnect'
|
|
1891
2058
|
}
|
|
1892
2059
|
|
|
2060
|
+
/**
|
|
2061
|
+
* Replaces an existing draft document.
|
|
2062
|
+
* At least one of the draft or published versions of the document must exist.
|
|
2063
|
+
*
|
|
2064
|
+
* @public
|
|
2065
|
+
*/
|
|
2066
|
+
export declare type ReplaceDraftAction = {
|
|
2067
|
+
actionType: 'sanity.action.document.replaceDraft'
|
|
2068
|
+
/**
|
|
2069
|
+
* Draft document ID to replace, if it exists.
|
|
2070
|
+
*/
|
|
2071
|
+
draftId: string
|
|
2072
|
+
/**
|
|
2073
|
+
* Published document ID to create draft from, if draft does not exist
|
|
2074
|
+
*/
|
|
2075
|
+
publishedId: string
|
|
2076
|
+
/**
|
|
2077
|
+
* Document to create if it does not already exist. Requires `_id` and `_type` properties.
|
|
2078
|
+
*/
|
|
2079
|
+
attributes: IdentifiedSanityDocumentStub
|
|
2080
|
+
}
|
|
2081
|
+
|
|
1893
2082
|
/** @public */
|
|
1894
2083
|
export declare const requester: Requester
|
|
1895
2084
|
|
|
@@ -2421,6 +2610,17 @@ export declare class SanityClient {
|
|
|
2421
2610
|
transaction<R extends Record<string, Any> = Record<string, Any>>(
|
|
2422
2611
|
operations?: Mutation<R>[],
|
|
2423
2612
|
): Transaction
|
|
2613
|
+
/**
|
|
2614
|
+
* Perform action operations against the configured dataset
|
|
2615
|
+
* Returns a promise that resolves to the transaction result
|
|
2616
|
+
*
|
|
2617
|
+
* @param operations - Action operation(s) to execute
|
|
2618
|
+
* @param options - Action options
|
|
2619
|
+
*/
|
|
2620
|
+
action(
|
|
2621
|
+
operations: Action | Action[],
|
|
2622
|
+
options?: BaseActionOptions,
|
|
2623
|
+
): Promise<SingleActionResult | MultipleActionResult>
|
|
2424
2624
|
/**
|
|
2425
2625
|
* Perform a request against the Sanity API
|
|
2426
2626
|
* NOTE: Only use this for Sanity API endpoints, not for your own APIs!
|
|
@@ -2577,6 +2777,11 @@ export declare class ServerError extends Error {
|
|
|
2577
2777
|
constructor(res: Any)
|
|
2578
2778
|
}
|
|
2579
2779
|
|
|
2780
|
+
/** @internal */
|
|
2781
|
+
export declare interface SingleActionResult {
|
|
2782
|
+
transactionId: string
|
|
2783
|
+
}
|
|
2784
|
+
|
|
2580
2785
|
/** @internal */
|
|
2581
2786
|
export declare interface SingleMutationResult {
|
|
2582
2787
|
transactionId: string
|
|
@@ -2741,6 +2946,25 @@ export declare interface UnfilteredResponseWithoutQuery extends ResponseQueryOpt
|
|
|
2741
2946
|
returnQuery: false
|
|
2742
2947
|
}
|
|
2743
2948
|
|
|
2949
|
+
/**
|
|
2950
|
+
* Retract a published document.
|
|
2951
|
+
* If there is no draft version then this is created from the published version.
|
|
2952
|
+
* In either case the published version is deleted.
|
|
2953
|
+
*
|
|
2954
|
+
* @public
|
|
2955
|
+
*/
|
|
2956
|
+
export declare type UnpublishAction = {
|
|
2957
|
+
actionType: 'sanity.action.document.unpublish'
|
|
2958
|
+
/**
|
|
2959
|
+
* Draft document ID to replace the published document with
|
|
2960
|
+
*/
|
|
2961
|
+
draftId: string
|
|
2962
|
+
/**
|
|
2963
|
+
* Published document ID to delete
|
|
2964
|
+
*/
|
|
2965
|
+
publishedId: string
|
|
2966
|
+
}
|
|
2967
|
+
|
|
2744
2968
|
export {unstable__adapter}
|
|
2745
2969
|
|
|
2746
2970
|
export {unstable__environment}
|
package/dist/index.browser.js
CHANGED
|
@@ -27,7 +27,7 @@ function extractErrorProps(res) {
|
|
|
27
27
|
};
|
|
28
28
|
if (body.error && body.message)
|
|
29
29
|
return props.message = `${body.error} - ${body.message}`, props;
|
|
30
|
-
if (isMutationError(body)) {
|
|
30
|
+
if (isMutationError(body) || isActionError(body)) {
|
|
31
31
|
const allItems = body.error.items || [], items = allItems.slice(0, 5).map((item) => {
|
|
32
32
|
var _a;
|
|
33
33
|
return (_a = item.error) == null ? void 0 : _a.description;
|
|
@@ -43,6 +43,9 @@ function extractErrorProps(res) {
|
|
|
43
43
|
function isMutationError(body) {
|
|
44
44
|
return isPlainObject(body) && isPlainObject(body.error) && body.error.type === "mutationError" && typeof body.error.description == "string";
|
|
45
45
|
}
|
|
46
|
+
function isActionError(body) {
|
|
47
|
+
return isPlainObject(body) && isPlainObject(body.error) && body.error.type === "actionError" && typeof body.error.description == "string";
|
|
48
|
+
}
|
|
46
49
|
function isPlainObject(obj) {
|
|
47
50
|
return typeof obj == "object" && obj !== null && !Array.isArray(obj);
|
|
48
51
|
}
|
|
@@ -674,8 +677,18 @@ function _mutate(client, httpRequest, mutations, options) {
|
|
|
674
677
|
const muts = Array.isArray(mut) ? mut : [mut], transactionId = options && options.transactionId || void 0;
|
|
675
678
|
return _dataRequest(client, httpRequest, "mutate", { mutations: muts, transactionId }, options);
|
|
676
679
|
}
|
|
680
|
+
function _action(client, httpRequest, actions, options) {
|
|
681
|
+
const acts = Array.isArray(actions) ? actions : [actions], transactionId = options && options.transactionId || void 0, skipCrossDatasetReferenceValidation = options && options.skipCrossDatasetReferenceValidation || void 0, dryRun = options && options.dryRun || void 0;
|
|
682
|
+
return _dataRequest(
|
|
683
|
+
client,
|
|
684
|
+
httpRequest,
|
|
685
|
+
"actions",
|
|
686
|
+
{ actions: acts, transactionId, skipCrossDatasetReferenceValidation, dryRun },
|
|
687
|
+
options
|
|
688
|
+
);
|
|
689
|
+
}
|
|
677
690
|
function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
|
|
678
|
-
const isMutation = endpoint === "mutate", isQuery = endpoint === "query", strQuery = isMutation ? "" : encodeQueryString(body), useGet = !isMutation && strQuery.length < getQuerySizeLimit, stringQuery = useGet ? strQuery : "", returnFirst = options.returnFirst, { timeout, token, tag, headers, returnQuery, lastLiveEventId } = options, uri = _getDataUrl(client, endpoint, stringQuery), reqOptions = {
|
|
691
|
+
const isMutation = endpoint === "mutate", isAction = endpoint === "actions", isQuery = endpoint === "query", strQuery = isMutation || isAction ? "" : encodeQueryString(body), useGet = !isMutation && !isAction && strQuery.length < getQuerySizeLimit, stringQuery = useGet ? strQuery : "", returnFirst = options.returnFirst, { timeout, token, tag, headers, returnQuery, lastLiveEventId } = options, uri = _getDataUrl(client, endpoint, stringQuery), reqOptions = {
|
|
679
692
|
method: useGet ? "GET" : "POST",
|
|
680
693
|
uri,
|
|
681
694
|
json: !0,
|
|
@@ -1287,6 +1300,15 @@ const _ObservableSanityClient = class _ObservableSanityClient2 {
|
|
|
1287
1300
|
transaction(operations) {
|
|
1288
1301
|
return new ObservableTransaction(operations, this);
|
|
1289
1302
|
}
|
|
1303
|
+
/**
|
|
1304
|
+
* Perform action operations against the configured dataset
|
|
1305
|
+
*
|
|
1306
|
+
* @param operations - Action operation(s) to execute
|
|
1307
|
+
* @param options - Action options
|
|
1308
|
+
*/
|
|
1309
|
+
action(operations, options) {
|
|
1310
|
+
return _action(this, __privateGet(this, _httpRequest), operations, options);
|
|
1311
|
+
}
|
|
1290
1312
|
/**
|
|
1291
1313
|
* Perform an HTTP request against the Sanity API
|
|
1292
1314
|
*
|
|
@@ -1424,6 +1446,16 @@ const _SanityClient = class _SanityClient2 {
|
|
|
1424
1446
|
transaction(operations) {
|
|
1425
1447
|
return new Transaction(operations, this);
|
|
1426
1448
|
}
|
|
1449
|
+
/**
|
|
1450
|
+
* Perform action operations against the configured dataset
|
|
1451
|
+
* Returns a promise that resolves to the transaction result
|
|
1452
|
+
*
|
|
1453
|
+
* @param operations - Action operation(s) to execute
|
|
1454
|
+
* @param options - Action options
|
|
1455
|
+
*/
|
|
1456
|
+
action(operations, options) {
|
|
1457
|
+
return lastValueFrom(_action(this, __privateGet(this, _httpRequest2), operations, options));
|
|
1458
|
+
}
|
|
1427
1459
|
/**
|
|
1428
1460
|
* Perform a request against the Sanity API
|
|
1429
1461
|
* NOTE: Only use this for Sanity API endpoints, not for your own APIs!
|