@sanity/client 2.24.3-pte.128 → 3.0.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2016 - 2021 Sanity.io
3
+ Copyright (c) 2016 - 2022 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
@@ -298,7 +298,7 @@ One or more documents can be deleted by specifying a GROQ query (and optionally,
298
298
  // Without params
299
299
 
300
300
  client
301
- .delete({ query: '*[_type == "bike"][0]' })
301
+ .delete({query: '*[_type == "bike"][0]'})
302
302
  .then(() => {
303
303
  console.log('The document matching *[_type == "bike"][0] was deleted')
304
304
  })
@@ -311,7 +311,7 @@ client
311
311
  // With params
312
312
 
313
313
  client
314
- .delete({ query: '*[_type == $type][0..1]', params: { type: 'bike' } })
314
+ .delete({query: '*[_type == $type][0..1]', params: {type: 'bike'}})
315
315
  .then(() => {
316
316
  console.log('The documents matching *[_type == "bike"][0..1] was deleted')
317
317
  })
@@ -513,3 +513,7 @@ client.config({dataset: 'newDataset'})
513
513
  `client.config(options)`
514
514
 
515
515
  Set client configuration. Required options are `projectId` and `dataset`.
516
+
517
+ ## License
518
+
519
+ MIT © [Sanity.io](https://www.sanity.io/)
@@ -14,11 +14,9 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
14
14
 
15
15
  var assign = require('object-assign');
16
16
 
17
- var _require = require('@sanity/observable/operators/map'),
18
- map = _require.map;
19
-
20
- var _require2 = require('@sanity/observable/operators/filter'),
21
- filter = _require2.filter;
17
+ var _require = require('../util/observable'),
18
+ map = _require.map,
19
+ filter = _require.filter;
22
20
 
23
21
  var queryString = require('../http/queryString');
24
22
 
@@ -28,20 +26,6 @@ function AssetsClient(client) {
28
26
  this.client = client;
29
27
  }
30
28
 
31
- function toDocument(body) {
32
- // todo: rewrite to just return body.document in a while
33
- var document = body.document;
34
- Object.defineProperty(document, 'document', {
35
- enumerable: false,
36
- get: function get() {
37
- // eslint-disable-next-line no-console
38
- console.warn('The promise returned from client.asset.upload(...) now resolves with the asset document');
39
- return document;
40
- }
41
- });
42
- return document;
43
- }
44
-
45
29
  function optionsFromFile(opts, file) {
46
30
  if (typeof window === 'undefined' || !(file instanceof window.File)) {
47
31
  return opts;
@@ -129,7 +113,7 @@ assign(AssetsClient.prototype, {
129
113
  return this.client.isPromiseAPI() ? observable.pipe(filter(function (event) {
130
114
  return event.type === 'response';
131
115
  }), map(function (event) {
132
- return toDocument(event.body);
116
+ return event.body.document;
133
117
  })).toPromise() : observable;
134
118
  },
135
119
  delete: function _delete(type, id) {
package/lib/config.js CHANGED
@@ -13,7 +13,6 @@ var defaultConfig = {
13
13
  apiHost: 'https://api.sanity.io',
14
14
  apiVersion: '1',
15
15
  useProjectHostname: true,
16
- gradientMode: false,
17
16
  isPromiseAPI: true
18
17
  };
19
18
  var LOCALHOSTS = ['localhost', '127.0.0.1', '0.0.0.0'];
@@ -32,18 +31,13 @@ exports.initConfig = function (config, prevConfig) {
32
31
  }
33
32
 
34
33
  var newConfig = assign({}, defaultConfig, specifiedConfig);
35
- var gradientMode = newConfig.gradientMode;
36
- var projectBased = !gradientMode && newConfig.useProjectHostname;
34
+ var projectBased = newConfig.useProjectHostname;
37
35
 
38
36
  if (typeof Promise === 'undefined') {
39
37
  var helpUrl = generateHelpUrl('js-client-promise-polyfill');
40
38
  throw new Error("No native Promise-implementation found, polyfill needed - see ".concat(helpUrl));
41
39
  }
42
40
 
43
- if (gradientMode && !newConfig.namespace) {
44
- throw new Error('Configuration must contain `namespace` when running in gradient mode');
45
- }
46
-
47
41
  if (projectBased && !newConfig.projectId) {
48
42
  throw new Error('Configuration must contain `projectId`');
49
43
  }
@@ -53,8 +47,6 @@ exports.initConfig = function (config, prevConfig) {
53
47
 
54
48
  if (isBrowser && isLocalhost && newConfig.token && newConfig.ignoreBrowserTokenWarning !== true) {
55
49
  warnings.printBrowserTokenWarning();
56
- } else if ((!isBrowser || isLocalhost) && newConfig.useCdn && newConfig.token) {
57
- warnings.printCdnTokenWarning();
58
50
  } else if (typeof newConfig.useCdn === 'undefined') {
59
51
  warnings.printCdnWarning();
60
52
  }
@@ -63,8 +55,8 @@ exports.initConfig = function (config, prevConfig) {
63
55
  validate.projectId(newConfig.projectId);
64
56
  }
65
57
 
66
- if (!gradientMode && newConfig.dataset) {
67
- validate.dataset(newConfig.dataset, newConfig.gradientMode);
58
+ if (newConfig.dataset) {
59
+ validate.dataset(newConfig.dataset);
68
60
  }
69
61
 
70
62
  if ('requestTagPrefix' in newConfig) {
@@ -74,25 +66,19 @@ exports.initConfig = function (config, prevConfig) {
74
66
 
75
67
  newConfig.apiVersion = "".concat(newConfig.apiVersion).replace(/^v/, '');
76
68
  newConfig.isDefaultApi = newConfig.apiHost === defaultConfig.apiHost;
77
- newConfig.useCdn = Boolean(newConfig.useCdn) && !newConfig.token && !newConfig.withCredentials;
69
+ newConfig.useCdn = Boolean(newConfig.useCdn) && !newConfig.withCredentials;
78
70
  exports.validateApiVersion(newConfig.apiVersion);
79
-
80
- if (newConfig.gradientMode) {
81
- newConfig.url = newConfig.apiHost;
82
- newConfig.cdnUrl = newConfig.apiHost;
71
+ var hostParts = newConfig.apiHost.split('://', 2);
72
+ var protocol = hostParts[0];
73
+ var host = hostParts[1];
74
+ var cdnHost = newConfig.isDefaultApi ? defaultCdnHost : host;
75
+
76
+ if (newConfig.useProjectHostname) {
77
+ newConfig.url = "".concat(protocol, "://").concat(newConfig.projectId, ".").concat(host, "/v").concat(newConfig.apiVersion);
78
+ newConfig.cdnUrl = "".concat(protocol, "://").concat(newConfig.projectId, ".").concat(cdnHost, "/v").concat(newConfig.apiVersion);
83
79
  } else {
84
- var hostParts = newConfig.apiHost.split('://', 2);
85
- var protocol = hostParts[0];
86
- var host = hostParts[1];
87
- var cdnHost = newConfig.isDefaultApi ? defaultCdnHost : host;
88
-
89
- if (newConfig.useProjectHostname) {
90
- newConfig.url = "".concat(protocol, "://").concat(newConfig.projectId, ".").concat(host, "/v").concat(newConfig.apiVersion);
91
- newConfig.cdnUrl = "".concat(protocol, "://").concat(newConfig.projectId, ".").concat(cdnHost, "/v").concat(newConfig.apiVersion);
92
- } else {
93
- newConfig.url = "".concat(newConfig.apiHost, "/v").concat(newConfig.apiVersion);
94
- newConfig.cdnUrl = newConfig.url;
95
- }
80
+ newConfig.url = "".concat(newConfig.apiHost, "/v").concat(newConfig.apiVersion);
81
+ newConfig.cdnUrl = newConfig.url;
96
82
  }
97
83
 
98
84
  return newConfig;
@@ -4,12 +4,10 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
4
4
 
5
5
  var assign = require('object-assign');
6
6
 
7
- var _require = require('@sanity/observable/operators/filter'),
7
+ var _require = require('../util/observable'),
8
+ map = _require.map,
8
9
  filter = _require.filter;
9
10
 
10
- var _require2 = require('@sanity/observable/operators/map'),
11
- map = _require2.map;
12
-
13
11
  var validators = require('../validators');
14
12
 
15
13
  var getSelection = require('../util/getSelection');
@@ -60,10 +58,10 @@ module.exports = {
60
58
  listen: listen,
61
59
  getDataUrl: function getDataUrl(operation, path) {
62
60
  var config = this.clientConfig;
63
- var catalog = config.gradientMode ? config.namespace : validators.hasDataset(config);
61
+ var catalog = validators.hasDataset(config);
64
62
  var baseUri = "/".concat(operation, "/").concat(catalog);
65
63
  var uri = path ? "".concat(baseUri, "/").concat(path) : baseUri;
66
- return (this.clientConfig.gradientMode ? uri : "/data".concat(uri)).replace(/\/($|\?)/, '$1');
64
+ return "/data".concat(uri).replace(/\/($|\?)/, '$1');
67
65
  },
68
66
  fetch: function fetch(query, params) {
69
67
  var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
@@ -8,7 +8,8 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
8
8
 
9
9
  var assign = require('object-assign');
10
10
 
11
- var Observable = require('@sanity/observable/minimal');
11
+ var _require = require('../util/observable'),
12
+ Observable = _require.Observable;
12
13
 
13
14
  var polyfilledEventSource = require('@sanity/eventsource');
14
15
 
package/lib/data/patch.js CHANGED
@@ -2,8 +2,6 @@
2
2
 
3
3
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
4
 
5
- var deepAssign = require('deep-assign');
6
-
7
5
  var assign = require('object-assign');
8
6
 
9
7
  var getSelection = require('../util/getSelection');
@@ -25,14 +23,6 @@ assign(Patch.prototype, {
25
23
  clone: function clone() {
26
24
  return new Patch(this.selection, assign({}, this.operations), this.client);
27
25
  },
28
- merge: function merge(props) {
29
- validateObject('merge', props);
30
- var stack = new Error().stack.toString().split('\n').filter(function (str) {
31
- return str.trim();
32
- }).slice(2);
33
- console.warn("The \"merge\" patch has been deprecated and will be removed in the future\n".concat(stack.join('\n')));
34
- return this._assign('merge', deepAssign(this.operations.merge || {}, props));
35
- },
36
26
  set: function set(props) {
37
27
  return this._assign('set', props);
38
28
  },
@@ -13,11 +13,12 @@ var jsonResponse = require('get-it/lib/middleware/jsonResponse');
13
13
 
14
14
  var progress = require('get-it/lib/middleware/progress');
15
15
 
16
- var Observable = require('@sanity/observable/minimal');
16
+ var _require = require('../util/observable'),
17
+ Observable = _require.Observable;
17
18
 
18
- var _require = require('./errors'),
19
- ClientError = _require.ClientError,
20
- ServerError = _require.ServerError;
19
+ var _require2 = require('./errors'),
20
+ ClientError = _require2.ClientError,
21
+ ServerError = _require2.ServerError;
21
22
 
22
23
  var httpError = {
23
24
  onResponse: function onResponse(res) {
@@ -8,12 +8,11 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
8
8
 
9
9
  var assign = require('object-assign');
10
10
 
11
- var _require = require('@sanity/observable/operators/filter'),
11
+ var _require = require('./util/observable'),
12
+ Observable = _require.Observable,
13
+ map = _require.map,
12
14
  filter = _require.filter;
13
15
 
14
- var _require2 = require('@sanity/observable/operators/map'),
15
- map = _require2.map;
16
-
17
16
  var Patch = require('./data/patch');
18
17
 
19
18
  var Transaction = require('./data/transaction');
@@ -34,9 +33,9 @@ var httpRequest = require('./http/request');
34
33
 
35
34
  var getRequestOptions = require('./http/requestOptions');
36
35
 
37
- var _require3 = require('./config'),
38
- defaultConfig = _require3.defaultConfig,
39
- initConfig = _require3.initConfig;
36
+ var _require2 = require('./config'),
37
+ defaultConfig = _require2.defaultConfig,
38
+ initConfig = _require2.initConfig;
40
39
 
41
40
  var validate = require('./validators');
42
41
 
@@ -98,6 +97,8 @@ assign(SanityClient.prototype, {
98
97
  return this.clientConfig.isPromiseAPI;
99
98
  },
100
99
  _requestObservable: function _requestObservable(options) {
100
+ var _this = this;
101
+
101
102
  var uri = options.url || options.uri; // If the `canUseCdn`-option is not set we detect it automatically based on the method + URL.
102
103
  // Only the /data endpoint is currently available through API-CDN.
103
104
 
@@ -114,7 +115,9 @@ assign(SanityClient.prototype, {
114
115
  var reqOptions = getRequestOptions(this.clientConfig, assign({}, options, {
115
116
  url: this.getUrl(uri, useCdn)
116
117
  }));
117
- return httpRequest(reqOptions, this.clientConfig.requester);
118
+ return new Observable(function (subscriber) {
119
+ return httpRequest(reqOptions, _this.clientConfig.requester).subscribe(subscriber);
120
+ });
118
121
  },
119
122
  request: function request(options) {
120
123
  var observable = this._requestObservable(options).pipe(filter(function (event) {
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ // Since `@sanity/client` doesn't offer ESM exports (yet) const {filter} = require('rxjs/operators') will cause the the whole of rxjs to be included in the bundle.
4
+ // The internal import paths here is a stop-gap measure and will become less of a problem when @sanity/client export tree-shakeable esm bundles
5
+ var _require = require('rxjs/internal/Observable'),
6
+ Observable = _require.Observable;
7
+
8
+ var _require2 = require('rxjs/internal/operators/filter'),
9
+ filter = _require2.filter;
10
+
11
+ var _require3 = require('rxjs/internal/operators/map'),
12
+ map = _require3.map;
13
+
14
+ module.exports = {
15
+ Observable: Observable,
16
+ filter: filter,
17
+ map: map
18
+ };
package/lib/validators.js CHANGED
@@ -63,7 +63,7 @@ exports.validateInsert = function (at, selector, items) {
63
63
  };
64
64
 
65
65
  exports.hasDataset = function (config) {
66
- if (!config.gradientMode && !config.dataset) {
66
+ if (!config.dataset) {
67
67
  throw new Error('`dataset` must be provided to perform queries');
68
68
  }
69
69
 
package/lib/warnings.js CHANGED
@@ -20,5 +20,4 @@ var createWarningPrinter = function createWarningPrinter(message) {
20
20
 
21
21
  exports.printCdnWarning = createWarningPrinter(['You are not using the Sanity CDN. That means your data is always fresh, but the CDN is faster and', "cheaper. Think about it! For more info, see ".concat(generateHelpUrl('js-client-cdn-configuration'), "."), 'To hide this warning, please set the `useCdn` option to either `true` or `false` when creating', 'the client.']);
22
22
  exports.printBrowserTokenWarning = createWarningPrinter(['You have configured Sanity client to use a token in the browser. This may cause unintentional security issues.', "See ".concat(generateHelpUrl('js-client-browser-token'), " for more information and how to hide this warning.")]);
23
- exports.printCdnTokenWarning = createWarningPrinter(['You have set `useCdn` to `true` while also specifying a token. This is usually not what you', 'want. The CDN cannot be used with an authorization token, since private data cannot be cached.', "See ".concat(generateHelpUrl('js-client-usecdn-token'), " for more information.")]);
24
23
  exports.printNoApiVersionSpecifiedWarning = createWarningPrinter(['Using the Sanity client without specifying an API version is deprecated.', "See ".concat(generateHelpUrl('js-client-api-version'))]);
package/package.json CHANGED
@@ -1,61 +1,60 @@
1
1
  {
2
2
  "name": "@sanity/client",
3
- "version": "2.24.3-pte.128+5c3cdaaa08",
4
- "description": "Client for retrieving data from Sanity",
3
+ "version": "3.0.2",
4
+ "description": "Client for retrieving, creating and patching data from Sanity.io",
5
5
  "main": "lib/sanityClient.js",
6
6
  "umd": "umd/sanityClient.min.js",
7
7
  "unpkg": "umd/sanityClient.min.js",
8
8
  "types": "./sanityClient.d.ts",
9
9
  "scripts": {
10
- "analyze": "NODE_ENV=production BROWSERIFY_ENV=build DEBUG='' browserify --full-paths -t envify -g uglifyify lib/sanityClient.js --standalone=SanityClient | discify --open",
11
10
  "browserify": "NODE_ENV=production BROWSERIFY_ENV=build DEBUG='' browserify -t envify -g uglifyify lib/sanityClient.js -o umd/sanityClient.js --standalone=SanityClient",
12
- "build": "babel src --copy-files --out-dir lib && npm run browserify && npm run minify && npm run size",
13
- "size": "node -r @babel/register src/scripts/print-bundle-size",
11
+ "compile": "babel -d lib src",
12
+ "build": "npm run compile && npm run browserify && npm run minify",
13
+ "lint": "eslint .",
14
14
  "clean": "rimraf lib coverage .nyc_output umd/*.js",
15
15
  "coverage": "DEBUG=sanity NODE_ENV=test nyc --reporter=html --reporter=lcov --reporter=text npm test",
16
16
  "minify": "terser -c -m -- umd/sanityClient.js > umd/sanityClient.min.js",
17
17
  "prepublishOnly": "npm run build",
18
- "test": "tape -r @babel/register test/*.test.js"
18
+ "test": "NODE_ENV=test tape test/*.test.js",
19
+ "posttest": "npm run lint"
19
20
  },
20
21
  "browser": {
21
22
  "./src/http/nodeMiddleware.js": "./src/http/browserMiddleware.js",
22
23
  "./lib/http/nodeMiddleware.js": "./lib/http/browserMiddleware.js"
23
24
  },
25
+ "engines": {
26
+ "node": ">=12"
27
+ },
24
28
  "dependencies": {
25
- "@sanity/eventsource": "2.24.3-pte.128+5c3cdaaa08",
26
- "@sanity/generate-help-url": "2.24.3-pte.128+5c3cdaaa08",
27
- "@sanity/observable": "2.0.9",
28
- "deep-assign": "^2.0.0",
29
+ "@sanity/eventsource": "^2.23.0",
30
+ "@sanity/generate-help-url": "^2.18.0",
29
31
  "get-it": "^5.2.1",
30
32
  "make-error": "^1.3.0",
31
- "object-assign": "^4.1.1"
33
+ "object-assign": "^4.1.1",
34
+ "rxjs": "^6.0.0"
32
35
  },
33
36
  "devDependencies": {
34
37
  "@babel/cli": "^7.11.6",
35
38
  "@babel/core": "^7.11.6",
36
39
  "@babel/preset-env": "^7.11.5",
37
- "boxen": "^4.1.0",
38
- "browserify": "^14.3.0",
39
- "chalk": "^2.4.2",
40
- "disc": "^1.3.2",
40
+ "browserify": "^17.0.0",
41
41
  "envify": "^4.0.0",
42
- "gzip-size": "^3.0.0",
43
- "hard-rejection": "^2.1.0",
44
- "nock": "^9.0.5",
45
- "nyc": "^11.0.3",
46
- "pretty-bytes": "^4.0.2",
47
- "rimraf": "^2.7.1",
48
- "rxjs": "^6.5.3",
49
- "sse-channel": "^2.0.6",
50
- "tape": "^4.8.0",
42
+ "eslint": "^8.7.0",
43
+ "eslint-config-prettier": "^8.3.0",
44
+ "eslint-config-sanity": "^5.1.0",
45
+ "nock": "^13.2.2",
46
+ "nyc": "^15.1.0",
47
+ "prettier": "^2.5.1",
48
+ "rimraf": "^3.0.2",
49
+ "sse-channel": "^4.0.0",
50
+ "tape": "^5.4.1",
51
51
  "terser": "^5.7.2",
52
52
  "uglifyify": "^5.0.1",
53
53
  "xtend": "4.0.2"
54
54
  },
55
55
  "repository": {
56
56
  "type": "git",
57
- "url": "git+https://github.com/sanity-io/sanity.git",
58
- "directory": "packages/@sanity/client"
57
+ "url": "git+https://github.com/sanity-io/client.git"
59
58
  },
60
59
  "keywords": [
61
60
  "sanity",
@@ -65,23 +64,24 @@
65
64
  "content",
66
65
  "client",
67
66
  "fetch",
68
- "api",
69
- "gradient"
67
+ "api"
70
68
  ],
71
69
  "author": "Sanity.io <hello@sanity.io>",
72
70
  "license": "MIT",
73
71
  "bugs": {
74
- "url": "https://github.com/sanity-io/sanity/issues"
72
+ "url": "https://github.com/sanity-io/client/issues"
75
73
  },
76
74
  "homepage": "https://www.sanity.io/",
77
75
  "nyc": {
78
76
  "include": [
79
77
  "src/**/*.js"
80
78
  ],
81
- "require": [
82
- "@babel/register"
83
- ],
84
79
  "sourceMap": false
85
80
  },
86
- "gitHead": "5c3cdaaa082559232fe3c60bdbf9ce2da337f776"
81
+ "prettier": {
82
+ "semi": false,
83
+ "printWidth": 100,
84
+ "bracketSpacing": false,
85
+ "singleQuote": true
86
+ }
87
87
  }
package/sanityClient.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable no-dupe-class-members, @typescript-eslint/no-misused-new */
2
- import Observable from '@sanity/observable/minimal'
2
+ import type {Observable} from 'rxjs'
3
3
 
4
4
  export type AssetMetadataType =
5
5
  | 'location'
@@ -51,6 +51,7 @@ interface RawRequestOptions {
51
51
  timeout?: number
52
52
  proxy?: string
53
53
  body?: any
54
+ maxRedirects?: number
54
55
  }
55
56
 
56
57
  interface AuthProvider {
@@ -190,7 +191,6 @@ export type InsertPatch =
190
191
  export interface PatchOperations {
191
192
  set?: {[key: string]: any}
192
193
  setIfMissing?: {[key: string]: any}
193
- merge?: {[key: string]: any}
194
194
  diffMatchPatch?: {[key: string]: any}
195
195
  unset?: string[]
196
196
  inc?: {[key: string]: number}
@@ -230,15 +230,6 @@ export class Patch {
230
230
  */
231
231
  clone(): Patch
232
232
 
233
- /**
234
- * DEPRECATED: Don't use.
235
- * The operation is added to the current patch, ready to be commited by `commit()`
236
- *
237
- * @deprecated
238
- * @param attrs Attributes to merge
239
- */
240
- merge(attrs: AttributeSet): this
241
-
242
233
  /**
243
234
  * DEPRECATED: Don't use.
244
235
  * The operation is added to the current patch, ready to be commited by `commit()`
@@ -512,16 +503,6 @@ export interface ClientConfig {
512
503
  ignoreBrowserTokenWarning?: boolean
513
504
  withCredentials?: boolean
514
505
 
515
- /**
516
- * @deprecated Don't use
517
- */
518
- gradientMode?: boolean
519
-
520
- /**
521
- * @deprecated Don't use
522
- */
523
- namespace?: string
524
-
525
506
  /**
526
507
  * @deprecated Don't use
527
508
  */