webflow-api 0.8.1 → 1.0.1

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/Webflow.js CHANGED
@@ -1,482 +1,344 @@
1
1
  "use strict";
2
2
 
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
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
8
- exports["default"] = void 0;
9
-
10
- var _isomorphicFetch = _interopRequireDefault(require("isomorphic-fetch"));
11
-
12
- var _qs = _interopRequireDefault(require("qs"));
13
-
14
- var _utils = require("./utils");
15
-
6
+ exports.WebflowArgumentError = exports.Webflow = void 0;
7
+ Object.defineProperty(exports, "WebflowRequestError", {
8
+ enumerable: true,
9
+ get: function () {
10
+ return _WebflowClient.WebflowRequestError;
11
+ }
12
+ });
13
+ exports.default = void 0;
14
+ var _WebflowClient = require("./WebflowClient");
16
15
  var _ResponseWrapper = _interopRequireDefault(require("./ResponseWrapper"));
17
-
18
- var _WebflowError = _interopRequireWildcard(require("./WebflowError"));
19
-
20
- var _excluded = ["collectionId"],
21
- _excluded2 = ["collectionId", "itemId"],
22
- _excluded3 = ["collectionId", "itemId"],
23
- _excluded4 = ["collectionId", "itemIds"],
24
- _excluded5 = ["collectionId", "itemIds"],
25
- _excluded6 = ["siteId", "userId"],
26
- _excluded7 = ["siteId"];
27
-
28
- 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); }
29
-
30
- 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; }
31
-
32
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
33
-
34
- function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
35
-
36
- function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
37
-
38
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
39
-
40
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
41
-
42
- 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; }
43
-
44
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
45
-
46
- 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); } }
47
-
48
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
49
-
50
- var DEFAULT_ENDPOINT = "https://api.webflow.com";
51
-
52
- var buildMeta = function buildMeta(res) {
53
- if (!res || !res.headers) {
54
- return {};
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+ class WebflowArgumentError extends Error {
18
+ constructor(name) {
19
+ super(`Argument '${name}' is required but was not present`);
20
+ }
21
+ }
22
+ exports.WebflowArgumentError = WebflowArgumentError;
23
+ class Webflow {
24
+ constructor(options = {}) {
25
+ this.client = new _WebflowClient.WebflowClient(options);
26
+ this.responseWrapper = new _ResponseWrapper.default(this);
27
+ }
28
+ set token(value) {
29
+ this.client.token = value;
30
+ }
31
+ get token() {
32
+ return this.client.token;
33
+ }
34
+ get(path, query = {}) {
35
+ return this.client.get(path, query);
36
+ }
37
+ post(path, data, query = {}) {
38
+ return this.client.post(path, data, query);
39
+ }
40
+ put(path, data, query = {}) {
41
+ return this.client.put(path, data, query);
42
+ }
43
+ patch(path, data, query = {}) {
44
+ return this.client.patch(path, data, query);
45
+ }
46
+ delete(path, data, query = {}) {
47
+ return this.client.delete(path, data, query);
55
48
  }
56
49
 
57
- return {
58
- rateLimit: {
59
- limit: parseInt(res.headers.get("x-ratelimit-limit"), 10),
60
- remaining: parseInt(res.headers.get("x-ratelimit-remaining"), 10)
61
- }
62
- };
63
- };
64
-
65
- var responseHandler = function responseHandler(res) {
66
- return res.json()["catch"](function (err) {
67
- return (// Catch unexpected server errors where json isn't sent and rewrite
68
- // with proper class (WebflowError)
69
- Promise.reject(new _WebflowError["default"](err))
70
- );
71
- }).then(function (body) {
72
- if (res.status >= 400) {
73
- var errOpts = {
74
- code: body.code,
75
- msg: body.msg,
76
- _meta: buildMeta(res)
77
- };
78
-
79
- if (body.problems && body.problems.length > 0) {
80
- errOpts.problems = body.problems;
81
- }
82
-
83
- var errMsg = body && body.err ? body.err : "Unknown error occured";
84
- var err = new _WebflowError["default"](errMsg);
85
- return Promise.reject(Object.assign(err, errOpts));
86
- }
87
-
88
- body._meta = buildMeta(res); // eslint-disable-line no-param-reassign
89
-
90
- return body;
91
- });
92
- };
93
-
94
- var Webflow = /*#__PURE__*/function () {
95
- function Webflow() {
96
- var _this = this;
50
+ // Meta
51
+ info() {
52
+ return this.get("/info");
53
+ }
54
+ installer() {
55
+ return this.get("/user");
56
+ }
97
57
 
98
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
99
- _ref$endpoint = _ref.endpoint,
100
- endpoint = _ref$endpoint === void 0 ? DEFAULT_ENDPOINT : _ref$endpoint,
101
- token = _ref.token,
102
- _ref$version = _ref.version,
103
- version = _ref$version === void 0 ? "1.0.0" : _ref$version;
58
+ // Sites
59
+ async sites(query = {}) {
60
+ const sites = await this.get("/sites", query);
61
+ return sites.map(site => this.responseWrapper.site(site));
62
+ }
63
+ async site({
64
+ siteId
65
+ }, query = {}) {
66
+ if (!siteId) throw new WebflowArgumentError("siteId");
67
+ const site = await this.get(`/sites/${siteId}`, query);
68
+ return this.responseWrapper.site(site);
69
+ }
70
+ publishSite({
71
+ siteId,
72
+ domains
73
+ }) {
74
+ if (!siteId) throw new WebflowArgumentError("siteId");
75
+ if (!domains) throw new WebflowArgumentError("domains");
76
+ return this.post(`/sites/${siteId}/publish`, {
77
+ domains
78
+ });
79
+ }
80
+ async domains({
81
+ siteId
82
+ }) {
83
+ if (!siteId) throw new WebflowArgumentError("siteId");
84
+ const domains = await this.client.get(`/sites/${siteId}/domains`);
85
+ return domains.map(domain => this.responseWrapper.domain(domain, siteId));
86
+ }
104
87
 
105
- _classCallCheck(this, Webflow);
88
+ // Collections
89
+ async collections({
90
+ siteId
91
+ }, query = {}) {
92
+ if (!siteId) throw new WebflowArgumentError("siteId");
93
+ const collections = await this.get(`/sites/${siteId}/collections`, query);
94
+ return collections.map(collection => this.responseWrapper.collection(collection));
95
+ }
96
+ async collection({
97
+ collectionId
98
+ }, query = {}) {
99
+ if (!collectionId) throw new WebflowArgumentError("collectionId");
100
+ const uri = `/collections/${collectionId}`;
101
+ const collection = await this.client.get(uri, query);
102
+ return this.responseWrapper.collection(collection);
103
+ }
106
104
 
107
- if (!token) throw (0, _WebflowError.buildRequiredArgError)("token");
108
- this.responseWrapper = new _ResponseWrapper["default"](this);
109
- this.endpoint = endpoint;
110
- this.token = token;
111
- this.headers = {
112
- Accept: "application/json",
113
- Authorization: "Bearer ".concat(token),
114
- "accept-version": version,
115
- "Content-Type": "application/json"
105
+ // Items
106
+ async items({
107
+ collectionId
108
+ }, query = {}) {
109
+ if (!collectionId) throw new WebflowArgumentError("collectionId");
110
+ const uri = `/collections/${collectionId}/items`;
111
+ const res = await this.client.get(uri, query);
112
+ return {
113
+ ...res,
114
+ items: res.items.map(item => this.responseWrapper.item(item, collectionId))
116
115
  };
116
+ }
117
+ async item({
118
+ collectionId,
119
+ itemId
120
+ }, query = {}) {
121
+ if (!collectionId) throw new WebflowArgumentError("collectionId");
122
+ if (!itemId) throw new WebflowArgumentError("itemId");
123
+ const uri = `/collections/${collectionId}/items/${itemId}`;
124
+ const {
125
+ items
126
+ } = await this.client.get(uri, query);
127
+ return this.responseWrapper.item(items[0], collectionId);
128
+ }
129
+ async createItem({
130
+ collectionId,
131
+ ...data
132
+ }, query = {}) {
133
+ if (!collectionId) throw new WebflowArgumentError("collectionId");
134
+ const uri = `/collections/${collectionId}/items`;
135
+ const item = await this.post(uri, data, query);
136
+ return this.responseWrapper.item(item, collectionId);
137
+ }
138
+ updateItem({
139
+ collectionId,
140
+ itemId,
141
+ ...data
142
+ }, query = {}) {
143
+ if (!collectionId) throw new WebflowArgumentError("collectionId");
144
+ if (!itemId) throw new WebflowArgumentError("itemId");
145
+ const uri = `/collections/${collectionId}/items/${itemId}`;
146
+ return this.put(uri, data, query);
147
+ }
148
+ removeItem({
149
+ collectionId,
150
+ itemId
151
+ }, query = {}) {
152
+ if (!collectionId) throw new WebflowArgumentError("collectionId");
153
+ if (!itemId) throw new WebflowArgumentError("itemId");
154
+ const uri = `/collections/${collectionId}/items/${itemId}`;
155
+ return this.delete(uri, null, query);
156
+ }
157
+ patchItem({
158
+ collectionId,
159
+ itemId,
160
+ ...data
161
+ }, query = {}) {
162
+ if (!collectionId) throw new WebflowArgumentError("collectionId");
163
+ if (!itemId) throw new WebflowArgumentError("itemId");
164
+ const uri = `/collections/${collectionId}/items/${itemId}`;
165
+ return this.patch(uri, data, query);
166
+ }
167
+ deleteItems({
168
+ collectionId,
169
+ itemIds,
170
+ ...data
171
+ }, query = {}) {
172
+ if (!collectionId) throw new WebflowArgumentError("collectionId");
173
+ if (!itemIds) throw new WebflowArgumentError("itemIds");
174
+ const uri = `/collections/${collectionId}/items`;
175
+ return this.delete(uri, {
176
+ ...data,
177
+ itemIds
178
+ }, query);
179
+ }
180
+ publishItems({
181
+ collectionId,
182
+ itemIds,
183
+ ...data
184
+ }, query = {}) {
185
+ if (!collectionId) throw new WebflowArgumentError("collectionId");
186
+ if (!itemIds) throw new WebflowArgumentError("itemIds");
187
+ const uri = `/collections/${collectionId}/items/publish`;
188
+ return this.put(uri, {
189
+ ...data,
190
+ itemIds
191
+ }, query);
192
+ }
117
193
 
118
- this.authenticatedFetch = function (method, path, data, query) {
119
- var queryString = query && !(0, _utils.isObjectEmpty)(query) ? "?".concat(_qs["default"].stringify(query)) : "";
120
- var uri = "".concat(_this.endpoint).concat(path).concat(queryString);
121
- var opts = {
122
- method: method,
123
- headers: _this.headers,
124
- mode: "cors"
125
- };
126
-
127
- if (data) {
128
- opts.body = JSON.stringify(data);
129
- }
130
-
131
- return (0, _isomorphicFetch["default"])(uri, opts).then(responseHandler);
194
+ // Users
195
+ async users({
196
+ siteId
197
+ }, query = {}) {
198
+ if (!siteId) throw new WebflowArgumentError("siteId");
199
+ const res = await this.get(`/sites/${siteId}/users`, query);
200
+ return {
201
+ ...res,
202
+ users: res.users.map(user => this.responseWrapper.user(user, siteId))
132
203
  };
133
- } // Generic HTTP request handlers
134
-
135
-
136
- _createClass(Webflow, [{
137
- key: "get",
138
- value: function get(path) {
139
- var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
140
- return this.authenticatedFetch("GET", path, null, query);
141
- }
142
- }, {
143
- key: "post",
144
- value: function post(path, data) {
145
- var query = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
146
- return this.authenticatedFetch("POST", path, data, query);
147
- }
148
- }, {
149
- key: "put",
150
- value: function put(path, data) {
151
- var query = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
152
- return this.authenticatedFetch("PUT", path, data, query);
153
- }
154
- }, {
155
- key: "patch",
156
- value: function patch(path, data) {
157
- var query = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
158
- return this.authenticatedFetch("PATCH", path, data, query);
159
- }
160
- }, {
161
- key: "delete",
162
- value: function _delete(path, data) {
163
- var query = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
164
- return this.authenticatedFetch("DELETE", path, data, query);
165
- } // Meta
166
-
167
- }, {
168
- key: "info",
169
- value: function info() {
170
- var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
171
- return this.get("/info", query);
172
- } // Sites
173
-
174
- }, {
175
- key: "sites",
176
- value: function sites() {
177
- var _this2 = this;
178
-
179
- var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
180
- return this.get("/sites", query).then(function (sites) {
181
- return sites.map(function (site) {
182
- return _this2.responseWrapper.site(site);
183
- });
184
- });
185
- }
186
- }, {
187
- key: "site",
188
- value: function site(_ref2) {
189
- var _this3 = this;
190
-
191
- var siteId = _ref2.siteId;
192
- var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
193
- if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("siteId"));
194
- return this.get("/sites/".concat(siteId), query).then(function (site) {
195
- return _this3.responseWrapper.site(site);
196
- });
197
- }
198
- }, {
199
- key: "publishSite",
200
- value: function publishSite(_ref3) {
201
- var siteId = _ref3.siteId,
202
- domains = _ref3.domains;
203
- if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("siteId"));
204
- if (!domains) return Promise.reject((0, _WebflowError.buildRequiredArgError)("domains"));
205
- return this.post("/sites/".concat(siteId, "/publish"), {
206
- domains: domains
207
- });
208
- } // Domains
209
-
210
- }, {
211
- key: "domains",
212
- value: function domains(_ref4) {
213
- var _this4 = this;
214
-
215
- var siteId = _ref4.siteId;
216
- if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("siteId"));
217
- return this.get("/sites/".concat(siteId, "/domains")).then(function (domains) {
218
- return domains.map(function (domain) {
219
- return _this4.responseWrapper.domain(domain, siteId);
220
- });
221
- });
222
- } // Collections
223
-
224
- }, {
225
- key: "collections",
226
- value: function collections(_ref5) {
227
- var _this5 = this;
228
-
229
- var siteId = _ref5.siteId;
230
- var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
231
- if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("siteId"));
232
- return this.get("/sites/".concat(siteId, "/collections"), query).then(function (collections) {
233
- return collections.map(function (collection) {
234
- return _this5.responseWrapper.collection(collection);
235
- });
236
- });
237
- }
238
- }, {
239
- key: "collection",
240
- value: function collection(_ref6) {
241
- var _this6 = this;
242
-
243
- var collectionId = _ref6.collectionId;
244
- var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
245
- if (!collectionId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("collectionId"));
246
- return this.get("/collections/".concat(collectionId), query).then(function (collection) {
247
- return _this6.responseWrapper.collection(collection);
248
- });
249
- } // Items
250
-
251
- }, {
252
- key: "items",
253
- value: function items(_ref7) {
254
- var _this7 = this;
255
-
256
- var collectionId = _ref7.collectionId;
257
- var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
258
- if (!collectionId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("collectionId"));
259
- return this.get("/collections/".concat(collectionId, "/items"), query).then(function (res) {
260
- return _objectSpread(_objectSpread({}, res), {}, {
261
- items: res.items.map(function (item) {
262
- return _this7.responseWrapper.item(item, collectionId);
263
- })
264
- });
265
- });
266
- }
267
- }, {
268
- key: "item",
269
- value: function item(_ref8) {
270
- var _this8 = this;
271
-
272
- var collectionId = _ref8.collectionId,
273
- itemId = _ref8.itemId;
274
- var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
275
- if (!collectionId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("collectionId"));
276
- if (!itemId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("itemId"));
277
- return this.get("/collections/".concat(collectionId, "/items/").concat(itemId), query).then(function (res) {
278
- return _this8.responseWrapper.item(res.items[0], collectionId);
279
- });
280
- }
281
- }, {
282
- key: "createItem",
283
- value: function createItem(_ref9) {
284
- var _this9 = this;
285
-
286
- var collectionId = _ref9.collectionId,
287
- data = _objectWithoutProperties(_ref9, _excluded);
288
-
289
- var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
290
- if (!collectionId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("collectionId"));
291
- return this.post("/collections/".concat(collectionId, "/items"), data, query).then(function (item) {
292
- return _this9.responseWrapper.item(item, collectionId);
293
- });
294
- }
295
- }, {
296
- key: "updateItem",
297
- value: function updateItem(_ref10) {
298
- var collectionId = _ref10.collectionId,
299
- itemId = _ref10.itemId,
300
- data = _objectWithoutProperties(_ref10, _excluded2);
301
-
302
- var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
303
- if (!collectionId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("collectionId"));
304
- if (!itemId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("itemId"));
305
- return this.put("/collections/".concat(collectionId, "/items/").concat(itemId), data, query);
306
- }
307
- }, {
308
- key: "removeItem",
309
- value: function removeItem(_ref11) {
310
- var collectionId = _ref11.collectionId,
311
- itemId = _ref11.itemId;
312
- var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
313
- if (!collectionId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("collectionId"));
314
- if (!itemId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("itemId"));
315
- return this["delete"]("/collections/".concat(collectionId, "/items/").concat(itemId), null, query);
316
- }
317
- }, {
318
- key: "patchItem",
319
- value: function patchItem(_ref12) {
320
- var collectionId = _ref12.collectionId,
321
- itemId = _ref12.itemId,
322
- data = _objectWithoutProperties(_ref12, _excluded3);
323
-
324
- var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
325
- if (!collectionId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("collectionId"));
326
- if (!itemId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("itemId"));
327
- return this.patch("/collections/".concat(collectionId, "/items/").concat(itemId), data, query);
328
- }
329
- }, {
330
- key: "deleteItems",
331
- value: function deleteItems(_ref13) {
332
- var collectionId = _ref13.collectionId,
333
- itemIds = _ref13.itemIds,
334
- data = _objectWithoutProperties(_ref13, _excluded4);
335
-
336
- var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
337
- if (!collectionId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("collectionId"));
338
- if (!itemIds) return Promise.reject((0, _WebflowError.buildRequiredArgError)("itemIds"));
339
- return this["delete"]("/collections/".concat(collectionId, "/items"), _objectSpread(_objectSpread({}, data), {}, {
340
- itemIds: itemIds
341
- }), query);
342
- }
343
- }, {
344
- key: "publishItems",
345
- value: function publishItems(_ref14) {
346
- var collectionId = _ref14.collectionId,
347
- itemIds = _ref14.itemIds,
348
- data = _objectWithoutProperties(_ref14, _excluded5);
349
-
350
- var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
351
- if (!collectionId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("collectionId"));
352
- if (!itemIds) return Promise.reject((0, _WebflowError.buildRequiredArgError)("itemIds"));
353
- return this.put("/collections/".concat(collectionId, "/items/publish"), _objectSpread(_objectSpread({}, data), {}, {
354
- itemIds: itemIds
355
- }), query);
356
- } // Users
357
-
358
- }, {
359
- key: "users",
360
- value: function users(_ref15) {
361
- var _this10 = this;
362
-
363
- var siteId = _ref15.siteId;
364
- var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
365
- if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("siteId"));
366
- return this.get("/sites/".concat(siteId, "/users"), query).then(function (res) {
367
- return res.users.map(function (user) {
368
- return _this10.responseWrapper.user(user);
369
- });
370
- });
371
- }
372
- }, {
373
- key: "user",
374
- value: function user(_ref16) {
375
- var _this11 = this;
376
-
377
- var siteId = _ref16.siteId,
378
- userId = _ref16.userId;
379
- var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
380
- if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("siteId"));
381
- if (!userId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("userId"));
382
- return this.get("/sites/".concat(siteId, "/users/").concat(userId), query).then(function (user) {
383
- return _this11.responseWrapper.user(user, siteId);
384
- });
385
- }
386
- }, {
387
- key: "updateUser",
388
- value: function updateUser(_ref17) {
389
- var siteId = _ref17.siteId,
390
- userId = _ref17.userId,
391
- data = _objectWithoutProperties(_ref17, _excluded6);
392
-
393
- var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
394
- if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("siteId"));
395
- if (!userId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("userId"));
396
- return this.patch("/sites/".concat(siteId, "/users/").concat(userId), data, query);
397
- }
398
- }, {
399
- key: "inviteUser",
400
- value: function inviteUser(_ref18) {
401
- var _this12 = this;
402
-
403
- var siteId = _ref18.siteId,
404
- email = _ref18.email;
405
- var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
406
- if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("siteId"));
407
- if (!email) return Promise.reject((0, _WebflowError.buildRequiredArgError)("email"));
408
- return this.post("/sites/".concat(siteId, "/users/invite"), {
409
- email: email
410
- }, query).then(function (user) {
411
- return _this12.responseWrapper.user(user, siteId);
412
- });
413
- }
414
- }, {
415
- key: "removeUser",
416
- value: function removeUser(_ref19) {
417
- var siteId = _ref19.siteId,
418
- userId = _ref19.userId;
419
- var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
420
- if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("siteId"));
421
- if (!userId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("userId"));
422
- return this["delete"]("/sites/".concat(siteId, "/users/").concat(userId), null, query);
423
- } // Webhooks
424
-
425
- }, {
426
- key: "webhooks",
427
- value: function webhooks(_ref20) {
428
- var _this13 = this;
429
-
430
- var siteId = _ref20.siteId;
431
- var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
432
- if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("siteId"));
433
- return this.get("/sites/".concat(siteId, "/webhooks"), query).then(function (webhooks) {
434
- return webhooks.map(function (webhook) {
435
- return _this13.responseWrapper.webhook(webhook, siteId);
436
- });
437
- });
438
- }
439
- }, {
440
- key: "webhook",
441
- value: function webhook(_ref21) {
442
- var _this14 = this;
443
-
444
- var siteId = _ref21.siteId,
445
- webhookId = _ref21.webhookId;
446
- var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
447
- if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("siteId"));
448
- if (!webhookId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("webhookId"));
449
- return this.get("/sites/".concat(siteId, "/webhooks/").concat(webhookId), query).then(function (webhook) {
450
- return _this14.responseWrapper.webhook(webhook, siteId);
451
- });
452
- }
453
- }, {
454
- key: "createWebhook",
455
- value: function createWebhook(_ref22) {
456
- var _this15 = this;
457
-
458
- var siteId = _ref22.siteId,
459
- data = _objectWithoutProperties(_ref22, _excluded7);
460
-
461
- var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
462
- if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("siteId"));
463
- return this.post("/sites/".concat(siteId, "/webhooks"), data, query).then(function (webhook) {
464
- return _this15.responseWrapper.webhook(webhook, siteId);
465
- });
466
- }
467
- }, {
468
- key: "removeWebhook",
469
- value: function removeWebhook(_ref23) {
470
- var siteId = _ref23.siteId,
471
- webhookId = _ref23.webhookId;
472
- var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
473
- if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("siteId"));
474
- if (!webhookId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("webhookId"));
475
- return this["delete"]("/sites/".concat(siteId, "/webhooks/").concat(webhookId), null, query);
476
- }
477
- }]);
204
+ }
205
+ async user({
206
+ siteId,
207
+ userId
208
+ }, query = {}) {
209
+ if (!siteId) throw new WebflowArgumentError("siteId");
210
+ if (!userId) throw new WebflowArgumentError("userId");
211
+ const uri = `/sites/${siteId}/users/${userId}`;
212
+ const user = await this.get(uri, query);
213
+ return this.responseWrapper.user(user, siteId);
214
+ }
215
+ async updateUser({
216
+ siteId,
217
+ userId,
218
+ ...data
219
+ }, query = {}) {
220
+ if (!siteId) throw new WebflowArgumentError("siteId");
221
+ if (!userId) throw new WebflowArgumentError("userId");
222
+ const uri = `/sites/${siteId}/users/${userId}`;
223
+ const user = await this.patch(uri, data, query);
224
+ return this.responseWrapper.user(user, siteId);
225
+ }
226
+ async inviteUser({
227
+ siteId,
228
+ email
229
+ }, query = {}) {
230
+ if (!siteId) throw new WebflowArgumentError("siteId");
231
+ if (!email) throw new WebflowArgumentError("email");
232
+ const uri = `/sites/${siteId}/users/invite`;
233
+ const user = await this.post(uri, {
234
+ email
235
+ }, query);
236
+ return this.responseWrapper.user(user, siteId);
237
+ }
238
+ removeUser({
239
+ siteId,
240
+ userId
241
+ }, query = {}) {
242
+ if (!siteId) throw new WebflowArgumentError("siteId");
243
+ if (!userId) throw new WebflowArgumentError("userId");
244
+ return this.delete(`/sites/${siteId}/users/${userId}`, null, query);
245
+ }
478
246
 
