@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.
Files changed (69) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +23 -16
  3. package/dist/sanityClient.browser.mjs +2806 -0
  4. package/dist/sanityClient.browser.mjs.map +7 -0
  5. package/index.js +7 -0
  6. package/lib/assets/assetsClient.js +102 -142
  7. package/lib/auth/authClient.js +20 -35
  8. package/lib/config.js +21 -43
  9. package/lib/data/dataMethods.js +42 -67
  10. package/lib/data/encodeQueryString.js +9 -15
  11. package/lib/data/listen.js +27 -56
  12. package/lib/data/patch.js +114 -167
  13. package/lib/data/transaction.js +95 -139
  14. package/lib/datasets/datasetsClient.js +31 -56
  15. package/lib/generateHelpUrl.js +11 -0
  16. package/lib/http/browserMiddleware.js +4 -3
  17. package/lib/http/errors.js +9 -15
  18. package/lib/http/nodeMiddleware.js +6 -10
  19. package/lib/http/queryString.js +4 -7
  20. package/lib/http/request.js +14 -28
  21. package/lib/http/requestOptions.js +7 -10
  22. package/lib/projects/projectsClient.js +19 -34
  23. package/lib/sanityClient.js +100 -157
  24. package/lib/users/usersClient.js +14 -27
  25. package/lib/util/defaults.js +6 -8
  26. package/lib/util/getSelection.js +3 -5
  27. package/lib/util/once.js +4 -6
  28. package/lib/util/pick.js +4 -6
  29. package/lib/validators.js +0 -26
  30. package/lib/warnings.js +9 -13
  31. package/package.json +51 -40
  32. package/sanityClient.d.ts +262 -105
  33. package/umd/sanityClient.js +5474 -146
  34. package/umd/sanityClient.min.js +14 -1
  35. package/dist/browser/sanityClient.js +0 -4165
  36. package/dist/node/sanityClient.js +0 -969
  37. package/lib/util/observable.js +0 -29
  38. package/src/assets/assetsClient.js +0 -132
  39. package/src/auth/authClient.js +0 -13
  40. package/src/config.js +0 -93
  41. package/src/data/dataMethods.js +0 -182
  42. package/src/data/encodeQueryString.js +0 -18
  43. package/src/data/listen.js +0 -159
  44. package/src/data/patch.js +0 -119
  45. package/src/data/transaction.js +0 -103
  46. package/src/datasets/datasetsClient.js +0 -28
  47. package/src/http/browserMiddleware.js +0 -1
  48. package/src/http/errors.js +0 -53
  49. package/src/http/nodeMiddleware.js +0 -11
  50. package/src/http/queryString.js +0 -10
  51. package/src/http/request.js +0 -50
  52. package/src/http/requestOptions.js +0 -29
  53. package/src/projects/projectsClient.js +0 -13
  54. package/src/sanityClient.js +0 -124
  55. package/src/users/usersClient.js +0 -9
  56. package/src/util/defaults.js +0 -9
  57. package/src/util/getSelection.js +0 -17
  58. package/src/util/observable.js +0 -6
  59. package/src/util/once.js +0 -12
  60. package/src/util/pick.js +0 -9
  61. package/src/validators.js +0 -76
  62. package/src/warnings.js +0 -25
  63. package/test/client.test.js +0 -2561
  64. package/test/encodeQueryString.test.js +0 -38
  65. package/test/fixtures/horsehead-nebula.jpg +0 -0
  66. package/test/fixtures/pdf-sample.pdf +0 -0
  67. package/test/helpers/sseServer.js +0 -27
  68. package/test/listen.test.js +0 -207
  69. package/test/warnings.test.disabled.js +0 -84
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2016 - 2022 Sanity.io
3
+ Copyright (c) 2023 Sanity.io
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/@sanity/client.svg?style=flat-square)](https://www.npmjs.com/package/@sanity/client)
4
4
 
5
- Javascript client for Sanity. Works in node.js and modern browsers (older browsers needs a [Promise polyfill](https://www.sanity.io/help/js-client-promise-polyfill)).
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
- import {createClient} from '@sanity/client'
23
- const client = createClient({
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 = createClient(options)`
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', [{_key: nanoid(), title: 'Great bike!', stars: 5}])
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
- import {SanityClient} from '@sanity/client'
376
- const client = new SanityClient({
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 SanityClient.Patch('<documentId>')
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 SanityClient.Transaction()
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 SanityClient.Patch(docId)`
393
+ `const patch = new sanityClient.Patch(docId)`
394
394
 
395
- `const transaction = new SanityClient.Transaction()`
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/http-api/assets)
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/)