@sanity/client 3.3.3-esm.0 → 3.3.3-esm.11
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/dist/sanityClient.browser.mjs +2834 -1062
- package/dist/sanityClient.browser.mjs.map +4 -4
- package/lib/assets/assetsClient.js +29 -15
- package/lib/auth/authClient.js +11 -3
- package/lib/config.js +40 -22
- package/lib/data/dataMethods.js +38 -24
- package/lib/data/encodeQueryString.js +9 -2
- package/lib/data/listen.js +30 -22
- package/lib/data/patch.js +36 -27
- package/lib/data/transaction.js +27 -11
- package/lib/datasets/datasetsClient.js +18 -4
- package/lib/generateHelpUrl.js +8 -2
- package/lib/http/browserMiddleware.js +7 -1
- package/lib/http/errors.js +16 -8
- package/lib/http/nodeMiddleware.js +16 -7
- package/lib/http/queryString.js +10 -2
- package/lib/http/request.js +23 -23
- package/lib/http/requestOptions.js +13 -5
- package/lib/projects/projectsClient.js +11 -3
- package/lib/sanityClient.js +59 -45
- package/lib/users/usersClient.js +11 -3
- package/lib/util/defaults.js +10 -2
- package/lib/util/getSelection.js +9 -2
- package/lib/util/observable.js +24 -13
- package/lib/util/once.js +10 -2
- package/lib/util/pick.js +10 -2
- package/lib/validators.js +38 -15
- package/lib/warnings.js +16 -6
- package/package.json +15 -7
- package/umd/sanityClient.js +168 -100
- package/umd/sanityClient.min.js +1 -1
package/lib/validators.js
CHANGED
|
@@ -1,49 +1,66 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.validateObject = exports.validateInsert = exports.validateDocumentId = exports.validateAssetType = exports.requireDocumentId = exports.requestTag = exports.projectId = exports.hasDataset = exports.dataset = void 0;
|
|
7
|
+
|
|
3
8
|
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); }
|
|
4
9
|
|
|
5
10
|
var VALID_ASSET_TYPES = ['image', 'file'];
|
|
6
11
|
var VALID_INSERT_LOCATIONS = ['before', 'after', 'replace'];
|
|
7
12
|
|
|
8
|
-
|
|
13
|
+
var dataset = function dataset(name) {
|
|
9
14
|
if (!/^(~[a-z0-9]{1}[-\w]{0,63}|[a-z0-9]{1}[-\w]{0,63})$/.test(name)) {
|
|
10
15
|
throw new Error('Datasets can only contain lowercase characters, numbers, underscores and dashes, and start with tilde, and be maximum 64 characters');
|
|
11
16
|
}
|
|
12
17
|
};
|
|
13
18
|
|
|
14
|
-
exports.
|
|
19
|
+
exports.dataset = dataset;
|
|
20
|
+
|
|
21
|
+
var projectId = function projectId(id) {
|
|
15
22
|
if (!/^[-a-z0-9]+$/i.test(id)) {
|
|
16
23
|
throw new Error('`projectId` can only contain only a-z, 0-9 and dashes');
|
|
17
24
|
}
|
|
18
25
|
};
|
|
19
26
|
|
|
20
|
-
exports.
|
|
27
|
+
exports.projectId = projectId;
|
|
28
|
+
|
|
29
|
+
var validateAssetType = function validateAssetType(type) {
|
|
21
30
|
if (VALID_ASSET_TYPES.indexOf(type) === -1) {
|
|
22
31
|
throw new Error("Invalid asset type: ".concat(type, ". Must be one of ").concat(VALID_ASSET_TYPES.join(', ')));
|
|
23
32
|
}
|
|
24
33
|
};
|
|
25
34
|
|
|
26
|
-
exports.
|
|
35
|
+
exports.validateAssetType = validateAssetType;
|
|
36
|
+
|
|
37
|
+
var validateObject = function validateObject(op, val) {
|
|
27
38
|
if (val === null || _typeof(val) !== 'object' || Array.isArray(val)) {
|
|
28
39
|
throw new Error("".concat(op, "() takes an object of properties"));
|
|
29
40
|
}
|
|
30
41
|
};
|
|
31
42
|
|
|
32
|
-
exports.
|
|
43
|
+
exports.validateObject = validateObject;
|
|
44
|
+
|
|
45
|
+
var validateDocumentId = function validateDocumentId(op, id) {
|
|
46
|
+
if (typeof id !== 'string' || !/^[a-z0-9_.-]+$/i.test(id)) {
|
|
47
|
+
throw new Error("".concat(op, "(): \"").concat(id, "\" is not a valid document ID"));
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
exports.validateDocumentId = validateDocumentId;
|
|
52
|
+
|
|
53
|
+
var requireDocumentId = function requireDocumentId(op, doc) {
|
|
33
54
|
if (!doc._id) {
|
|
34
55
|
throw new Error("".concat(op, "() requires that the document contains an ID (\"_id\" property)"));
|
|
35
56
|
}
|
|
36
57
|
|
|
37
|
-
|
|
58
|
+
validateDocumentId(op, doc._id);
|
|
38
59
|
};
|
|
39
60
|
|
|
40
|
-
exports.
|
|
41
|
-
if (typeof id !== 'string' || !/^[a-z0-9_.-]+$/i.test(id)) {
|
|
42
|
-
throw new Error("".concat(op, "(): \"").concat(id, "\" is not a valid document ID"));
|
|
43
|
-
}
|
|
44
|
-
};
|
|
61
|
+
exports.requireDocumentId = requireDocumentId;
|
|
45
62
|
|
|
46
|
-
|
|
63
|
+
var validateInsert = function validateInsert(at, selector, items) {
|
|
47
64
|
var signature = 'insert(at, selector, items)';
|
|
48
65
|
|
|
49
66
|
if (VALID_INSERT_LOCATIONS.indexOf(at) === -1) {
|
|
@@ -62,7 +79,9 @@ exports.validateInsert = function (at, selector, items) {
|
|
|
62
79
|
}
|
|
63
80
|
};
|
|
64
81
|
|
|
65
|
-
exports.
|
|
82
|
+
exports.validateInsert = validateInsert;
|
|
83
|
+
|
|
84
|
+
var hasDataset = function hasDataset(config) {
|
|
66
85
|
if (!config.dataset) {
|
|
67
86
|
throw new Error('`dataset` must be provided to perform queries');
|
|
68
87
|
}
|
|
@@ -70,10 +89,14 @@ exports.hasDataset = function (config) {
|
|
|
70
89
|
return config.dataset || '';
|
|
71
90
|
};
|
|
72
91
|
|
|
73
|
-
exports.
|
|
92
|
+
exports.hasDataset = hasDataset;
|
|
93
|
+
|
|
94
|
+
var requestTag = function requestTag(tag) {
|
|
74
95
|
if (typeof tag !== 'string' || !/^[a-z0-9._-]{1,75}$/i.test(tag)) {
|
|
75
96
|
throw new Error("Tag can only contain alphanumeric characters, underscores, dashes and dots, and be between one and 75 characters long.");
|
|
76
97
|
}
|
|
77
98
|
|
|
78
99
|
return tag;
|
|
79
|
-
};
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
exports.requestTag = requestTag;
|
package/lib/warnings.js
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.printNoApiVersionSpecifiedWarning = exports.printCdnWarning = exports.printBrowserTokenWarning = void 0;
|
|
4
7
|
|
|
5
|
-
var
|
|
8
|
+
var _generateHelpUrl = _interopRequireDefault(require("./generateHelpUrl"));
|
|
9
|
+
|
|
10
|
+
var _once = _interopRequireDefault(require("./util/once"));
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
6
13
|
|
|
7
14
|
var createWarningPrinter = function createWarningPrinter(message) {
|
|
8
15
|
return (// eslint-disable-next-line no-console
|
|
9
|
-
|
|
16
|
+
(0, _once.default)(function () {
|
|
10
17
|
var _console;
|
|
11
18
|
|
|
12
19
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
@@ -18,6 +25,9 @@ var createWarningPrinter = function createWarningPrinter(message) {
|
|
|
18
25
|
);
|
|
19
26
|
};
|
|
20
27
|
|
|
21
|
-
|
|
22
|
-
exports.
|
|
23
|
-
|
|
28
|
+
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.']);
|
|
29
|
+
exports.printCdnWarning = printCdnWarning;
|
|
30
|
+
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.")]);
|
|
31
|
+
exports.printBrowserTokenWarning = printBrowserTokenWarning;
|
|
32
|
+
var printNoApiVersionSpecifiedWarning = createWarningPrinter(['Using the Sanity client without specifying an API version is deprecated.', "See ".concat((0, _generateHelpUrl.default)('js-client-api-version'))]);
|
|
33
|
+
exports.printNoApiVersionSpecifiedWarning = printNoApiVersionSpecifiedWarning;
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/client",
|
|
3
|
-
"version": "3.3.3-esm.
|
|
3
|
+
"version": "3.3.3-esm.11",
|
|
4
4
|
"description": "Client for retrieving, creating and patching data from Sanity.io",
|
|
5
|
+
"type": "commonjs",
|
|
5
6
|
"main": "lib/sanityClient.js",
|
|
6
7
|
"umd": "umd/sanityClient.min.js",
|
|
7
8
|
"unpkg": "umd/sanityClient.min.js",
|
|
@@ -9,9 +10,12 @@
|
|
|
9
10
|
"exports": {
|
|
10
11
|
".": {
|
|
11
12
|
"source": "./src/sanityClient.js",
|
|
13
|
+
"types": "./sanityClient.d.ts",
|
|
12
14
|
"browser": "./dist/sanityClient.browser.mjs",
|
|
15
|
+
"deno": "./dist/sanityClient.browser.mjs",
|
|
13
16
|
"default": "./lib/sanityClient.js"
|
|
14
|
-
}
|
|
17
|
+
},
|
|
18
|
+
"./package.json": "./package.json"
|
|
15
19
|
},
|
|
16
20
|
"files": [
|
|
17
21
|
"dist",
|
|
@@ -23,7 +27,8 @@
|
|
|
23
27
|
"browserify": "NODE_ENV=production BROWSERIFY_ENV=build DEBUG='' browserify -t envify -g uglifyify lib/sanityClient.js -o umd/sanityClient.js --standalone=SanityClient",
|
|
24
28
|
"compile": "babel -d lib src",
|
|
25
29
|
"build": "npm run compile && npm run browserify && npm run minify && npm run esbuild:browser",
|
|
26
|
-
"esbuild": "esbuild src/sanityClient.js --bundle --sourcemap --external:
|
|
30
|
+
"esbuild": "esbuild src/sanityClient.js --bundle --sourcemap --external:get-it",
|
|
31
|
+
"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",
|
|
27
32
|
"esbuild:browser": "npm run esbuild -- --format=esm --outfile=dist/sanityClient.browser.mjs --platform=browser",
|
|
28
33
|
"lint": "eslint .",
|
|
29
34
|
"clean": "rimraf dist lib coverage .nyc_output umd/*.js",
|
|
@@ -31,7 +36,7 @@
|
|
|
31
36
|
"coverage": "DEBUG=sanity NODE_ENV=test nyc --reporter=html --reporter=lcov --reporter=text npm test",
|
|
32
37
|
"minify": "terser -c -m -- umd/sanityClient.js > umd/sanityClient.min.js",
|
|
33
38
|
"prepublishOnly": "npm run clean && npm run build",
|
|
34
|
-
"test": "NODE_ENV=test tape test/*.test.js",
|
|
39
|
+
"test": "NODE_ENV=test babel-tape-runner test/*.test.js",
|
|
35
40
|
"posttest": "npm run lint && npm run typecheck"
|
|
36
41
|
},
|
|
37
42
|
"browser": {
|
|
@@ -43,16 +48,19 @@
|
|
|
43
48
|
},
|
|
44
49
|
"dependencies": {
|
|
45
50
|
"@sanity/eventsource": "^4.0.0",
|
|
46
|
-
"get-it": "esm",
|
|
51
|
+
"get-it": "6.1.1-esm.9",
|
|
47
52
|
"make-error": "^1.3.0",
|
|
48
|
-
"
|
|
49
|
-
"rxjs": "^6.0.0"
|
|
53
|
+
"rxjs": "^6.6.7"
|
|
50
54
|
},
|
|
51
55
|
"devDependencies": {
|
|
52
56
|
"@babel/cli": "^7.18.10",
|
|
53
57
|
"@babel/core": "^7.18.10",
|
|
58
|
+
"@babel/plugin-transform-object-assign": "^7.18.6",
|
|
54
59
|
"@babel/preset-env": "^7.18.10",
|
|
55
60
|
"@types/node": "^16.11.49",
|
|
61
|
+
"babel-plugin-add-module-exports": "^1.0.4",
|
|
62
|
+
"babel-plugin-istanbul": "^6.1.1",
|
|
63
|
+
"babel-tape-runner": "^3.0.0",
|
|
56
64
|
"browserify": "^17.0.0",
|
|
57
65
|
"envify": "^4.0.0",
|
|
58
66
|
"esbuild": "^0.15.5",
|