479
- return Webflow;
480
- }();
247
+ // Webhooks
248
+ async webhooks({
249
+ siteId
250
+ }, query = {}) {
251
+ if (!siteId) throw new WebflowArgumentError("siteId");
252
+ const uri = `/sites/${siteId}/webhooks`;
253
+ const webhooks = await this.client.get(uri, query);
254
+ return webhooks.map(webhook => this.responseWrapper.webhook(webhook, siteId));
255
+ }
256
+ async webhook({
257
+ siteId,
258
+ webhookId
259
+ }, query = {}) {
260
+ if (!siteId) throw new WebflowArgumentError("siteId");
261
+ if (!webhookId) throw new WebflowArgumentError("webhookId");
262
+ const uri = `/sites/${siteId}/webhooks/${webhookId}`;
263
+ const webhook = await this.client.get(uri, query);
264
+ return this.responseWrapper.webhook(webhook, siteId);
265
+ }
266
+ async createWebhook({
267
+ siteId,
268
+ triggerType,
269
+ ...data
270
+ }, query = {}) {
271
+ if (!siteId) throw new WebflowArgumentError("siteId");
272
+ if (!triggerType) throw new WebflowArgumentError("triggerType");
273
+ const uri = `/sites/${siteId}/webhooks`;
274
+ const webhook = {
275
+ ...data,
276
+ triggerType
277
+ };
278
+ const createdWebhook = await this.client.post(uri, webhook, query);
279
+ return this.responseWrapper.webhook(createdWebhook, siteId);
280
+ }
281
+ removeWebhook({
282
+ siteId,
283
+ webhookId
284
+ }, query = {}) {
285
+ if (!siteId) throw new WebflowArgumentError("siteId");
286
+ if (!webhookId) throw new WebflowArgumentError("webhookId");
287
+ return this.delete(`/sites/${siteId}/webhooks/${webhookId}`, null, query);
288
+ }
481
289
 
