@sanity/client 4.0.0-alpha.esm.6 → 4.0.1-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/LICENSE +1 -1
- package/README.md +23 -16
- package/dist/sanityClient.browser.mjs +2806 -0
- package/dist/sanityClient.browser.mjs.map +7 -0
- package/index.js +7 -0
- package/lib/assets/assetsClient.js +102 -142
- package/lib/auth/authClient.js +20 -35
- package/lib/config.js +21 -43
- package/lib/data/dataMethods.js +42 -67
- package/lib/data/encodeQueryString.js +9 -15
- package/lib/data/listen.js +27 -56
- package/lib/data/patch.js +114 -167
- package/lib/data/transaction.js +95 -139
- package/lib/datasets/datasetsClient.js +31 -56
- package/lib/generateHelpUrl.js +11 -0
- package/lib/http/browserMiddleware.js +4 -3
- package/lib/http/errors.js +9 -15
- package/lib/http/nodeMiddleware.js +6 -10
- package/lib/http/queryString.js +4 -7
- package/lib/http/request.js +14 -28
- package/lib/http/requestOptions.js +7 -10
- package/lib/projects/projectsClient.js +19 -34
- package/lib/sanityClient.js +100 -157
- package/lib/users/usersClient.js +14 -27
- package/lib/util/defaults.js +6 -8
- package/lib/util/getSelection.js +3 -5
- package/lib/util/once.js +4 -6
- package/lib/util/pick.js +4 -6
- package/lib/validators.js +0 -26
- package/lib/warnings.js +9 -13
- package/package.json +51 -40
- package/sanityClient.d.ts +262 -105
- package/umd/sanityClient.js +5474 -146
- package/umd/sanityClient.min.js +14 -1
- package/dist/browser/sanityClient.js +0 -4165
- package/dist/node/sanityClient.js +0 -969
- package/lib/util/observable.js +0 -29
- package/src/assets/assetsClient.js +0 -132
- package/src/auth/authClient.js +0 -13
- package/src/config.js +0 -93
- package/src/data/dataMethods.js +0 -182
- package/src/data/encodeQueryString.js +0 -18
- package/src/data/listen.js +0 -159
- package/src/data/patch.js +0 -119
- package/src/data/transaction.js +0 -103
- package/src/datasets/datasetsClient.js +0 -28
- package/src/http/browserMiddleware.js +0 -1
- package/src/http/errors.js +0 -53
- package/src/http/nodeMiddleware.js +0 -11
- package/src/http/queryString.js +0 -10
- package/src/http/request.js +0 -50
- package/src/http/requestOptions.js +0 -29
- package/src/projects/projectsClient.js +0 -13
- package/src/sanityClient.js +0 -124
- package/src/users/usersClient.js +0 -9
- package/src/util/defaults.js +0 -9
- package/src/util/getSelection.js +0 -17
- package/src/util/observable.js +0 -6
- package/src/util/once.js +0 -12
- package/src/util/pick.js +0 -9
- package/src/validators.js +0 -76
- package/src/warnings.js +0 -25
- package/test/client.test.js +0 -2561
- package/test/encodeQueryString.test.js +0 -38
- package/test/fixtures/horsehead-nebula.jpg +0 -0
- package/test/fixtures/pdf-sample.pdf +0 -0
- package/test/helpers/sseServer.js +0 -27
- package/test/listen.test.js +0 -207
- package/test/warnings.test.disabled.js +0 -84
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@sanity/client)
|
|
4
4
|
|
|
5
|
-
Javascript client for Sanity. Works in node.js and modern browsers (older browsers
|
|
5
|
+
Javascript client for Sanity. Works in node.js and modern browsers (older browsers need a [Promise polyfill](https://www.sanity.io/help/js-client-promise-polyfill)).
|
|
6
6
|
|
|
7
7
|
## Requirements
|
|
8
8
|
|
|
@@ -19,17 +19,19 @@ npm install -g @sanity/client
|
|
|
19
19
|
## API
|
|
20
20
|
|
|
21
21
|
```js
|
|
22
|
-
|
|
23
|
-
const client =
|
|
22
|
+
const sanityClient = require('@sanity/client')
|
|
23
|
+
const client = sanityClient({
|
|
24
24
|
projectId: 'your-project-id',
|
|
25
25
|
dataset: 'bikeshop',
|
|
26
26
|
apiVersion: '2021-03-25', // use current UTC date - see "specifying API version"!
|
|
27
27
|
token: 'sanity-auth-token', // or leave blank for unauthenticated usage
|
|
28
28
|
useCdn: true, // `false` if you want to ensure fresh data
|
|
29
29
|
})
|
|
30
|
+
|
|
31
|
+
export default client
|
|
30
32
|
```
|
|
31
33
|
|
|
32
|
-
`const client =
|
|
34
|
+
`const client = sanityClient(options)`
|
|
33
35
|
|
|
34
36
|
Initializes a new Sanity Client. Required options are `projectId`, `dataset`, and `apiVersion`. Setting a value for `useCdn` is encouraged.
|
|
35
37
|
|
|
@@ -37,7 +39,7 @@ Initializes a new Sanity Client. Required options are `projectId`, `dataset`, an
|
|
|
37
39
|
|
|
38
40
|
Sanity uses ISO dates (YYYY-MM-DD) in UTC timezone for versioning. The explanation for this can be found [in the documentation](http://sanity.io/docs/api-versioning)
|
|
39
41
|
|
|
40
|
-
In general, unless you know what API version you want to use, you'll want to set it to today's UTC date. By doing this, you'll get all the latest bugfixes and features, while locking the API to prevent breaking changes.
|
|
42
|
+
In general, unless you know what API version you want to use, you'll want to statically set it to today's UTC date when starting a new project. By doing this, you'll get all the latest bugfixes and features, while locking the API to prevent breaking changes.
|
|
41
43
|
|
|
42
44
|
**Note**: Do not be tempted to use a dynamic value for the `apiVersion`. The reason for setting a static value is to prevent unexpected, breaking changes.
|
|
43
45
|
|
|
@@ -260,13 +262,11 @@ client
|
|
|
260
262
|
The operations of appending and prepending to an array are so common that they have been given their own methods for better readability:
|
|
261
263
|
|
|
262
264
|
```js
|
|
263
|
-
import {nanoid} from 'nanoid'
|
|
264
|
-
|
|
265
265
|
client
|
|
266
266
|
.patch('bike-123')
|
|
267
267
|
.setIfMissing({reviews: []})
|
|
268
|
-
.append('reviews', [{
|
|
269
|
-
.commit()
|
|
268
|
+
.append('reviews', [{title: 'Great bike!', stars: 5}])
|
|
269
|
+
.commit({autoGenerateArrayKeys: true})
|
|
270
270
|
```
|
|
271
271
|
|
|
272
272
|
### Deleting an element from an array
|
|
@@ -372,27 +372,27 @@ A `patch` can be performed inline on a `transaction`.
|
|
|
372
372
|
Transactions and patches can also be built outside the scope of a client:
|
|
373
373
|
|
|
374
374
|
```js
|
|
375
|
-
|
|
376
|
-
const client =
|
|
375
|
+
const sanityClient = require('@sanity/client')
|
|
376
|
+
const client = sanityClient({
|
|
377
377
|
projectId: 'your-project-id',
|
|
378
378
|
dataset: 'bikeshop',
|
|
379
379
|
})
|
|
380
380
|
|
|
381
381
|
// Patches:
|
|
382
|
-
const patch = new
|
|
382
|
+
const patch = new sanityClient.Patch('<documentId>')
|
|
383
383
|
client.mutate(patch.inc({count: 1}).unset(['visits']))
|
|
384
384
|
|
|
385
385
|
// Transactions:
|
|
386
|
-
const transaction = new
|
|
386
|
+
const transaction = new sanityClient.Transaction()
|
|
387
387
|
.create({_id: '123', name: 'FooBike'})
|
|
388
388
|
.delete('someDocId')
|
|
389
389
|
|
|
390
390
|
client.mutate(transaction)
|
|
391
391
|
```
|
|
392
392
|
|
|
393
|
-
`const patch = new
|
|
393
|
+
`const patch = new sanityClient.Patch(docId)`
|
|
394
394
|
|
|
395
|
-
`const transaction = new
|
|
395
|
+
`const transaction = new sanityClient.Transaction()`
|
|
396
396
|
|
|
397
397
|
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()`
|
|
398
398
|
|
|
@@ -404,7 +404,7 @@ Assets can be uploaded using the `client.assets.upload(...)` method.
|
|
|
404
404
|
client.assets.upload(type: 'file' | image', body: File | Blob | Buffer | NodeStream, options = {}): Promise<AssetDocument>
|
|
405
405
|
```
|
|
406
406
|
|
|
407
|
-
👉 Read more about [assets in Sanity](https://sanity.io/docs/
|
|
407
|
+
👉 Read more about [assets in Sanity](https://sanity.io/docs/assets)
|
|
408
408
|
|
|
409
409
|
#### Examples: Uploading assets from Node.js
|
|
410
410
|
|
|
@@ -531,6 +531,13 @@ client.config({dataset: 'newDataset'})
|
|
|
531
531
|
|
|
532
532
|
Set client configuration. Required options are `projectId` and `dataset`.
|
|
533
533
|
|
|
534
|
+
## Release new version
|
|
535
|
+
|
|
536
|
+
Run ["CI & Release" workflow](https://github.com/sanity-io/client/actions/workflows/ci.yml).
|
|
537
|
+
Make sure to select the main branch and check "Release new version".
|
|
538
|
+
|
|
539
|
+
Semantic release will only release on configured branches, so it is safe to run release on any branch.
|
|
540
|
+
|
|
534
541
|
## License
|
|
535
542
|
|
|
536
543
|
MIT © [Sanity.io](https://www.sanity.io/)
|