@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
@@ -3,14 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.defaults = void 0;
7
-
8
- // eslint-disable-next-line no-shadow
9
- var defaults = function defaults(obj, _defaults) {
10
- return Object.keys(_defaults).concat(Object.keys(obj)).reduce(function (target, prop) {
11
- target[prop] = typeof obj[prop] === 'undefined' ? _defaults[prop] : obj[prop];
6
+ exports.default = void 0;
7
+ var _default = function _default(obj, defaults) {
8
+ return Object.keys(defaults).concat(Object.keys(obj)).reduce(function (target, prop) {
9
+ target[prop] = typeof obj[prop] === 'undefined' ? defaults[prop] : obj[prop];
12
10
  return target;
13
11
  }, {});
14
12
  };
15
-
16
- exports.defaults = defaults;
13
+ exports.default = _default;
14
+ module.exports = exports.default;
@@ -3,15 +3,13 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getSelection = getSelection;
7
-
6
+ exports.default = getSelection;
8
7
  function getSelection(sel) {
9
8
  if (typeof sel === 'string' || Array.isArray(sel)) {
10
9
  return {
11
10
  id: sel
12
11
  };
13
12
  }
14
-
15
13
  if (sel && sel.query) {
16
14
  return 'params' in sel ? {
17
15
  query: sel.query,
@@ -20,7 +18,7 @@ function getSelection(sel) {
20
18
  query: sel.query
21
19
  };
22
20
  }
23
-
24
21
  var selectionOpts = ['* Document ID (<docId>)', '* Array of document IDs', '* Object containing `query`'].join('\n');
25
22
  throw new Error("Unknown selection - must be one of:\n\n".concat(selectionOpts));
26
- }
23
+ }
24
+ module.exports = exports.default;
package/lib/util/once.js CHANGED
@@ -3,20 +3,18 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.once = void 0;
7
-
8
- var once = function once(fn) {
6
+ exports.default = void 0;
7
+ var _default = function _default(fn) {
9
8
  var didCall = false;
10
9
  var returnValue;
11
10
  return function () {
12
11
  if (didCall) {
13
12
  return returnValue;
14
13
  }
15
-
16
14
  returnValue = fn.apply(void 0, arguments);
17
15
  didCall = true;
18
16
  return returnValue;
19
17
  };
20
18
  };
21
-
22
- exports.once = once;
19
+ exports.default = _default;
20
+ module.exports = exports.default;
package/lib/util/pick.js CHANGED
@@ -3,17 +3,15 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.pick = void 0;
7
-
8
- var pick = function pick(obj, props) {
6
+ exports.default = void 0;
7
+ var _default = function _default(obj, props) {
9
8
  return props.reduce(function (selection, prop) {
10
9
  if (typeof obj[prop] === 'undefined') {
11
10
  return selection;
12
11
  }
13
-
14
12
  selection[prop] = obj[prop];
15
13
  return selection;
16
14
  }, {});
17
15
  };
18
-
19
- exports.pick = pick;
16
+ exports.default = _default;
17
+ module.exports = exports.default;
package/lib/validators.js CHANGED
@@ -4,99 +4,73 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.validateObject = exports.validateInsert = exports.validateDocumentId = exports.validateAssetType = exports.requireDocumentId = exports.requestTag = exports.projectId = exports.hasDataset = exports.dataset = void 0;
7
-
8
7
  function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
9
-
10
8
  var VALID_ASSET_TYPES = ['image', 'file'];
11
9
  var VALID_INSERT_LOCATIONS = ['before', 'after', 'replace'];
12
-
13
10
  var dataset = function dataset(name) {
14
11
  if (!/^(~[a-z0-9]{1}[-\w]{0,63}|[a-z0-9]{1}[-\w]{0,63})$/.test(name)) {
15
12
  throw new Error('Datasets can only contain lowercase characters, numbers, underscores and dashes, and start with tilde, and be maximum 64 characters');
16
13
  }
17
14
  };
18
-
19
15
  exports.dataset = dataset;
20
-
21
16
  var projectId = function projectId(id) {
22
17
  if (!/^[-a-z0-9]+$/i.test(id)) {
23
18
  throw new Error('`projectId` can only contain only a-z, 0-9 and dashes');
24
19
  }
25
20
  };
26
-
27
21
  exports.projectId = projectId;
28
-
29
22
  var validateAssetType = function validateAssetType(type) {
30
23
  if (VALID_ASSET_TYPES.indexOf(type) === -1) {
31
24
  throw new Error("Invalid asset type: ".concat(type, ". Must be one of ").concat(VALID_ASSET_TYPES.join(', ')));
32
25
  }
33
26
  };
34
-
35
27
  exports.validateAssetType = validateAssetType;
36
-
37
28
  var validateObject = function validateObject(op, val) {
38
29
  if (val === null || _typeof(val) !== 'object' || Array.isArray(val)) {
39
30
  throw new Error("".concat(op, "() takes an object of properties"));
40
31
  }
41
32
  };
42
-
43
33
  exports.validateObject = validateObject;
44
-
45
34
  var validateDocumentId = function validateDocumentId(op, id) {
46
35
  if (typeof id !== 'string' || !/^[a-z0-9_.-]+$/i.test(id)) {
47
36
  throw new Error("".concat(op, "(): \"").concat(id, "\" is not a valid document ID"));
48
37
  }
49
38
  };
50
-
51
39
  exports.validateDocumentId = validateDocumentId;
52
-
53
40
  var requireDocumentId = function requireDocumentId(op, doc) {
54
41
  if (!doc._id) {
55
42
  throw new Error("".concat(op, "() requires that the document contains an ID (\"_id\" property)"));
56
43
  }
57
-
58
44
  validateDocumentId(op, doc._id);
59
45
  };
60
-
61
46
  exports.requireDocumentId = requireDocumentId;
62
-
63
47
  var validateInsert = function validateInsert(at, selector, items) {
64
48
  var signature = 'insert(at, selector, items)';
65
-
66
49
  if (VALID_INSERT_LOCATIONS.indexOf(at) === -1) {
67
50
  var valid = VALID_INSERT_LOCATIONS.map(function (loc) {
68
51
  return "\"".concat(loc, "\"");
69
52
  }).join(', ');
70
53
  throw new Error("".concat(signature, " takes an \"at\"-argument which is one of: ").concat(valid));
71
54
  }
72
-
73
55
  if (typeof selector !== 'string') {
74
56
  throw new Error("".concat(signature, " takes a \"selector\"-argument which must be a string"));
75
57
  }
76
-
77
58
  if (!Array.isArray(items)) {
78
59
  throw new Error("".concat(signature, " takes an \"items\"-argument which must be an array"));
79
60
  }
80
61
  };
81
-
82
62
  exports.validateInsert = validateInsert;
83
-
84
63
  var hasDataset = function hasDataset(config) {
85
64
  if (!config.dataset) {
86
65
  throw new Error('`dataset` must be provided to perform queries');
87
66
  }
88
-
89
67
  return config.dataset || '';
90
68
  };
91
-
92
69
  exports.hasDataset = hasDataset;
93
-
94
70
  var requestTag = function requestTag(tag) {
95
71
  if (typeof tag !== 'string' || !/^[a-z0-9._-]{1,75}$/i.test(tag)) {
96
72
  throw new Error("Tag can only contain alphanumeric characters, underscores, dashes and dots, and be between one and 75 characters long.");
97
73
  }
98
-
99
74
  return tag;
100
75
  };
101
-
102
76
  exports.requestTag = requestTag;
package/lib/warnings.js CHANGED
@@ -4,28 +4,24 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.printNoApiVersionSpecifiedWarning = exports.printCdnWarning = exports.printBrowserTokenWarning = void 0;
7
-
8
- var _generateHelpUrl = require("@sanity/generate-help-url");
9
-
10
- var _once = require("./util/once");
11
-
7
+ var _generateHelpUrl = _interopRequireDefault(require("./generateHelpUrl"));
8
+ var _once = _interopRequireDefault(require("./util/once"));
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
10
  var createWarningPrinter = function createWarningPrinter(message) {
13
- return (// eslint-disable-next-line no-console
14
- (0, _once.once)(function () {
11
+ return (
12
+ // eslint-disable-next-line no-console
13
+ (0, _once.default)(function () {
15
14
  var _console;
16
-
17
15
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
18
16
  args[_key] = arguments[_key];
19
17
  }
20
-
21
18
  return (_console = console).warn.apply(_console, [message.join(' ')].concat(args));
22
19
  })
23
20
  );
24
21
  };
25
-
26
- var 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((0, _generateHelpUrl.generateHelpUrl)('js-client-cdn-configuration'), "."), 'To hide this warning, please set the `useCdn` option to either `true` or `false` when creating', 'the client.']);
22
+ var 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((0, _generateHelpUrl.default)('js-client-cdn-configuration'), "."), 'To hide this warning, please set the `useCdn` option to either `true` or `false` when creating', 'the client.']);
27
23
  exports.printCdnWarning = printCdnWarning;
28
- var printBrowserTokenWarning = createWarningPrinter(['You have configured Sanity client to use a token in the browser. This may cause unintentional security issues.', "See ".concat((0, _generateHelpUrl.generateHelpUrl)('js-client-browser-token'), " for more information and how to hide this warning.")]);
24
+ var printBrowserTokenWarning = createWarningPrinter(['You have configured Sanity client to use a token in the browser. This may cause unintentional security issues.', "See ".concat((0, _generateHelpUrl.default)('js-client-browser-token'), " for more information and how to hide this warning.")]);
29
25
  exports.printBrowserTokenWarning = printBrowserTokenWarning;
30
- var printNoApiVersionSpecifiedWarning = createWarningPrinter(['Using the Sanity client without specifying an API version is deprecated.', "See ".concat((0, _generateHelpUrl.generateHelpUrl)('js-client-api-version'))]);
26
+ var printNoApiVersionSpecifiedWarning = createWarningPrinter(['Using the Sanity client without specifying an API version is deprecated.', "See ".concat((0, _generateHelpUrl.default)('js-client-api-version'))]);
31
27
  exports.printNoApiVersionSpecifiedWarning = printNoApiVersionSpecifiedWarning;
package/package.json CHANGED
@@ -1,40 +1,48 @@
1
1
  {
2
2
  "name": "@sanity/client",
3
- "version": "4.0.0-alpha.esm.6",
3
+ "version": "4.0.1-0",
4
4
  "description": "Client for retrieving, creating and patching data from Sanity.io",
5
- "main": "lib/sanityClient.js",
5
+ "type": "commonjs",
6
+ "main": "index.js",
6
7
  "umd": "umd/sanityClient.min.js",
7
8
  "unpkg": "umd/sanityClient.min.js",
8
9
  "types": "./sanityClient.d.ts",
9
- "module": "./dist/sanityClient.js",
10
10
  "exports": {
11
11
  ".": {
12
12
  "source": "./src/sanityClient.js",
13
- "browser": "./dist/browser/sanityClient.js",
14
- "default": "./dist/node/sanityClient.js"
13
+ "types": "./sanityClient.d.ts",
14
+ "browser": "./dist/sanityClient.browser.mjs",
15
+ "deno": "./dist/sanityClient.browser.mjs",
16
+ "default": "./lib/sanityClient.js"
15
17
  },
16
- "./src/http/nodeMiddleware": {
17
- "browser": "./src/http/nodeMiddleware.js",
18
- "default": "./src/http/nodeMiddleware.js"
19
- }
18
+ "./package.json": "./package.json"
20
19
  },
20
+ "files": [
21
+ "dist",
22
+ "lib",
23
+ "umd",
24
+ "index.js",
25
+ "sanityClient.d.ts"
26
+ ],
21
27
  "scripts": {
22
- "browserify": "NODE_ENV=production BROWSERIFY_ENV=build DEBUG='' browserify -t envify -g uglifyify lib/sanityClient.js -o umd/sanityClient.js --standalone=SanityClient",
28
+ "rollup": "NODE_ENV=production rollup -c rollup.config.js",
23
29
  "compile": "babel -d lib src",
24
- "build": "npm run compile && npm run browserify && npm run minify && npm run esbuild:browser && npm run esbuild:node",
25
- "esbuild": "esbuild src/sanityClient.js --bundle --format=esm",
26
- "esbuild:browser": "npm run esbuild -- --outfile=dist/browser/sanityClient.js --platform=browser",
27
- "esbuild:node": "npm run esbuild -- --outfile=dist/node/sanityClient.js --platform=node --external:get-it --external:@sanity/eventsource --external:@sanity/generate-help-url --external:make-error --external:rxjs",
28
- "postesbuild": "package-check || true",
30
+ "build": "npm run compile && npm run rollup && npm run minify && npm run esbuild:browser",
31
+ "esbuild": "esbuild src/sanityClient.js --bundle --sourcemap --external:get-it",
32
+ "esbuild-when-upstream-deps-works-in-deno-cloudflare-and-vercel": "esbuild src/sanityClient.js --bundle --sourcemap --external:rxjs --external:@sanity/eventsource --external:get-it --external:make-error",
33
+ "esbuild:browser": "npm run esbuild -- --format=esm --outfile=dist/sanityClient.browser.mjs --platform=browser",
29
34
  "lint": "eslint .",
30
- "clean": "rimraf lib coverage .nyc_output umd/*.js",
35
+ "clean": "rimraf dist lib coverage .nyc_output umd/*.js",
36
+ "typecheck": "tsc --lib es2015 --lib dom,es2015 --noEmit sanityClient.d.ts",
31
37
  "coverage": "DEBUG=sanity NODE_ENV=test nyc --reporter=html --reporter=lcov --reporter=text npm test",
32
38
  "minify": "terser -c -m -- umd/sanityClient.js > umd/sanityClient.min.js",
33
- "prepublishOnly": "npm run build",
34
- "test": "NODE_ENV=test tape test/*.test.js",
35
- "posttest": "npm run lint"
39
+ "prepublishOnly": "npm run clean && npm run build",
40
+ "test": "NODE_ENV=test babel-tape-runner test/*.test.js",
41
+ "posttest": "npm run lint && npm run typecheck --strict"
36
42
  },
37
43
  "browser": {
44
+ "get-it": "get-it/lib",
45
+ "get-it/middleware": "get-it/lib/middleware",
38
46
  "./src/http/nodeMiddleware.js": "./src/http/browserMiddleware.js",
39
47
  "./lib/http/nodeMiddleware.js": "./lib/http/browserMiddleware.js"
40
48
  },
@@ -42,33 +50,36 @@
42
50
  "node": ">=12"
43
51
  },
44
52
  "dependencies": {
45
- "@sanity/eventsource": "^3.0.2",
46
- "@sanity/generate-help-url": "^3.0.0",
47
- "get-it": "^6.0.1",
48
- "make-error": "^1.3.0",
49
- "rxjs": "^6.0.0"
53
+ "@sanity/eventsource": "^4.0.0",
54
+ "get-it": "^7.0.2",
55
+ "make-error": "^1.3.6",
56
+ "rxjs": "^7.0.0"
50
57
  },
51
58
  "devDependencies": {
52
- "@babel/cli": "^7.17.6",
53
- "@babel/core": "^7.17.7",
54
- "@babel/eslint-parser": "^7.17.0",
55
- "@babel/preset-env": "^7.11.5",
56
- "@skypack/package-check": "^0.2.2",
57
- "browserify": "^17.0.0",
58
- "envify": "^4.0.0",
59
- "esbuild": "^0.14.38",
60
- "eslint": "^8.11.0",
59
+ "@babel/cli": "^7.20.7",
60
+ "@babel/core": "^7.20.7",
61
+ "@babel/plugin-transform-object-assign": "^7.18.6",
62
+ "@babel/preset-env": "^7.20.2",
63
+ "@rollup/plugin-commonjs": "^24.0.0",
64
+ "@rollup/plugin-node-resolve": "^15.0.1",
65
+ "@sanity/semantic-release-preset": "^2.0.5",
66
+ "@types/node": "^18.11.18",
67
+ "babel-plugin-add-module-exports": "^1.0.4",
68
+ "babel-plugin-istanbul": "^6.1.1",
69
+ "babel-tape-runner": "^3.0.0",
70
+ "esbuild": "^0.16.12",
71
+ "eslint": "^8.31.0",
61
72
  "eslint-config-prettier": "^8.5.0",
62
- "eslint-config-sanity": "^5.1.0",
63
- "esm": "^3.2.25",
64
- "nock": "^13.2.4",
73
+ "eslint-config-sanity": "^6.0.0",
74
+ "nock": "^13.2.9",
65
75
  "nyc": "^15.1.0",
66
- "prettier": "^2.6.0",
76
+ "prettier": "^2.8.1",
67
77
  "rimraf": "^3.0.2",
78
+ "rollup": "^3.9.1",
68
79
  "sse-channel": "^4.0.0",
69
- "tape": "^5.5.2",
70
- "terser": "^5.12.1",
71
- "uglifyify": "^5.0.1",
80
+ "tape": "^5.6.1",
81
+ "terser": "^5.16.1",
82
+ "typescript": "^4.9.4",
72
83
  "xtend": "4.0.2"
73
84
  },
74
85
  "repository": {