@sanity/client 4.0.1 → 5.0.0-esm.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/dist/index.browser.cjs +1335 -0
- package/dist/index.browser.cjs.map +1 -0
- package/dist/index.browser.js +1312 -0
- package/dist/index.browser.js.map +1 -0
- package/dist/index.cjs +1344 -0
- package/dist/index.cjs.js +15 -0
- package/dist/index.cjs.map +1 -0
- package/{sanityClient.d.ts → dist/index.d.ts} +991 -1117
- package/dist/index.js +1321 -0
- package/dist/index.js.map +1 -0
- package/package.json +81 -73
- package/src/SanityClient.ts +1261 -0
- package/src/assets/AssetsClient.ts +164 -0
- package/src/auth/AuthClient.ts +43 -0
- package/src/config.ts +95 -0
- package/src/data/dataMethods.ts +328 -0
- package/src/data/encodeQueryString.ts +28 -0
- package/src/data/listen.ts +195 -0
- package/src/data/patch.ts +353 -0
- package/src/data/transaction.ts +352 -0
- package/src/datasets/DatasetsClient.ts +97 -0
- package/src/generateHelpUrl.ts +5 -0
- package/src/http/browserMiddleware.ts +1 -0
- package/src/http/errors.ts +68 -0
- package/src/http/nodeMiddleware.ts +11 -0
- package/src/http/request.ts +50 -0
- package/src/http/requestOptions.ts +31 -0
- package/src/index.browser.ts +18 -0
- package/src/index.ts +57 -0
- package/src/projects/ProjectsClient.ts +45 -0
- package/src/types.ts +502 -0
- package/src/users/UsersClient.ts +46 -0
- package/src/util/defaults.ts +8 -0
- package/src/util/getSelection.ts +21 -0
- package/src/util/once.ts +12 -0
- package/src/util/pick.ts +9 -0
- package/src/validators.ts +76 -0
- package/src/warnings.ts +25 -0
- package/umd/sanityClient.js +5199 -5302
- package/umd/sanityClient.min.js +13 -13
- package/dist/sanityClient.browser.mjs +0 -2806
- package/dist/sanityClient.browser.mjs.map +0 -7
- package/index.js +0 -7
- package/lib/assets/assetsClient.js +0 -145
- package/lib/auth/authClient.js +0 -26
- package/lib/config.js +0 -88
- package/lib/data/dataMethods.js +0 -205
- package/lib/data/encodeQueryString.js +0 -31
- package/lib/data/listen.js +0 -164
- package/lib/data/patch.js +0 -121
- package/lib/data/transaction.js +0 -117
- package/lib/datasets/datasetsClient.js +0 -41
- package/lib/generateHelpUrl.js +0 -11
- package/lib/http/browserMiddleware.js +0 -9
- package/lib/http/errors.js +0 -56
- package/lib/http/nodeMiddleware.js +0 -22
- package/lib/http/queryString.js +0 -17
- package/lib/http/request.js +0 -52
- package/lib/http/requestOptions.js +0 -30
- package/lib/projects/projectsClient.js +0 -25
- package/lib/sanityClient.js +0 -118
- package/lib/users/usersClient.js +0 -20
- package/lib/util/defaults.js +0 -14
- package/lib/util/getSelection.js +0 -24
- package/lib/util/once.js +0 -20
- package/lib/util/pick.js +0 -17
- package/lib/validators.js +0 -76
- package/lib/warnings.js +0 -27
package/lib/util/defaults.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
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];
|
|
10
|
-
return target;
|
|
11
|
-
}, {});
|
|
12
|
-
};
|
|
13
|
-
exports.default = _default;
|
|
14
|
-
module.exports = exports.default;
|
package/lib/util/getSelection.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = getSelection;
|
|
7
|
-
function getSelection(sel) {
|
|
8
|
-
if (typeof sel === 'string' || Array.isArray(sel)) {
|
|
9
|
-
return {
|
|
10
|
-
id: sel
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
if (sel && sel.query) {
|
|
14
|
-
return 'params' in sel ? {
|
|
15
|
-
query: sel.query,
|
|
16
|
-
params: sel.params
|
|
17
|
-
} : {
|
|
18
|
-
query: sel.query
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
var selectionOpts = ['* Document ID (<docId>)', '* Array of document IDs', '* Object containing `query`'].join('\n');
|
|
22
|
-
throw new Error("Unknown selection - must be one of:\n\n".concat(selectionOpts));
|
|
23
|
-
}
|
|
24
|
-
module.exports = exports.default;
|
package/lib/util/once.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _default = function _default(fn) {
|
|
8
|
-
var didCall = false;
|
|
9
|
-
var returnValue;
|
|
10
|
-
return function () {
|
|
11
|
-
if (didCall) {
|
|
12
|
-
return returnValue;
|
|
13
|
-
}
|
|
14
|
-
returnValue = fn.apply(void 0, arguments);
|
|
15
|
-
didCall = true;
|
|
16
|
-
return returnValue;
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
exports.default = _default;
|
|
20
|
-
module.exports = exports.default;
|
package/lib/util/pick.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _default = function _default(obj, props) {
|
|
8
|
-
return props.reduce(function (selection, prop) {
|
|
9
|
-
if (typeof obj[prop] === 'undefined') {
|
|
10
|
-
return selection;
|
|
11
|
-
}
|
|
12
|
-
selection[prop] = obj[prop];
|
|
13
|
-
return selection;
|
|
14
|
-
}, {});
|
|
15
|
-
};
|
|
16
|
-
exports.default = _default;
|
|
17
|
-
module.exports = exports.default;
|
package/lib/validators.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
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
|
-
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); }
|
|
8
|
-
var VALID_ASSET_TYPES = ['image', 'file'];
|
|
9
|
-
var VALID_INSERT_LOCATIONS = ['before', 'after', 'replace'];
|
|
10
|
-
var dataset = function dataset(name) {
|
|
11
|
-
if (!/^(~[a-z0-9]{1}[-\w]{0,63}|[a-z0-9]{1}[-\w]{0,63})$/.test(name)) {
|
|
12
|
-
throw new Error('Datasets can only contain lowercase characters, numbers, underscores and dashes, and start with tilde, and be maximum 64 characters');
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
exports.dataset = dataset;
|
|
16
|
-
var projectId = function projectId(id) {
|
|
17
|
-
if (!/^[-a-z0-9]+$/i.test(id)) {
|
|
18
|
-
throw new Error('`projectId` can only contain only a-z, 0-9 and dashes');
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
exports.projectId = projectId;
|
|
22
|
-
var validateAssetType = function validateAssetType(type) {
|
|
23
|
-
if (VALID_ASSET_TYPES.indexOf(type) === -1) {
|
|
24
|
-
throw new Error("Invalid asset type: ".concat(type, ". Must be one of ").concat(VALID_ASSET_TYPES.join(', ')));
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
exports.validateAssetType = validateAssetType;
|
|
28
|
-
var validateObject = function validateObject(op, val) {
|
|
29
|
-
if (val === null || _typeof(val) !== 'object' || Array.isArray(val)) {
|
|
30
|
-
throw new Error("".concat(op, "() takes an object of properties"));
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
exports.validateObject = validateObject;
|
|
34
|
-
var validateDocumentId = function validateDocumentId(op, id) {
|
|
35
|
-
if (typeof id !== 'string' || !/^[a-z0-9_.-]+$/i.test(id)) {
|
|
36
|
-
throw new Error("".concat(op, "(): \"").concat(id, "\" is not a valid document ID"));
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
exports.validateDocumentId = validateDocumentId;
|
|
40
|
-
var requireDocumentId = function requireDocumentId(op, doc) {
|
|
41
|
-
if (!doc._id) {
|
|
42
|
-
throw new Error("".concat(op, "() requires that the document contains an ID (\"_id\" property)"));
|
|
43
|
-
}
|
|
44
|
-
validateDocumentId(op, doc._id);
|
|
45
|
-
};
|
|
46
|
-
exports.requireDocumentId = requireDocumentId;
|
|
47
|
-
var validateInsert = function validateInsert(at, selector, items) {
|
|
48
|
-
var signature = 'insert(at, selector, items)';
|
|
49
|
-
if (VALID_INSERT_LOCATIONS.indexOf(at) === -1) {
|
|
50
|
-
var valid = VALID_INSERT_LOCATIONS.map(function (loc) {
|
|
51
|
-
return "\"".concat(loc, "\"");
|
|
52
|
-
}).join(', ');
|
|
53
|
-
throw new Error("".concat(signature, " takes an \"at\"-argument which is one of: ").concat(valid));
|
|
54
|
-
}
|
|
55
|
-
if (typeof selector !== 'string') {
|
|
56
|
-
throw new Error("".concat(signature, " takes a \"selector\"-argument which must be a string"));
|
|
57
|
-
}
|
|
58
|
-
if (!Array.isArray(items)) {
|
|
59
|
-
throw new Error("".concat(signature, " takes an \"items\"-argument which must be an array"));
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
exports.validateInsert = validateInsert;
|
|
63
|
-
var hasDataset = function hasDataset(config) {
|
|
64
|
-
if (!config.dataset) {
|
|
65
|
-
throw new Error('`dataset` must be provided to perform queries');
|
|
66
|
-
}
|
|
67
|
-
return config.dataset || '';
|
|
68
|
-
};
|
|
69
|
-
exports.hasDataset = hasDataset;
|
|
70
|
-
var requestTag = function requestTag(tag) {
|
|
71
|
-
if (typeof tag !== 'string' || !/^[a-z0-9._-]{1,75}$/i.test(tag)) {
|
|
72
|
-
throw new Error("Tag can only contain alphanumeric characters, underscores, dashes and dots, and be between one and 75 characters long.");
|
|
73
|
-
}
|
|
74
|
-
return tag;
|
|
75
|
-
};
|
|
76
|
-
exports.requestTag = requestTag;
|
package/lib/warnings.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.printNoApiVersionSpecifiedWarning = exports.printCdnWarning = exports.printBrowserTokenWarning = void 0;
|
|
7
|
-
var _generateHelpUrl = _interopRequireDefault(require("./generateHelpUrl"));
|
|
8
|
-
var _once = _interopRequireDefault(require("./util/once"));
|
|
9
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
-
var createWarningPrinter = function createWarningPrinter(message) {
|
|
11
|
-
return (
|
|
12
|
-
// eslint-disable-next-line no-console
|
|
13
|
-
(0, _once.default)(function () {
|
|
14
|
-
var _console;
|
|
15
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
16
|
-
args[_key] = arguments[_key];
|
|
17
|
-
}
|
|
18
|
-
return (_console = console).warn.apply(_console, [message.join(' ')].concat(args));
|
|
19
|
-
})
|
|
20
|
-
);
|
|
21
|
-
};
|
|
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.']);
|
|
23
|
-
exports.printCdnWarning = printCdnWarning;
|
|
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.")]);
|
|
25
|
-
exports.printBrowserTokenWarning = printBrowserTokenWarning;
|
|
26
|
-
var printNoApiVersionSpecifiedWarning = createWarningPrinter(['Using the Sanity client without specifying an API version is deprecated.', "See ".concat((0, _generateHelpUrl.default)('js-client-api-version'))]);
|
|
27
|
-
exports.printNoApiVersionSpecifiedWarning = printNoApiVersionSpecifiedWarning;
|