482
- exports["default"] = Webflow;
290
+ // OAuth
291
+ authorizeUrl({
292
+ client_id,
293
+ redirect_uri,
294
+ state,
295
+ scope,
296
+ response_type = "code"
297
+ }) {
298
+ if (!client_id) throw new WebflowArgumentError("clientId");
299
+ const query = new URLSearchParams({
300
+ response_type,
301
+ client_id
302
+ });
303
+ if (redirect_uri) query.set("redirect_uri", redirect_uri);
304
+ if (state) query.set("state", state);
305
+ if (scope) query.set("scope", scope);
306
+ return `https://${this.host}/oauth/authorize?${query}`;
307
+ }
308
+ accessToken({
309
+ client_id,
310
+ client_secret,
311
+ code,
312
+ redirect_uri,
313
+ grant_type = "authorization_code"
314
+ }) {
315
+ if (!client_id) throw new WebflowArgumentError("client_id");
316
+ if (!client_secret) throw new WebflowArgumentError("client_secret");
317
+ if (!code) throw new WebflowArgumentError("code");
318
+ return this.post("/oauth/access_token", {
319
+ client_id,
320
+ client_secret,
321
+ code,
322
+ redirect_uri,
323
+ grant_type
324
+ });
325
+ }
326
+ revokeToken({
327
+ client_id,
328
+ client_secret,
329
+ access_token
330
+ }) {
331
+ if (!client_id) throw new WebflowArgumentError("client_id");
332
+ if (!client_secret) throw new WebflowArgumentError("client_secret");
333
+ if (!access_token) throw new WebflowArgumentError("access_token");
334
+ const uri = "/oauth/revoke_authorization";
335
+ return this.post(uri, {
336
+ client_id,
337
+ client_secret,
338
+ access_token
339
+ });
340
+ }
341
+ }
342
+ exports.Webflow = Webflow;
343
+ var _default = Webflow;
344
+ exports.default = _default;