@sanity/client 6.19.0 → 6.19.2

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
@@ -101,6 +101,15 @@ export async function updateDocumentTitle(_id, title) {
101
101
  - [2. Cancel a request by unsubscribing from the Observable](#2-cancel-a-request-by-unsubscribing-from-the-observable)
102
102
  - [Get client configuration](#get-client-configuration)
103
103
  - [Set client configuration](#set-client-configuration)
104
+ - [Server Side Actions](#server-side-actions)
105
+ - [Action options](#action-options)
106
+ - [Create Action](#create-action)
107
+ - [Delete Action](#delete-action)
108
+ - [Discard Action](#discard-action)
109
+ - [Edit Action](#edit-action)
110
+ - [Publish Action](#publish-action)
111
+ - [ReplaceDraft Action](#replacedraft-action)
112
+ - [Unpublish Action](#unpublish-action)
104
113
  - [License](#license)
105
114
  - [From `v5`](#from-v5)
106
115
  - [The default `useCdn` is changed to `true`](#the-default-usecdn-is-changed-to-true)
@@ -1148,6 +1157,176 @@ client.mutate(transaction)
1148
1157
 
1149
1158
  An important note on this approach is that you cannot call `commit()` on transactions or patches instantiated this way, instead you have to pass them to `client.mutate()`
1150
1159
 
1160
+ ### Server Side Actions
1161
+
1162
+ The Server Side Actions API provides a new interface for creating, updating and publishing documents. It is a wrapper around the [Server Side Actions API](https://www.sanity.io/docs/http-actions).
1163
+
1164
+ This API is only available from API version `v2024-05-23`.
1165
+
1166
+ #### Action options
1167
+
1168
+ The following options are available for actions, and can be applied as the second argument to `action()`.
1169
+
1170
+ - `transactionId`: If set, this ID is as transaction ID for the action instead of using an autogenerated one.
1171
+ - `dryRun` (`true|false`) - default `false`. If true, the mutation will be a dry run - the response will be identical to the one returned had this property been omitted or false (including error responses) but no documents will be affected.
1172
+ - `skipCrossDatasetReferenceValidation` (`true|false`) - default `false`. If true, the mutation will be skipped validation of cross dataset references. This is useful when you are creating a document that references a document in a different dataset, and you want to skip the validation to avoid an error.
1173
+
1174
+ #### Create Action
1175
+
1176
+ A document draft can be created by specifying a create action type:
1177
+
1178
+ ```js
1179
+ client
1180
+ .action(
1181
+ {
1182
+ actionType: 'sanity.action.document.create',
1183
+ publishedId: 'bike-123',
1184
+ attributes: {name: 'Sanity Tandem Extraordinaire', _type: 'bike', seats: 1},
1185
+ ifExists: 'fail',
1186
+ },
1187
+ actionOptions,
1188
+ )
1189
+ .then(() => {
1190
+ console.log('Bike draft created')
1191
+ })
1192
+ .catch((err) => {
1193
+ console.error('Create draft failed: ', err.message)
1194
+ })
1195
+ ```
1196
+
1197
+ #### Delete Action
1198
+
1199
+ A published document can be deleted by specifying a delete action type, optionally including some drafts:
1200
+
1201
+ ```js
1202
+ client
1203
+ .action(
1204
+ {
1205
+ actionType: 'sanity.action.document.delete',
1206
+ publishedId: 'bike-123',
1207
+ includeDrafts: ['draft.bike-123'],
1208
+ },
1209
+ actionOptions,
1210
+ )
1211
+ .then(() => {
1212
+ console.log('Bike deleted')
1213
+ })
1214
+ .catch((err) => {
1215
+ console.error('Delete failed: ', err.message)
1216
+ })
1217
+ ```
1218
+
1219
+ #### Discard Action
1220
+
1221
+ A draft document can be deleted by specifying a discard action type:
1222
+
1223
+ ```js
1224
+ client
1225
+ .action(
1226
+ {
1227
+ actionType: 'sanity.action.document.discard',
1228
+ draftId: 'draft.bike-123',
1229
+ },
1230
+ actionOptions,
1231
+ )
1232
+ .then(() => {
1233
+ console.log('Bike draft deleted')
1234
+ })
1235
+ .catch((err) => {
1236
+ console.error('Discard failed: ', err.message)
1237
+ })
1238
+ ```
1239
+
1240
+ #### Edit Action
1241
+
1242
+ A patch can be applied to an existing document draft or create a new one by specifying an edit action type:
1243
+
1244
+ ```js
1245
+ client
1246
+ .action(
1247
+ {
1248
+ actionType: 'sanity.action.document.edit',
1249
+ publishedId: 'bike-123',
1250
+ attributes: {name: 'Sanity Tandem Extraordinaire', _type: 'bike', seats: 2},
1251
+ },
1252
+ actionOptions,
1253
+ )
1254
+ .then(() => {
1255
+ console.log('Bike draft edited')
1256
+ })
1257
+ .catch((err) => {
1258
+ console.error('Edit draft failed: ', err.message)
1259
+ })
1260
+ ```
1261
+
1262
+ #### Publish Action
1263
+
1264
+ A draft document can be published by specifying a publish action type, optionally with revision ID checks:
1265
+
1266
+ ```js
1267
+ client
1268
+ .action(
1269
+ {
1270
+ actionType: 'sanity.action.document.publish',
1271
+ draftId: 'draft.bike-123',
1272
+ ifDraftRevisionId: '<previously-known-revision>',
1273
+ publishedId: 'bike-123',
1274
+ ifPublishedRevisionId: '<previously-known-revision>',
1275
+ },
1276
+ actionOptions,
1277
+ )
1278
+ .then(() => {
1279
+ console.log('Bike draft published')
1280
+ })
1281
+ .catch((err) => {
1282
+ console.error('Publish draft failed: ', err.message)
1283
+ })
1284
+ ```
1285
+
1286
+ #### ReplaceDraft Action
1287
+
1288
+ An existing document draft can be deleted and replaced by a new one by specifying a replaceDraft action type:
1289
+
1290
+ ```js
1291
+ client
1292
+ .action(
1293
+ {
1294
+ actionType: 'sanity.action.document.replaceDraft',
1295
+ publishedId: 'bike-123',
1296
+ attributes: {name: 'Sanity Tandem Extraordinaire', _type: 'bike', seats: 1},
1297
+ },
1298
+ actionOptions,
1299
+ )
1300
+ .then(() => {
1301
+ console.log('Bike draft replaced')
1302
+ })
1303
+ .catch((err) => {
1304
+ console.error('Replace draft failed: ', err.message)
1305
+ })
1306
+ ```
1307
+
1308
+ #### Unpublish Action
1309
+
1310
+ A published document can be retracted by specifying an unpublish action type:
1311
+
1312
+ ```js
1313
+ client
1314
+ .action(
1315
+ {
1316
+ actionType: 'sanity.action.document.unpublish',
1317
+ draftId: 'draft.bike-123',
1318
+ publishedId: 'bike-123',
1319
+ },
1320
+ actionOptions,
1321
+ )
1322
+ .then(() => {
1323
+ console.log('Bike draft unpublished')
1324
+ })
1325
+ .catch((err) => {
1326
+ console.error('Unpublish draft failed: ', err.message)
1327
+ })
1328
+ ```
1329
+
1151
1330
  ### Uploading assets
1152
1331
 
1153
1332
  Assets can be uploaded using the `client.assets.upload(...)` method.
@@ -598,7 +598,7 @@ export declare type DeleteAction = {
598
598
  /**
599
599
  * Delete document history
600
600
  */
601
- purge: boolean
601
+ purge?: boolean
602
602
  }
603
603
 
604
604
  /**
@@ -623,7 +623,7 @@ export declare type DiscardAction = {
623
623
  /**
624
624
  * Delete document history
625
625
  */
626
- purge: boolean
626
+ purge?: boolean
627
627
  }
628
628
 
629
629
  /**
@@ -1951,7 +1951,7 @@ export declare type PublishAction = {
1951
1951
  /**
1952
1952
  * Draft revision ID to match
1953
1953
  */
1954
- ifDraftRevisionId: string
1954
+ ifDraftRevisionId?: string
1955
1955
  /**
1956
1956
  * Published document ID to replace
1957
1957
  */
@@ -1959,7 +1959,7 @@ export declare type PublishAction = {
1959
1959
  /**
1960
1960
  * Published revision ID to match
1961
1961
  */
1962
- ifPublishedRevisionId: string
1962
+ ifPublishedRevisionId?: string
1963
1963
  }
1964
1964
 
1965
1965
  /** @public */
@@ -2065,10 +2065,6 @@ export declare type ReconnectEvent = {
2065
2065
  */
2066
2066
  export declare type ReplaceDraftAction = {
2067
2067
  actionType: 'sanity.action.document.replaceDraft'
2068
- /**
2069
- * Draft document ID to replace, if it exists.
2070
- */
2071
- draftId: string
2072
2068
  /**
2073
2069
  * Published document ID to create draft from, if draft does not exist
2074
2070
  */
@@ -598,7 +598,7 @@ export declare type DeleteAction = {
598
598
  /**
599
599
  * Delete document history
600
600
  */
601
- purge: boolean
601
+ purge?: boolean
602
602
  }
603
603
 
604
604
  /**
@@ -623,7 +623,7 @@ export declare type DiscardAction = {
623
623
  /**
624
624
  * Delete document history
625
625
  */
626
- purge: boolean
626
+ purge?: boolean
627
627
  }
628
628
 
629
629
  /**
@@ -1951,7 +1951,7 @@ export declare type PublishAction = {
1951
1951
  /**
1952
1952
  * Draft revision ID to match
1953
1953
  */
1954
- ifDraftRevisionId: string
1954
+ ifDraftRevisionId?: string
1955
1955
  /**
1956
1956
  * Published document ID to replace
1957
1957
  */
@@ -1959,7 +1959,7 @@ export declare type PublishAction = {
1959
1959
  /**
1960
1960
  * Published revision ID to match
1961
1961
  */
1962
- ifPublishedRevisionId: string
1962
+ ifPublishedRevisionId?: string
1963
1963
  }
1964
1964
 
1965
1965
  /** @public */
@@ -2065,10 +2065,6 @@ export declare type ReconnectEvent = {
2065
2065
  */
2066
2066
  export declare type ReplaceDraftAction = {
2067
2067
  actionType: 'sanity.action.document.replaceDraft'
2068
- /**
2069
- * Draft document ID to replace, if it exists.
2070
- */
2071
- draftId: string
2072
2068
  /**
2073
2069
  * Published document ID to create draft from, if draft does not exist
2074
2070
  */
package/dist/index.cjs CHANGED
@@ -1534,7 +1534,7 @@ function defineDeprecatedCreateClient(createClient2) {
1534
1534
  return printNoDefaultExport(), createClient2(config);
1535
1535
  };
1536
1536
  }
1537
- var name = "@sanity/client", version = "6.19.0";
1537
+ var name = "@sanity/client", version = "6.19.2";
1538
1538
  const middleware = [
1539
1539
  middleware$1.debug({ verbose: !0, namespace: "sanity:client" }),
1540
1540
  middleware$1.headers({ "User-Agent": `${name} ${version}` }),
package/dist/index.d.cts CHANGED
@@ -598,7 +598,7 @@ export declare type DeleteAction = {
598
598
  /**
599
599
  * Delete document history
600
600
  */
601
- purge: boolean
601
+ purge?: boolean
602
602
  }
603
603
 
604
604
  /**
@@ -623,7 +623,7 @@ export declare type DiscardAction = {
623
623
  /**
624
624
  * Delete document history
625
625
  */
626
- purge: boolean
626
+ purge?: boolean
627
627
  }
628
628
 
629
629
  /**
@@ -1951,7 +1951,7 @@ export declare type PublishAction = {
1951
1951
  /**
1952
1952
  * Draft revision ID to match
1953
1953
  */
1954
- ifDraftRevisionId: string
1954
+ ifDraftRevisionId?: string
1955
1955
  /**
1956
1956
  * Published document ID to replace
1957
1957
  */
@@ -1959,7 +1959,7 @@ export declare type PublishAction = {
1959
1959
  /**
1960
1960
  * Published revision ID to match
1961
1961
  */
1962
- ifPublishedRevisionId: string
1962
+ ifPublishedRevisionId?: string
1963
1963
  }
1964
1964
 
1965
1965
  /** @public */
@@ -2065,10 +2065,6 @@ export declare type ReconnectEvent = {
2065
2065
  */
2066
2066
  export declare type ReplaceDraftAction = {
2067
2067
  actionType: 'sanity.action.document.replaceDraft'
2068
- /**
2069
- * Draft document ID to replace, if it exists.
2070
- */
2071
- draftId: string
2072
2068
  /**
2073
2069
  * Published document ID to create draft from, if draft does not exist
2074
2070
  */
package/dist/index.d.ts CHANGED
@@ -598,7 +598,7 @@ export declare type DeleteAction = {
598
598
  /**
599
599
  * Delete document history
600
600
  */
601
- purge: boolean
601
+ purge?: boolean
602
602
  }
603
603
 
604
604
  /**
@@ -623,7 +623,7 @@ export declare type DiscardAction = {
623
623
  /**
624
624
  * Delete document history
625
625
  */
626
- purge: boolean
626
+ purge?: boolean
627
627
  }
628
628
 
629
629
  /**
@@ -1951,7 +1951,7 @@ export declare type PublishAction = {
1951
1951
  /**
1952
1952
  * Draft revision ID to match
1953
1953
  */
1954
- ifDraftRevisionId: string
1954
+ ifDraftRevisionId?: string
1955
1955
  /**
1956
1956
  * Published document ID to replace
1957
1957
  */
@@ -1959,7 +1959,7 @@ export declare type PublishAction = {
1959
1959
  /**
1960
1960
  * Published revision ID to match
1961
1961
  */
1962
- ifPublishedRevisionId: string
1962
+ ifPublishedRevisionId?: string
1963
1963
  }
1964
1964
 
1965
1965
  /** @public */
@@ -2065,10 +2065,6 @@ export declare type ReconnectEvent = {
2065
2065
  */
2066
2066
  export declare type ReplaceDraftAction = {
2067
2067
  actionType: 'sanity.action.document.replaceDraft'
2068
- /**
2069
- * Draft document ID to replace, if it exists.
2070
- */
2071
- draftId: string
2072
2068
  /**
2073
2069
  * Published document ID to create draft from, if draft does not exist
2074
2070
  */
package/dist/index.js CHANGED
@@ -1517,7 +1517,7 @@ function defineDeprecatedCreateClient(createClient2) {
1517
1517
  return printNoDefaultExport(), createClient2(config);
1518
1518
  };
1519
1519
  }
1520
- var name = "@sanity/client", version = "6.19.0";
1520
+ var name = "@sanity/client", version = "6.19.2";
1521
1521
  const middleware = [
1522
1522
  debug({ verbose: !0, namespace: "sanity:client" }),
1523
1523
  headers({ "User-Agent": `${name} ${version}` }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/client",
3
- "version": "6.19.0",
3
+ "version": "6.19.2",
4
4
  "description": "Client for retrieving, creating and patching data from Sanity.io",
5
5
  "keywords": [
6
6
  "sanity",
@@ -118,7 +118,7 @@
118
118
  },
119
119
  "dependencies": {
120
120
  "@sanity/eventsource": "^5.0.2",
121
- "get-it": "^8.5.0",
121
+ "get-it": "^8.6.0",
122
122
  "rxjs": "^7.0.0"
123
123
  },
124
124
  "devDependencies": {
@@ -126,11 +126,11 @@
126
126
  "@edge-runtime/vm": "^3.2.0",
127
127
  "@rollup/plugin-commonjs": "^25.0.8",
128
128
  "@rollup/plugin-node-resolve": "^15.2.3",
129
- "@sanity/pkg-utils": "^6.8.18",
129
+ "@sanity/pkg-utils": "^6.9.3",
130
130
  "@types/json-diff": "^1.0.3",
131
131
  "@types/node": "^20.8.8",
132
- "@typescript-eslint/eslint-plugin": "^7.10.0",
133
- "@typescript-eslint/parser": "^7.10.0",
132
+ "@typescript-eslint/eslint-plugin": "^7.12.0",
133
+ "@typescript-eslint/parser": "^7.12.0",
134
134
  "@vercel/stega": "0.1.2",
135
135
  "@vitest/coverage-v8": "1.6.0",
136
136
  "eslint": "^8.57.0",
@@ -143,12 +143,12 @@
143
143
  "ls-engines": "^0.9.1",
144
144
  "next": "^14.2.3",
145
145
  "nock": "^13.5.4",
146
- "prettier": "^3.2.5",
146
+ "prettier": "^3.3.1",
147
147
  "prettier-plugin-packagejson": "^2.5.0",
148
148
  "rimraf": "^5.0.1",
149
149
  "rollup": "^4.18.0",
150
150
  "sse-channel": "^4.0.0",
151
- "terser": "^5.31.0",
151
+ "terser": "^5.31.1",
152
152
  "typescript": "5.4.5",
153
153
  "vitest": "1.6.0",
154
154
  "vitest-github-actions-reporter": "0.11.1"
package/src/types.ts CHANGED
@@ -556,11 +556,6 @@ export type CreateAction = {
556
556
  export type ReplaceDraftAction = {
557
557
  actionType: 'sanity.action.document.replaceDraft'
558
558
 
559
- /**
560
- * Draft document ID to replace, if it exists.
561
- */
562
- draftId: string
563
-
564
559
  /**
565
560
  * Published document ID to create draft from, if draft does not exist
566
561
  */
@@ -621,7 +616,7 @@ export type DeleteAction = {
621
616
  /**
622
617
  * Delete document history
623
618
  */
624
- purge: boolean
619
+ purge?: boolean
625
620
  }
626
621
 
627
622
  /**
@@ -641,7 +636,7 @@ export type DiscardAction = {
641
636
  /**
642
637
  * Delete document history
643
638
  */
644
- purge: boolean
639
+ purge?: boolean
645
640
  }
646
641
 
647
642
  /**
@@ -664,7 +659,7 @@ export type PublishAction = {
664
659
  /**
665
660
  * Draft revision ID to match
666
661
  */
667
- ifDraftRevisionId: string
662
+ ifDraftRevisionId?: string
668
663
 
669
664
  /**
670
665
  * Published document ID to replace
@@ -674,7 +669,7 @@ export type PublishAction = {
674
669
  /**
675
670
  * Published revision ID to match
676
671
  */
677
- ifPublishedRevisionId: string
672
+ ifPublishedRevisionId?: string
678
673
  }
679
674
 
680
675
  /**
@@ -166,7 +166,7 @@
166
166
  typeof result[key] > "u" ? result[key] = value : isArray$3(result[key]) ? result[key].push(value) : result[key] = [result[key], value];
167
167
  }
168
168
  return result;
169
- }, parseHeaders$1 = /* @__PURE__ */ getDefaultExportFromCjs$1(parseHeaders), __defProp$5 = Object.defineProperty, __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField$5 = (obj, key, value) => (__defNormalProp$5(obj, typeof key != "symbol" ? key + "" : key, value), value), __accessCheck$8 = (obj, member, msg) => {
169
+ }, parseHeaders$1 = /* @__PURE__ */ getDefaultExportFromCjs$1(parseHeaders), __defProp$4 = Object.defineProperty, __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField$4 = (obj, key, value) => (__defNormalProp$4(obj, typeof key != "symbol" ? key + "" : key, value), value), __accessCheck$8 = (obj, member, msg) => {
170
170
  if (!member.has(obj))
171
171
  throw TypeError("Cannot " + msg);
172
172
  }, __privateGet$8 = (obj, member, getter) => (__accessCheck$8(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)), __privateAdd$8 = (obj, member, value) => {
@@ -176,7 +176,7 @@
176
176
  }, __privateSet$8 = (obj, member, value, setter) => (__accessCheck$8(obj, member, "write to private field"), member.set(obj, value), value), _method, _url, _resHeaders, _headers, _controller, _init, _useAbortSignal;
177
177
  class FetchXhr {
178
178
  constructor() {
179
- __publicField$5(this, "onabort"), __publicField$5(this, "onerror"), __publicField$5(this, "onreadystatechange"), __publicField$5(this, "ontimeout"), __publicField$5(this, "readyState", 0), __publicField$5(this, "response"), __publicField$5(this, "responseText", ""), __publicField$5(this, "responseType", ""), __publicField$5(this, "status"), __publicField$5(this, "statusText"), __publicField$5(this, "withCredentials"), __privateAdd$8(this, _method, void 0), __privateAdd$8(this, _url, void 0), __privateAdd$8(this, _resHeaders, void 0), __privateAdd$8(this, _headers, {}), __privateAdd$8(this, _controller, void 0), __privateAdd$8(this, _init, {}), __privateAdd$8(this, _useAbortSignal, void 0);
179
+ __publicField$4(this, "onabort"), __publicField$4(this, "onerror"), __publicField$4(this, "onreadystatechange"), __publicField$4(this, "ontimeout"), __publicField$4(this, "readyState", 0), __publicField$4(this, "response"), __publicField$4(this, "responseText", ""), __publicField$4(this, "responseType", ""), __publicField$4(this, "status"), __publicField$4(this, "statusText"), __publicField$4(this, "withCredentials"), __privateAdd$8(this, _method, void 0), __privateAdd$8(this, _url, void 0), __privateAdd$8(this, _resHeaders, void 0), __privateAdd$8(this, _headers, {}), __privateAdd$8(this, _controller, void 0), __privateAdd$8(this, _init, {}), __privateAdd$8(this, _useAbortSignal, void 0);
180
180
  }
181
181
  // eslint-disable-next-line @typescript-eslint/no-unused-vars -- _async is only declared for typings compatibility
182
182
  open(method, url, _async) {
@@ -697,10 +697,10 @@
697
697
  }
698
698
  };
699
699
  }
700
- var __defProp$4 = Object.defineProperty, __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField$4 = (obj, key, value) => (__defNormalProp$4(obj, typeof key != "symbol" ? key + "" : key, value), value);
700
+ var __defProp$1$1 = Object.defineProperty, __defNormalProp$1$1 = (obj, key, value) => key in obj ? __defProp$1$1(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, __publicField$1$1 = (obj, key, value) => (__defNormalProp$1$1(obj, typeof key != "symbol" ? key + "" : key, value), value);
701
701
  class Cancel {
702
702
  constructor(message) {
703
- __publicField$4(this, "__CANCEL__", !0), __publicField$4(this, "message"), this.message = message;
703
+ __publicField$1$1(this, "__CANCEL__", !0), __publicField$1$1(this, "message"), this.message = message;
704
704
  }
705
705
  toString() {
706
706
  return `Cancel${this.message ? `: ${this.message}` : ""}`;
@@ -708,7 +708,7 @@
708
708
  }
709
709
  const _CancelToken = class {
710
710
  constructor(executor) {
711
- if (__publicField$4(this, "promise"), __publicField$4(this, "reason"), typeof executor != "function")
711
+ if (__publicField$1$1(this, "promise"), __publicField$1$1(this, "reason"), typeof executor != "function")
712
712
  throw new TypeError("executor must be a function.");
713
713
  let resolvePromise = null;
714
714
  this.promise = new Promise((resolve) => {
@@ -718,7 +718,7 @@
718
718
  });
719
719
  }
720
720
  };
721
- __publicField$4(_CancelToken, "source", () => {
721
+ __publicField$1$1(_CancelToken, "source", () => {
722
722
  let cancel;
723
723
  return {
724
724
  token: new _CancelToken((can) => {