@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
@@ -1,46 +1,37 @@
1
1
  "use strict";
2
2
 
3
3
  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
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
- exports.AssetsClient = void 0;
9
-
10
- var _observable = require("../util/observable");
11
-
12
- var _queryString = require("../http/queryString");
13
-
7
+ exports.default = void 0;
8
+ var _queryString = _interopRequireDefault(require("../http/queryString"));
14
9
  var validators = _interopRequireWildcard(require("../validators"));
15
-
10
+ var _operators = require("rxjs/operators");
11
+ var _rxjs = require("rxjs");
16
12
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
-
18
13
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
-
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
15
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
21
-
22
16
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
23
-
24
17
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
25
-
26
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
27
-
28
- function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
29
-
18
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
19
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
30
20
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
31
-
32
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
33
-
34
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
35
-
36
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
37
-
38
- var AssetsClient = /*#__PURE__*/function () {
39
- function AssetsClient(client) {
40
- _classCallCheck(this, AssetsClient);
41
-
42
- this.client = client;
21
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
22
+ function AssetsClient(client) {
23
+ this.client = client;
24
+ }
25
+ function optionsFromFile(opts, file) {
26
+ if (typeof window === 'undefined' || !(file instanceof window.File)) {
27
+ return opts;
43
28
  }
29
+ return _extends({
30
+ filename: opts.preserveFilename === false ? undefined : file.name,
31
+ contentType: file.type
32
+ }, opts);
33
+ }
34
+ _extends(AssetsClient.prototype, {
44
35
  /**
45
36
  * Upload an asset
46
37
  *
@@ -66,120 +57,89 @@ var AssetsClient = /*#__PURE__*/function () {
66
57
  * Optional
67
58
  * @return {Promise} Resolves with the created asset document
68
59
  */
69
-
70
-
71
- _createClass(AssetsClient, [{
72
- key: "upload",
73
- value: function upload(assetType, body) {
74
- var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
75
- validators.validateAssetType(assetType); // If an empty array is given, explicitly set `none` to override API defaults
76
-
77
- var meta = opts.extract || undefined;
78
-
79
- if (meta && !meta.length) {
80
- meta = ['none'];
81
- }
82
-
83
- var dataset = validators.hasDataset(this.client.clientConfig);
84
- var assetEndpoint = assetType === 'image' ? 'images' : 'files';
85
- var options = optionsFromFile(opts, body);
86
- var tag = options.tag,
87
- label = options.label,
88
- title = options.title,
89
- description = options.description,
90
- creditLine = options.creditLine,
91
- filename = options.filename,
92
- source = options.source;
93
- var query = {
94
- label: label,
95
- title: title,
96
- description: description,
97
- filename: filename,
98
- meta: meta,
99
- creditLine: creditLine
100
- };
101
-
102
- if (source) {
103
- query.sourceId = source.id;
104
- query.sourceName = source.name;
105
- query.sourceUrl = source.url;
106
- }
107
-
108
- var observable = this.client._requestObservable({
109
- tag: tag,
110
- method: 'POST',
111
- timeout: options.timeout || 0,
112
- uri: "/assets/".concat(assetEndpoint, "/").concat(dataset),
113
- headers: options.contentType ? {
114
- 'Content-Type': options.contentType
115
- } : {},
116
- query: query,
117
- body: body
118
- });
119
-
120
- return this.client.isPromiseAPI() ? observable.pipe((0, _observable.filter)(function (event) {
121
- return event.type === 'response';
122
- }), (0, _observable.map)(function (event) {
123
- return event.body.document;
124
- })).toPromise() : observable;
60
+ upload: function upload(assetType, body) {
61
+ var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
62
+ validators.validateAssetType(assetType);
63
+
64
+ // If an empty array is given, explicitly set `none` to override API defaults
65
+ var meta = opts.extract || undefined;
66
+ if (meta && !meta.length) {
67
+ meta = ['none'];
125
68
  }
126
- }, {
127
- key: "delete",
128
- value: function _delete(type, id) {
129
- // eslint-disable-next-line no-console
130
- console.warn('client.assets.delete() is deprecated, please use client.delete(<document-id>)');
131
- var docId = id || '';
132
-
133
- if (!/^(image|file)-/.test(docId)) {
134
- docId = "".concat(type, "-").concat(docId);
135
- } else if (type._id) {
136
- // We could be passing an entire asset document instead of an ID
137
- docId = type._id;
138
- }
139
-
140
- validators.hasDataset(this.client.clientConfig);
141
- return this.client.delete(docId);
69
+ var dataset = validators.hasDataset(this.client.clientConfig);
70
+ var assetEndpoint = assetType === 'image' ? 'images' : 'files';
71
+ var options = optionsFromFile(opts, body);
72
+ var tag = options.tag,
73
+ label = options.label,
74
+ title = options.title,
75
+ description = options.description,
76
+ creditLine = options.creditLine,
77
+ filename = options.filename,
78
+ source = options.source;
79
+ var query = {
80
+ label: label,
81
+ title: title,
82
+ description: description,
83
+ filename: filename,
84
+ meta: meta,
85
+ creditLine: creditLine
86
+ };
87
+ if (source) {
88
+ query.sourceId = source.id;
89
+ query.sourceName = source.name;
90
+ query.sourceUrl = source.url;
142
91
  }
143
- }, {
144
- key: "getImageUrl",
145
- value: function getImageUrl(ref, query) {
146
- var id = ref._ref || ref;
147
-
148
- if (typeof id !== 'string') {
149
- throw new Error('getImageUrl() needs either an object with a _ref, or a string with an asset document ID');
150
- }
151
-
152
- if (!/^image-[A-Za-z0-9_]+-\d+x\d+-[a-z]{1,5}$/.test(id)) {
153
- throw new Error("Unsupported asset ID \"".concat(id, "\". URL generation only works for auto-generated IDs."));
154
- }
155
-
156
- var _id$split = id.split('-'),
157
- _id$split2 = _slicedToArray(_id$split, 4),
158
- assetId = _id$split2[1],
159
- size = _id$split2[2],
160
- format = _id$split2[3];
161
-
162
- validators.hasDataset(this.client.clientConfig);
163
- var _this$client$clientCo = this.client.clientConfig,
164
- projectId = _this$client$clientCo.projectId,
165
- dataset = _this$client$clientCo.dataset;
166
- var qs = query ? (0, _queryString.queryString)(query) : '';
167
- return "https://cdn.sanity.io/images/".concat(projectId, "/").concat(dataset, "/").concat(assetId, "-").concat(size, ".").concat(format).concat(qs);
92
+ var observable = this.client._requestObservable({
93
+ tag: tag,
94
+ method: 'POST',
95
+ timeout: options.timeout || 0,
96
+ uri: "/assets/".concat(assetEndpoint, "/").concat(dataset),
97
+ headers: options.contentType ? {
98
+ 'Content-Type': options.contentType
99
+ } : {},
100
+ query: query,
101
+ body: body
102
+ });
103
+ return this.client.isPromiseAPI() ? (0, _rxjs.lastValueFrom)(observable.pipe((0, _operators.filter)(function (event) {
104
+ return event.type === 'response';
105
+ }), (0, _operators.map)(function (event) {
106
+ return event.body.document;
107
+ }))) : observable;
108
+ },
109
+ delete: function _delete(type, id) {
110
+ // eslint-disable-next-line no-console
111
+ console.warn('client.assets.delete() is deprecated, please use client.delete(<document-id>)');
112
+ var docId = id || '';
113
+ if (!/^(image|file)-/.test(docId)) {
114
+ docId = "".concat(type, "-").concat(docId);
115
+ } else if (type._id) {
116
+ // We could be passing an entire asset document instead of an ID
117
+ docId = type._id;
168
118
  }
169
- }]);
170
-
171
- return AssetsClient;
172
- }();
173
-
174
- exports.AssetsClient = AssetsClient;
175
-
176
- function optionsFromFile(opts, file) {
177
- if (typeof window === 'undefined' || !(file instanceof window.File)) {
178
- return opts;
119
+ validators.hasDataset(this.client.clientConfig);
120
+ return this.client.delete(docId);
121
+ },
122
+ getImageUrl: function getImageUrl(ref, query) {
123
+ var id = ref._ref || ref;
124
+ if (typeof id !== 'string') {
125
+ throw new Error('getImageUrl() needs either an object with a _ref, or a string with an asset document ID');
126
+ }
127
+ if (!/^image-[A-Za-z0-9_]+-\d+x\d+-[a-z]{1,5}$/.test(id)) {
128
+ throw new Error("Unsupported asset ID \"".concat(id, "\". URL generation only works for auto-generated IDs."));
129
+ }
130
+ var _id$split = id.split('-'),
131
+ _id$split2 = _slicedToArray(_id$split, 4),
132
+ assetId = _id$split2[1],
133
+ size = _id$split2[2],
134
+ format = _id$split2[3];
135
+ validators.hasDataset(this.client.clientConfig);
136
+ var _this$client$clientCo = this.client.clientConfig,
137
+ projectId = _this$client$clientCo.projectId,
138
+ dataset = _this$client$clientCo.dataset;
139
+ var qs = query ? (0, _queryString.default)(query) : '';
140
+ return "https://cdn.sanity.io/images/".concat(projectId, "/").concat(dataset, "/").concat(assetId, "-").concat(size, ".").concat(format).concat(qs);
179
141
  }
180
-
181
- return Object.assign({
182
- filename: opts.preserveFilename === false ? undefined : file.name,
183
- contentType: file.type
184
- }, opts);
185
- }
142
+ });
143
+ var _default = AssetsClient;
144
+ exports.default = _default;
145
+ module.exports = exports.default;
@@ -3,39 +3,24 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.AuthClient = void 0;
7
-
8
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
9
-
10
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
11
-
12
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
13
-
14
- var AuthClient = /*#__PURE__*/function () {
15
- function AuthClient(client) {
16
- _classCallCheck(this, AuthClient);
17
-
18
- this.client = client;
6
+ exports.default = void 0;
7
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
8
+ function AuthClient(client) {
9
+ this.client = client;
10
+ }
11
+ _extends(AuthClient.prototype, {
12
+ getLoginProviders: function getLoginProviders() {
13
+ return this.client.request({
14
+ uri: '/auth/providers'
15
+ });
16
+ },
17
+ logout: function logout() {
18
+ return this.client.request({
19
+ uri: '/auth/logout',
20
+ method: 'POST'
21
+ });
19
22
  }
20
-
21
- _createClass(AuthClient, [{
22
- key: "getLoginProviders",
23
- value: function getLoginProviders() {
24
- return this.client.request({
25
- uri: '/auth/providers'
26
- });
27
- }
28
- }, {
29
- key: "logout",
30
- value: function logout() {
31
- return this.client.request({
32
- uri: '/auth/logout',
33
- method: 'POST'
34
- });
35
- }
36
- }]);
37
-
38
- return AuthClient;
39
- }();
40
-
41
- exports.AuthClient = AuthClient;
23
+ });
24
+ var _default = AuthClient;
25
+ exports.default = _default;
26
+ module.exports = exports.default;
package/lib/config.js CHANGED
@@ -1,23 +1,17 @@
1
1
  "use strict";
2
2
 
3
3
  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
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
- exports.initConfig = exports.defaultConfig = void 0;
9
- exports.validateApiVersion = validateApiVersion;
10
-
11
- var _generateHelpUrl = require("@sanity/generate-help-url");
12
-
7
+ exports.validateApiVersion = exports.initConfig = exports.defaultConfig = void 0;
8
+ var _generateHelpUrl = _interopRequireDefault(require("./generateHelpUrl"));
13
9
  var validate = _interopRequireWildcard(require("./validators"));
14
-
15
10
  var warnings = _interopRequireWildcard(require("./warnings"));
16
-
17
11
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
18
-
19
12
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
20
-
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
21
15
  var defaultCdnHost = 'apicdn.sanity.io';
22
16
  var defaultConfig = {
23
17
  apiHost: 'https://api.sanity.io',
@@ -27,53 +21,53 @@ var defaultConfig = {
27
21
  };
28
22
  exports.defaultConfig = defaultConfig;
29
23
  var LOCALHOSTS = ['localhost', '127.0.0.1', '0.0.0.0'];
30
-
31
24
  var isLocal = function isLocal(host) {
32
25
  return LOCALHOSTS.indexOf(host) !== -1;
33
- }; // eslint-disable-next-line complexity
34
-
26
+ };
27
+ var validateApiVersion = function validateApiVersion(apiVersion) {
28
+ if (apiVersion === '1' || apiVersion === 'X') {
29
+ return;
30
+ }
31
+ var apiDate = new Date(apiVersion);
32
+ var apiVersionValid = /^\d{4}-\d{2}-\d{2}$/.test(apiVersion) && apiDate instanceof Date && apiDate.getTime() > 0;
33
+ if (!apiVersionValid) {
34
+ throw new Error('Invalid API version string, expected `1` or date in format `YYYY-MM-DD`');
35
+ }
36
+ };
35
37
 
38
+ // eslint-disable-next-line complexity
39
+ exports.validateApiVersion = validateApiVersion;
36
40
  var initConfig = function initConfig(config, prevConfig) {
37
- var specifiedConfig = Object.assign({}, prevConfig, config);
38
-
41
+ var specifiedConfig = _extends({}, prevConfig, config);
39
42
  if (!specifiedConfig.apiVersion) {
40
43
  warnings.printNoApiVersionSpecifiedWarning();
41
44
  }
42
-
43
- var newConfig = Object.assign({}, defaultConfig, specifiedConfig);
45
+ var newConfig = _extends({}, defaultConfig, specifiedConfig);
44
46
  var projectBased = newConfig.useProjectHostname;
45
-
46
47
  if (typeof Promise === 'undefined') {
47
- var helpUrl = (0, _generateHelpUrl.generateHelpUrl)('js-client-promise-polyfill');
48
+ var helpUrl = (0, _generateHelpUrl.default)('js-client-promise-polyfill');
48
49
  throw new Error("No native Promise-implementation found, polyfill needed - see ".concat(helpUrl));
49
50
  }
50
-
51
51
  if (projectBased && !newConfig.projectId) {
52
52
  throw new Error('Configuration must contain `projectId`');
53
53
  }
54
-
55
54
  var isBrowser = typeof window !== 'undefined' && window.location && window.location.hostname;
56
55
  var isLocalhost = isBrowser && isLocal(window.location.hostname);
57
-
58
56
  if (isBrowser && isLocalhost && newConfig.token && newConfig.ignoreBrowserTokenWarning !== true) {
59
57
  warnings.printBrowserTokenWarning();
60
58
  } else if (typeof newConfig.useCdn === 'undefined') {
61
59
  warnings.printCdnWarning();
62
60
  }
63
-
64
61
  if (projectBased) {
65
62
  validate.projectId(newConfig.projectId);
66
63
  }
67
-
68
64
  if (newConfig.dataset) {
69
65
  validate.dataset(newConfig.dataset);
70
66
  }
71
-
72
67
  if ('requestTagPrefix' in newConfig) {
73
68
  // Allow setting and unsetting request tag prefix
74
69
  newConfig.requestTagPrefix = newConfig.requestTagPrefix ? validate.requestTag(newConfig.requestTagPrefix).replace(/\.+$/, '') : undefined;
75
70
  }
76
-
77
71
  newConfig.apiVersion = "".concat(newConfig.apiVersion).replace(/^v/, '');
78
72
  newConfig.isDefaultApi = newConfig.apiHost === defaultConfig.apiHost;
79
73
  newConfig.useCdn = Boolean(newConfig.useCdn) && !newConfig.withCredentials;
@@ -82,7 +76,6 @@ var initConfig = function initConfig(config, prevConfig) {
82
76
  var protocol = hostParts[0];
83
77
  var host = hostParts[1];
84
78
  var cdnHost = newConfig.isDefaultApi ? defaultCdnHost : host;
85
-
86
79
  if (newConfig.useProjectHostname) {
87
80
  newConfig.url = "".concat(protocol, "://").concat(newConfig.projectId, ".").concat(host, "/v").concat(newConfig.apiVersion);
88
81
  newConfig.cdnUrl = "".concat(protocol, "://").concat(newConfig.projectId, ".").concat(cdnHost, "/v").concat(newConfig.apiVersion);
@@ -90,21 +83,6 @@ var initConfig = function initConfig(config, prevConfig) {
90
83
  newConfig.url = "".concat(newConfig.apiHost, "/v").concat(newConfig.apiVersion);
91
84
  newConfig.cdnUrl = newConfig.url;
92
85
  }
93
-
94
86
  return newConfig;
95
87
  };
96
-
97
- exports.initConfig = initConfig;
98
-
99
- function validateApiVersion(apiVersion) {
100
- if (apiVersion === '1' || apiVersion === 'X') {
101
- return;
102
- }
103
-
104
- var apiDate = new Date(apiVersion);
105
- var apiVersionValid = /^\d{4}-\d{2}-\d{2}$/.test(apiVersion) && apiDate instanceof Date && apiDate.getTime() > 0;
106
-
107
- if (!apiVersionValid) {
108
- throw new Error('Invalid API version string, expected `1` or date in format `YYYY-MM-DD`');
109
- }
110
- }
88
+ exports.initConfig = initConfig;