webflow-api 0.7.1 → 0.8.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/ResponseWrapper.js +28 -0
- package/dist/Webflow.js +161 -65
- package/index.d.ts +40 -1
- package/package.json +3 -2
- package/src/ResponseWrapper.js +41 -7
- package/src/Webflow.js +171 -84
- package/src/WebflowError.js +2 -3
- package/src/utils.js +1 -1
- package/yarn.lock +6 -1
package/dist/ResponseWrapper.js
CHANGED
|
@@ -158,6 +158,34 @@ var ResponseWrapper = /*#__PURE__*/function () {
|
|
|
158
158
|
})
|
|
159
159
|
});
|
|
160
160
|
}
|
|
161
|
+
}, {
|
|
162
|
+
key: "user",
|
|
163
|
+
value: function user(_user, siteId) {
|
|
164
|
+
return _objectSpread(_objectSpread({}, _user), {}, {
|
|
165
|
+
update: function update(first) {
|
|
166
|
+
var _this$api9;
|
|
167
|
+
|
|
168
|
+
for (var _len9 = arguments.length, rest = new Array(_len9 > 1 ? _len9 - 1 : 0), _key9 = 1; _key9 < _len9; _key9++) {
|
|
169
|
+
rest[_key9 - 1] = arguments[_key9];
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return (_this$api9 = this.api).updateUser.apply(_this$api9, [_objectSpread(_objectSpread({}, first), {}, {
|
|
173
|
+
siteId: siteId
|
|
174
|
+
})].concat(rest));
|
|
175
|
+
},
|
|
176
|
+
remove: function remove(first) {
|
|
177
|
+
var _this$api10;
|
|
178
|
+
|
|
179
|
+
for (var _len10 = arguments.length, rest = new Array(_len10 > 1 ? _len10 - 1 : 0), _key10 = 1; _key10 < _len10; _key10++) {
|
|
180
|
+
rest[_key10 - 1] = arguments[_key10];
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return (_this$api10 = this.api).removeUser.apply(_this$api10, [_objectSpread(_objectSpread({}, first), {}, {
|
|
184
|
+
siteId: siteId
|
|
185
|
+
})].concat(rest));
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
}
|
|
161
189
|
}, {
|
|
162
190
|
key: "webhook",
|
|
163
191
|
value: function webhook(_webhook, siteId) {
|
package/dist/Webflow.js
CHANGED
|
@@ -20,7 +20,10 @@ var _WebflowError = _interopRequireWildcard(require("./WebflowError"));
|
|
|
20
20
|
var _excluded = ["collectionId"],
|
|
21
21
|
_excluded2 = ["collectionId", "itemId"],
|
|
22
22
|
_excluded3 = ["collectionId", "itemId"],
|
|
23
|
-
_excluded4 = ["
|
|
23
|
+
_excluded4 = ["collectionId", "itemIds"],
|
|
24
|
+
_excluded5 = ["collectionId", "itemIds"],
|
|
25
|
+
_excluded6 = ["siteId", "userId"],
|
|
26
|
+
_excluded7 = ["siteId"];
|
|
24
27
|
|
|
25
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); }
|
|
26
29
|
|
|
@@ -44,7 +47,7 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
|
|
|
44
47
|
|
|
45
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; }
|
|
46
49
|
|
|
47
|
-
var DEFAULT_ENDPOINT =
|
|
50
|
+
var DEFAULT_ENDPOINT = "https://api.webflow.com";
|
|
48
51
|
|
|
49
52
|
var buildMeta = function buildMeta(res) {
|
|
50
53
|
if (!res || !res.headers) {
|
|
@@ -53,8 +56,8 @@ var buildMeta = function buildMeta(res) {
|
|
|
53
56
|
|
|
54
57
|
return {
|
|
55
58
|
rateLimit: {
|
|
56
|
-
limit: parseInt(res.headers.get(
|
|
57
|
-
remaining: parseInt(res.headers.get(
|
|
59
|
+
limit: parseInt(res.headers.get("x-ratelimit-limit"), 10),
|
|
60
|
+
remaining: parseInt(res.headers.get("x-ratelimit-remaining"), 10)
|
|
58
61
|
}
|
|
59
62
|
};
|
|
60
63
|
};
|
|
@@ -77,7 +80,7 @@ var responseHandler = function responseHandler(res) {
|
|
|
77
80
|
errOpts.problems = body.problems;
|
|
78
81
|
}
|
|
79
82
|
|
|
80
|
-
var errMsg = body && body.err ? body.err :
|
|
83
|
+
var errMsg = body && body.err ? body.err : "Unknown error occured";
|
|
81
84
|
var err = new _WebflowError["default"](errMsg);
|
|
82
85
|
return Promise.reject(Object.assign(err, errOpts));
|
|
83
86
|
}
|
|
@@ -97,28 +100,28 @@ var Webflow = /*#__PURE__*/function () {
|
|
|
97
100
|
endpoint = _ref$endpoint === void 0 ? DEFAULT_ENDPOINT : _ref$endpoint,
|
|
98
101
|
token = _ref.token,
|
|
99
102
|
_ref$version = _ref.version,
|
|
100
|
-
version = _ref$version === void 0 ?
|
|
103
|
+
version = _ref$version === void 0 ? "1.0.0" : _ref$version;
|
|
101
104
|
|
|
102
105
|
_classCallCheck(this, Webflow);
|
|
103
106
|
|
|
104
|
-
if (!token) throw (0, _WebflowError.buildRequiredArgError)(
|
|
107
|
+
if (!token) throw (0, _WebflowError.buildRequiredArgError)("token");
|
|
105
108
|
this.responseWrapper = new _ResponseWrapper["default"](this);
|
|
106
109
|
this.endpoint = endpoint;
|
|
107
110
|
this.token = token;
|
|
108
111
|
this.headers = {
|
|
109
|
-
Accept:
|
|
112
|
+
Accept: "application/json",
|
|
110
113
|
Authorization: "Bearer ".concat(token),
|
|
111
|
-
|
|
112
|
-
|
|
114
|
+
"accept-version": version,
|
|
115
|
+
"Content-Type": "application/json"
|
|
113
116
|
};
|
|
114
117
|
|
|
115
118
|
this.authenticatedFetch = function (method, path, data, query) {
|
|
116
|
-
var queryString = query && !(0, _utils.isObjectEmpty)(query) ? "?".concat(_qs["default"].stringify(query)) :
|
|
119
|
+
var queryString = query && !(0, _utils.isObjectEmpty)(query) ? "?".concat(_qs["default"].stringify(query)) : "";
|
|
117
120
|
var uri = "".concat(_this.endpoint).concat(path).concat(queryString);
|
|
118
121
|
var opts = {
|
|
119
122
|
method: method,
|
|
120
123
|
headers: _this.headers,
|
|
121
|
-
mode:
|
|
124
|
+
mode: "cors"
|
|
122
125
|
};
|
|
123
126
|
|
|
124
127
|
if (data) {
|
|
@@ -134,38 +137,38 @@ var Webflow = /*#__PURE__*/function () {
|
|
|
134
137
|
key: "get",
|
|
135
138
|
value: function get(path) {
|
|
136
139
|
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
137
|
-
return this.authenticatedFetch(
|
|
140
|
+
return this.authenticatedFetch("GET", path, null, query);
|
|
138
141
|
}
|
|
139
142
|
}, {
|
|
140
143
|
key: "post",
|
|
141
144
|
value: function post(path, data) {
|
|
142
145
|
var query = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
143
|
-
return this.authenticatedFetch(
|
|
146
|
+
return this.authenticatedFetch("POST", path, data, query);
|
|
144
147
|
}
|
|
145
148
|
}, {
|
|
146
149
|
key: "put",
|
|
147
150
|
value: function put(path, data) {
|
|
148
151
|
var query = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
149
|
-
return this.authenticatedFetch(
|
|
152
|
+
return this.authenticatedFetch("PUT", path, data, query);
|
|
150
153
|
}
|
|
151
154
|
}, {
|
|
152
155
|
key: "patch",
|
|
153
156
|
value: function patch(path, data) {
|
|
154
157
|
var query = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
155
|
-
return this.authenticatedFetch(
|
|
158
|
+
return this.authenticatedFetch("PATCH", path, data, query);
|
|
156
159
|
}
|
|
157
160
|
}, {
|
|
158
161
|
key: "delete",
|
|
159
|
-
value: function _delete(path) {
|
|
160
|
-
var query = arguments.length >
|
|
161
|
-
return this.authenticatedFetch(
|
|
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);
|
|
162
165
|
} // Meta
|
|
163
166
|
|
|
164
167
|
}, {
|
|
165
168
|
key: "info",
|
|
166
169
|
value: function info() {
|
|
167
170
|
var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
168
|
-
return this.get(
|
|
171
|
+
return this.get("/info", query);
|
|
169
172
|
} // Sites
|
|
170
173
|
|
|
171
174
|
}, {
|
|
@@ -174,7 +177,7 @@ var Webflow = /*#__PURE__*/function () {
|
|
|
174
177
|
var _this2 = this;
|
|
175
178
|
|
|
176
179
|
var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
177
|
-
return this.get(
|
|
180
|
+
return this.get("/sites", query).then(function (sites) {
|
|
178
181
|
return sites.map(function (site) {
|
|
179
182
|
return _this2.responseWrapper.site(site);
|
|
180
183
|
});
|
|
@@ -187,7 +190,7 @@ var Webflow = /*#__PURE__*/function () {
|
|
|
187
190
|
|
|
188
191
|
var siteId = _ref2.siteId;
|
|
189
192
|
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
190
|
-
if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)(
|
|
193
|
+
if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("siteId"));
|
|
191
194
|
return this.get("/sites/".concat(siteId), query).then(function (site) {
|
|
192
195
|
return _this3.responseWrapper.site(site);
|
|
193
196
|
});
|
|
@@ -197,8 +200,8 @@ var Webflow = /*#__PURE__*/function () {
|
|
|
197
200
|
value: function publishSite(_ref3) {
|
|
198
201
|
var siteId = _ref3.siteId,
|
|
199
202
|
domains = _ref3.domains;
|
|
200
|
-
if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)(
|
|
201
|
-
if (!domains) return Promise.reject((0, _WebflowError.buildRequiredArgError)(
|
|
203
|
+
if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("siteId"));
|
|
204
|
+
if (!domains) return Promise.reject((0, _WebflowError.buildRequiredArgError)("domains"));
|
|
202
205
|
return this.post("/sites/".concat(siteId, "/publish"), {
|
|
203
206
|
domains: domains
|
|
204
207
|
});
|
|
@@ -210,7 +213,7 @@ var Webflow = /*#__PURE__*/function () {
|
|
|
210
213
|
var _this4 = this;
|
|
211
214
|
|
|
212
215
|
var siteId = _ref4.siteId;
|
|
213
|
-
if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)(
|
|
216
|
+
if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("siteId"));
|
|
214
217
|
return this.get("/sites/".concat(siteId, "/domains")).then(function (domains) {
|
|
215
218
|
return domains.map(function (domain) {
|
|
216
219
|
return _this4.responseWrapper.domain(domain, siteId);
|
|
@@ -225,7 +228,7 @@ var Webflow = /*#__PURE__*/function () {
|
|
|
225
228
|
|
|
226
229
|
var siteId = _ref5.siteId;
|
|
227
230
|
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
228
|
-
if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)(
|
|
231
|
+
if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("siteId"));
|
|
229
232
|
return this.get("/sites/".concat(siteId, "/collections"), query).then(function (collections) {
|
|
230
233
|
return collections.map(function (collection) {
|
|
231
234
|
return _this5.responseWrapper.collection(collection);
|
|
@@ -239,7 +242,7 @@ var Webflow = /*#__PURE__*/function () {
|
|
|
239
242
|
|
|
240
243
|
var collectionId = _ref6.collectionId;
|
|
241
244
|
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
242
|
-
if (!collectionId) return Promise.reject((0, _WebflowError.buildRequiredArgError)(
|
|
245
|
+
if (!collectionId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("collectionId"));
|
|
243
246
|
return this.get("/collections/".concat(collectionId), query).then(function (collection) {
|
|
244
247
|
return _this6.responseWrapper.collection(collection);
|
|
245
248
|
});
|
|
@@ -252,7 +255,7 @@ var Webflow = /*#__PURE__*/function () {
|
|
|
252
255
|
|
|
253
256
|
var collectionId = _ref7.collectionId;
|
|
254
257
|
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
255
|
-
if (!collectionId) return Promise.reject((0, _WebflowError.buildRequiredArgError)(
|
|
258
|
+
if (!collectionId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("collectionId"));
|
|
256
259
|
return this.get("/collections/".concat(collectionId, "/items"), query).then(function (res) {
|
|
257
260
|
return _objectSpread(_objectSpread({}, res), {}, {
|
|
258
261
|
items: res.items.map(function (item) {
|
|
@@ -269,8 +272,8 @@ var Webflow = /*#__PURE__*/function () {
|
|
|
269
272
|
var collectionId = _ref8.collectionId,
|
|
270
273
|
itemId = _ref8.itemId;
|
|
271
274
|
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
272
|
-
if (!collectionId) return Promise.reject((0, _WebflowError.buildRequiredArgError)(
|
|
273
|
-
if (!itemId) return Promise.reject((0, _WebflowError.buildRequiredArgError)(
|
|
275
|
+
if (!collectionId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("collectionId"));
|
|
276
|
+
if (!itemId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("itemId"));
|
|
274
277
|
return this.get("/collections/".concat(collectionId, "/items/").concat(itemId), query).then(function (res) {
|
|
275
278
|
return _this8.responseWrapper.item(res.items[0], collectionId);
|
|
276
279
|
});
|
|
@@ -284,7 +287,7 @@ var Webflow = /*#__PURE__*/function () {
|
|
|
284
287
|
data = _objectWithoutProperties(_ref9, _excluded);
|
|
285
288
|
|
|
286
289
|
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
287
|
-
if (!collectionId) return Promise.reject((0, _WebflowError.buildRequiredArgError)(
|
|
290
|
+
if (!collectionId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("collectionId"));
|
|
288
291
|
return this.post("/collections/".concat(collectionId, "/items"), data, query).then(function (item) {
|
|
289
292
|
return _this9.responseWrapper.item(item, collectionId);
|
|
290
293
|
});
|
|
@@ -297,8 +300,8 @@ var Webflow = /*#__PURE__*/function () {
|
|
|
297
300
|
data = _objectWithoutProperties(_ref10, _excluded2);
|
|
298
301
|
|
|
299
302
|
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
300
|
-
if (!collectionId) return Promise.reject((0, _WebflowError.buildRequiredArgError)(
|
|
301
|
-
if (!itemId) return Promise.reject((0, _WebflowError.buildRequiredArgError)(
|
|
303
|
+
if (!collectionId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("collectionId"));
|
|
304
|
+
if (!itemId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("itemId"));
|
|
302
305
|
return this.put("/collections/".concat(collectionId, "/items/").concat(itemId), data, query);
|
|
303
306
|
}
|
|
304
307
|
}, {
|
|
@@ -307,9 +310,9 @@ var Webflow = /*#__PURE__*/function () {
|
|
|
307
310
|
var collectionId = _ref11.collectionId,
|
|
308
311
|
itemId = _ref11.itemId;
|
|
309
312
|
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
310
|
-
if (!collectionId) return Promise.reject((0, _WebflowError.buildRequiredArgError)(
|
|
311
|
-
if (!itemId) return Promise.reject((0, _WebflowError.buildRequiredArgError)(
|
|
312
|
-
return this["delete"]("/collections/".concat(collectionId, "/items/").concat(itemId), query);
|
|
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);
|
|
313
316
|
}
|
|
314
317
|
}, {
|
|
315
318
|
key: "patchItem",
|
|
@@ -319,64 +322,157 @@ var Webflow = /*#__PURE__*/function () {
|
|
|
319
322
|
data = _objectWithoutProperties(_ref12, _excluded3);
|
|
320
323
|
|
|
321
324
|
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
322
|
-
if (!collectionId) return Promise.reject((0, _WebflowError.buildRequiredArgError)(
|
|
323
|
-
if (!itemId) return Promise.reject((0, _WebflowError.buildRequiredArgError)(
|
|
325
|
+
if (!collectionId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("collectionId"));
|
|
326
|
+
if (!itemId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("itemId"));
|
|
324
327
|
return this.patch("/collections/".concat(collectionId, "/items/").concat(itemId), data, query);
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
+
}
|
|
329
|
+
}, {
|
|
330
|
+
key: "deleteItems",
|
|
331
|
+
value: function deleteItems(_ref13) {
|
|
332
|
+
var collectionId = _ref13.collectionId,
|
|
333
|
+
itemIds = _ref13.itemIds,
|
|
334
|
+
data = _objectWithoutProperties(_ref13, _excluded4);
|
|
328
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
|
+
}
|
|
329
343
|
}, {
|
|
330
|
-
key: "
|
|
331
|
-
value: function
|
|
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) {
|
|
332
361
|
var _this10 = this;
|
|
333
362
|
|
|
334
|
-
var siteId =
|
|
363
|
+
var siteId = _ref15.siteId;
|
|
335
364
|
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
336
|
-
if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)(
|
|
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"));
|
|
337
433
|
return this.get("/sites/".concat(siteId, "/webhooks"), query).then(function (webhooks) {
|
|
338
434
|
return webhooks.map(function (webhook) {
|
|
339
|
-
return
|
|
435
|
+
return _this13.responseWrapper.webhook(webhook, siteId);
|
|
340
436
|
});
|
|
341
437
|
});
|
|
342
438
|
}
|
|
343
439
|
}, {
|
|
344
440
|
key: "webhook",
|
|
345
|
-
value: function webhook(
|
|
346
|
-
var
|
|
441
|
+
value: function webhook(_ref21) {
|
|
442
|
+
var _this14 = this;
|
|
347
443
|
|
|
348
|
-
var siteId =
|
|
349
|
-
webhookId =
|
|
444
|
+
var siteId = _ref21.siteId,
|
|
445
|
+
webhookId = _ref21.webhookId;
|
|
350
446
|
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
351
|
-
if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)(
|
|
352
|
-
if (!webhookId) return Promise.reject((0, _WebflowError.buildRequiredArgError)(
|
|
447
|
+
if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("siteId"));
|
|
448
|
+
if (!webhookId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("webhookId"));
|
|
353
449
|
return this.get("/sites/".concat(siteId, "/webhooks/").concat(webhookId), query).then(function (webhook) {
|
|
354
|
-
return
|
|
450
|
+
return _this14.responseWrapper.webhook(webhook, siteId);
|
|
355
451
|
});
|
|
356
452
|
}
|
|
357
453
|
}, {
|
|
358
454
|
key: "createWebhook",
|
|
359
|
-
value: function createWebhook(
|
|
360
|
-
var
|
|
455
|
+
value: function createWebhook(_ref22) {
|
|
456
|
+
var _this15 = this;
|
|
361
457
|
|
|
362
|
-
var siteId =
|
|
363
|
-
data = _objectWithoutProperties(
|
|
458
|
+
var siteId = _ref22.siteId,
|
|
459
|
+
data = _objectWithoutProperties(_ref22, _excluded7);
|
|
364
460
|
|
|
365
461
|
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
366
|
-
if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)(
|
|
462
|
+
if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("siteId"));
|
|
367
463
|
return this.post("/sites/".concat(siteId, "/webhooks"), data, query).then(function (webhook) {
|
|
368
|
-
return
|
|
464
|
+
return _this15.responseWrapper.webhook(webhook, siteId);
|
|
369
465
|
});
|
|
370
466
|
}
|
|
371
467
|
}, {
|
|
372
468
|
key: "removeWebhook",
|
|
373
|
-
value: function removeWebhook(
|
|
374
|
-
var siteId =
|
|
375
|
-
webhookId =
|
|
469
|
+
value: function removeWebhook(_ref23) {
|
|
470
|
+
var siteId = _ref23.siteId,
|
|
471
|
+
webhookId = _ref23.webhookId;
|
|
376
472
|
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
377
|
-
if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)(
|
|
378
|
-
if (!webhookId) return Promise.reject((0, _WebflowError.buildRequiredArgError)(
|
|
379
|
-
return this["delete"]("/sites/".concat(siteId, "/webhooks/").concat(webhookId), query);
|
|
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);
|
|
380
476
|
}
|
|
381
477
|
}]);
|
|
382
478
|
|
package/index.d.ts
CHANGED
|
@@ -72,6 +72,37 @@ declare class Webflow {
|
|
|
72
72
|
query?: Webflow.WebflowQueryArg
|
|
73
73
|
): Promise<Webflow.WebflowApiModel.Collection>;
|
|
74
74
|
|
|
75
|
+
// Users
|
|
76
|
+
users(
|
|
77
|
+
data: {
|
|
78
|
+
siteId: string;
|
|
79
|
+
},
|
|
80
|
+
query?: Webflow.WebflowQueryArg
|
|
81
|
+
): Promise<Webflow.WebflowApiModel.User[]>;
|
|
82
|
+
|
|
83
|
+
user(
|
|
84
|
+
data: {
|
|
85
|
+
siteId: string;
|
|
86
|
+
userId: string;
|
|
87
|
+
},
|
|
88
|
+
query?: Webflow.WebflowQueryArg
|
|
89
|
+
): Promise<Webflow.WebflowApiModel.User>;
|
|
90
|
+
|
|
91
|
+
updateUser(
|
|
92
|
+
data: { siteId: string; userId: string } & Record<string, any>,
|
|
93
|
+
query?: Webflow.WebflowQueryArg
|
|
94
|
+
): Promise<Webflow.WebflowApiModel.User>;
|
|
95
|
+
|
|
96
|
+
removeUser(
|
|
97
|
+
data: { siteId: string; userId: string },
|
|
98
|
+
query?: Webflow.WebflowQueryArg
|
|
99
|
+
): Promise<{ deleted: number }>;
|
|
100
|
+
|
|
101
|
+
inviteUser(
|
|
102
|
+
data: { siteId: string; email: string },
|
|
103
|
+
query?: Webflow.WebflowQueryArg
|
|
104
|
+
): Promise<Webflow.WebflowApiModel.User>;
|
|
105
|
+
|
|
75
106
|
// Items
|
|
76
107
|
|
|
77
108
|
items(
|
|
@@ -213,6 +244,14 @@ declare namespace Webflow {
|
|
|
213
244
|
name: string;
|
|
214
245
|
}
|
|
215
246
|
|
|
247
|
+
interface User {
|
|
248
|
+
_id: string;
|
|
249
|
+
lastUpdated: string;
|
|
250
|
+
createdOn: string;
|
|
251
|
+
emailVerified: boolean;
|
|
252
|
+
data: object;
|
|
253
|
+
}
|
|
254
|
+
|
|
216
255
|
/**
|
|
217
256
|
* https://developers.webflow.com/?javascript#collections
|
|
218
257
|
*/
|
|
@@ -301,7 +340,7 @@ declare namespace Webflow {
|
|
|
301
340
|
rateLimit: {
|
|
302
341
|
limit: number;
|
|
303
342
|
remaining: number;
|
|
304
|
-
}
|
|
343
|
+
};
|
|
305
344
|
}
|
|
306
345
|
|
|
307
346
|
interface ItemsResponse {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webflow-api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "SDK for the Webflow CMS API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"jsnext:main": "src/index.js",
|
|
@@ -34,13 +34,14 @@
|
|
|
34
34
|
"ava": "^4.1.0",
|
|
35
35
|
"eslint": "^8.12.0",
|
|
36
36
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
37
|
+
"eslint-config-prettier": "^8.5.0",
|
|
37
38
|
"eslint-plugin-import": "^2.25.2",
|
|
38
39
|
"nock": "^13.0.7",
|
|
39
40
|
"nyc": "^15.1.0"
|
|
40
41
|
},
|
|
41
42
|
"dependencies": {
|
|
42
|
-
"isomorphic-fetch": "^3.0.0",
|
|
43
43
|
"es6-error": "^4.0.0",
|
|
44
|
+
"isomorphic-fetch": "^3.0.0",
|
|
44
45
|
"qs": "^6.3.0"
|
|
45
46
|
},
|
|
46
47
|
"ava": {
|
package/src/ResponseWrapper.js
CHANGED
|
@@ -37,16 +37,28 @@ export default class ResponseWrapper {
|
|
|
37
37
|
|
|
38
38
|
items: this.api.items.bind(this.api, { collectionId: collection._id }),
|
|
39
39
|
item(first, ...rest) {
|
|
40
|
-
return this.api.item(
|
|
40
|
+
return this.api.item(
|
|
41
|
+
{ ...first, collectionId: collection._id },
|
|
42
|
+
...rest
|
|
43
|
+
);
|
|
41
44
|
},
|
|
42
45
|
createItem(first, ...rest) {
|
|
43
|
-
return this.api.createItem(
|
|
46
|
+
return this.api.createItem(
|
|
47
|
+
{ ...first, collectionId: collection._id },
|
|
48
|
+
...rest
|
|
49
|
+
);
|
|
44
50
|
},
|
|
45
51
|
updateItem(first, ...rest) {
|
|
46
|
-
return this.api.updateItem(
|
|
52
|
+
return this.api.updateItem(
|
|
53
|
+
{ ...first, collectionId: collection._id },
|
|
54
|
+
...rest
|
|
55
|
+
);
|
|
47
56
|
},
|
|
48
57
|
removeItem(first, ...rest) {
|
|
49
|
-
return this.api.removeItem(
|
|
58
|
+
return this.api.removeItem(
|
|
59
|
+
{ ...first, collectionId: collection._id },
|
|
60
|
+
...rest
|
|
61
|
+
);
|
|
50
62
|
},
|
|
51
63
|
};
|
|
52
64
|
}
|
|
@@ -56,9 +68,28 @@ export default class ResponseWrapper {
|
|
|
56
68
|
...item,
|
|
57
69
|
|
|
58
70
|
update(first, ...rest) {
|
|
59
|
-
return this.api.updateItem(
|
|
71
|
+
return this.api.updateItem(
|
|
72
|
+
{ ...first, collectionId, itemId: item._id },
|
|
73
|
+
...rest
|
|
74
|
+
);
|
|
75
|
+
},
|
|
76
|
+
remove: this.api.updateItem.bind(this.api, {
|
|
77
|
+
collectionId,
|
|
78
|
+
itemId: item._id,
|
|
79
|
+
}),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
user(user, siteId) {
|
|
84
|
+
return {
|
|
85
|
+
...user,
|
|
86
|
+
|
|
87
|
+
update(first, ...rest) {
|
|
88
|
+
return this.api.updateUser({ ...first, siteId }, ...rest);
|
|
89
|
+
},
|
|
90
|
+
remove(first, ...rest) {
|
|
91
|
+
return this.api.removeUser({ ...first, siteId }, ...rest);
|
|
60
92
|
},
|
|
61
|
-
remove: this.api.updateItem.bind(this.api, { collectionId, itemId: item._id }),
|
|
62
93
|
};
|
|
63
94
|
}
|
|
64
95
|
|
|
@@ -66,7 +97,10 @@ export default class ResponseWrapper {
|
|
|
66
97
|
return {
|
|
67
98
|
...webhook,
|
|
68
99
|
|
|
69
|
-
remove: this.api.removeWebhook.bind(this.api, {
|
|
100
|
+
remove: this.api.removeWebhook.bind(this.api, {
|
|
101
|
+
siteId,
|
|
102
|
+
webhookId: webhook._id,
|
|
103
|
+
}),
|
|
70
104
|
};
|
|
71
105
|
}
|
|
72
106
|
}
|
package/src/Webflow.js
CHANGED
|
@@ -1,29 +1,33 @@
|
|
|
1
|
-
import fetch from
|
|
2
|
-
import qs from
|
|
1
|
+
import fetch from "isomorphic-fetch";
|
|
2
|
+
import qs from "qs";
|
|
3
3
|
|
|
4
|
-
import { isObjectEmpty } from
|
|
5
|
-
import ResponseWrapper from
|
|
6
|
-
import WebflowError, { buildRequiredArgError } from
|
|
4
|
+
import { isObjectEmpty } from "./utils";
|
|
5
|
+
import ResponseWrapper from "./ResponseWrapper";
|
|
6
|
+
import WebflowError, { buildRequiredArgError } from "./WebflowError";
|
|
7
7
|
|
|
8
|
-
const DEFAULT_ENDPOINT =
|
|
8
|
+
const DEFAULT_ENDPOINT = "https://api.webflow.com";
|
|
9
9
|
|
|
10
10
|
const buildMeta = (res) => {
|
|
11
|
-
if (!res || !res.headers) {
|
|
11
|
+
if (!res || !res.headers) {
|
|
12
|
+
return {};
|
|
13
|
+
}
|
|
12
14
|
|
|
13
15
|
return {
|
|
14
16
|
rateLimit: {
|
|
15
|
-
limit: parseInt(res.headers.get(
|
|
16
|
-
remaining: parseInt(res.headers.get(
|
|
17
|
+
limit: parseInt(res.headers.get("x-ratelimit-limit"), 10),
|
|
18
|
+
remaining: parseInt(res.headers.get("x-ratelimit-remaining"), 10),
|
|
17
19
|
},
|
|
18
20
|
};
|
|
19
21
|
};
|
|
20
22
|
|
|
21
|
-
const responseHandler = res =>
|
|
22
|
-
res
|
|
23
|
-
.
|
|
23
|
+
const responseHandler = (res) =>
|
|
24
|
+
res
|
|
25
|
+
.json()
|
|
26
|
+
.catch((err) =>
|
|
24
27
|
// Catch unexpected server errors where json isn't sent and rewrite
|
|
25
28
|
// with proper class (WebflowError)
|
|
26
|
-
Promise.reject(new WebflowError(err))
|
|
29
|
+
Promise.reject(new WebflowError(err))
|
|
30
|
+
)
|
|
27
31
|
.then((body) => {
|
|
28
32
|
if (res.status >= 400) {
|
|
29
33
|
const errOpts = {
|
|
@@ -36,7 +40,7 @@ const responseHandler = res =>
|
|
|
36
40
|
errOpts.problems = body.problems;
|
|
37
41
|
}
|
|
38
42
|
|
|
39
|
-
const errMsg =
|
|
43
|
+
const errMsg = body && body.err ? body.err : "Unknown error occured";
|
|
40
44
|
const err = new WebflowError(errMsg);
|
|
41
45
|
|
|
42
46
|
return Promise.reject(Object.assign(err, errOpts));
|
|
@@ -48,12 +52,8 @@ const responseHandler = res =>
|
|
|
48
52
|
});
|
|
49
53
|
|
|
50
54
|
export default class Webflow {
|
|
51
|
-
constructor({
|
|
52
|
-
|
|
53
|
-
token,
|
|
54
|
-
version = '1.0.0',
|
|
55
|
-
} = {}) {
|
|
56
|
-
if (!token) throw buildRequiredArgError('token');
|
|
55
|
+
constructor({ endpoint = DEFAULT_ENDPOINT, token, version = "1.0.0" } = {}) {
|
|
56
|
+
if (!token) throw buildRequiredArgError("token");
|
|
57
57
|
|
|
58
58
|
this.responseWrapper = new ResponseWrapper(this);
|
|
59
59
|
|
|
@@ -61,76 +61,78 @@ export default class Webflow {
|
|
|
61
61
|
this.token = token;
|
|
62
62
|
|
|
63
63
|
this.headers = {
|
|
64
|
-
Accept:
|
|
64
|
+
Accept: "application/json",
|
|
65
65
|
Authorization: `Bearer ${token}`,
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
"accept-version": version,
|
|
67
|
+
"Content-Type": "application/json",
|
|
68
68
|
};
|
|
69
69
|
|
|
70
70
|
this.authenticatedFetch = (method, path, data, query) => {
|
|
71
|
-
const queryString =
|
|
72
|
-
? `?${qs.stringify(query)}`
|
|
73
|
-
: '';
|
|
71
|
+
const queryString =
|
|
72
|
+
query && !isObjectEmpty(query) ? `?${qs.stringify(query)}` : "";
|
|
74
73
|
|
|
75
74
|
const uri = `${this.endpoint}${path}${queryString}`;
|
|
76
75
|
const opts = {
|
|
77
76
|
method,
|
|
78
77
|
headers: this.headers,
|
|
79
|
-
mode:
|
|
78
|
+
mode: "cors",
|
|
80
79
|
};
|
|
81
80
|
|
|
82
81
|
if (data) {
|
|
83
82
|
opts.body = JSON.stringify(data);
|
|
84
83
|
}
|
|
85
84
|
|
|
86
|
-
return fetch(uri, opts)
|
|
87
|
-
.then(responseHandler);
|
|
85
|
+
return fetch(uri, opts).then(responseHandler);
|
|
88
86
|
};
|
|
89
87
|
}
|
|
90
88
|
|
|
91
89
|
// Generic HTTP request handlers
|
|
92
90
|
|
|
93
91
|
get(path, query = {}) {
|
|
94
|
-
return this.authenticatedFetch(
|
|
92
|
+
return this.authenticatedFetch("GET", path, null, query);
|
|
95
93
|
}
|
|
96
94
|
|
|
97
95
|
post(path, data, query = {}) {
|
|
98
|
-
return this.authenticatedFetch(
|
|
96
|
+
return this.authenticatedFetch("POST", path, data, query);
|
|
99
97
|
}
|
|
100
98
|
|
|
101
99
|
put(path, data, query = {}) {
|
|
102
|
-
return this.authenticatedFetch(
|
|
100
|
+
return this.authenticatedFetch("PUT", path, data, query);
|
|
103
101
|
}
|
|
104
102
|
|
|
105
103
|
patch(path, data, query = {}) {
|
|
106
|
-
return this.authenticatedFetch(
|
|
104
|
+
return this.authenticatedFetch("PATCH", path, data, query);
|
|
107
105
|
}
|
|
108
106
|
|
|
109
|
-
delete(path, query = {}) {
|
|
110
|
-
return this.authenticatedFetch(
|
|
107
|
+
delete(path, data, query = {}) {
|
|
108
|
+
return this.authenticatedFetch("DELETE", path, data, query);
|
|
111
109
|
}
|
|
112
110
|
|
|
113
111
|
// Meta
|
|
114
112
|
|
|
115
113
|
info(query = {}) {
|
|
116
|
-
return this.get(
|
|
114
|
+
return this.get("/info", query);
|
|
117
115
|
}
|
|
118
116
|
|
|
119
117
|
// Sites
|
|
120
118
|
|
|
121
119
|
sites(query = {}) {
|
|
122
|
-
return this.get(
|
|
120
|
+
return this.get("/sites", query).then((sites) =>
|
|
121
|
+
sites.map((site) => this.responseWrapper.site(site))
|
|
122
|
+
);
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
site({ siteId }, query = {}) {
|
|
126
|
-
if (!siteId) return Promise.reject(buildRequiredArgError(
|
|
126
|
+
if (!siteId) return Promise.reject(buildRequiredArgError("siteId"));
|
|
127
127
|
|
|
128
|
-
return this.get(`/sites/${siteId}`, query).then(site =>
|
|
128
|
+
return this.get(`/sites/${siteId}`, query).then((site) =>
|
|
129
|
+
this.responseWrapper.site(site)
|
|
130
|
+
);
|
|
129
131
|
}
|
|
130
132
|
|
|
131
133
|
publishSite({ siteId, domains }) {
|
|
132
|
-
if (!siteId) return Promise.reject(buildRequiredArgError(
|
|
133
|
-
if (!domains) return Promise.reject(buildRequiredArgError(
|
|
134
|
+
if (!siteId) return Promise.reject(buildRequiredArgError("siteId"));
|
|
135
|
+
if (!domains) return Promise.reject(buildRequiredArgError("domains"));
|
|
134
136
|
|
|
135
137
|
return this.post(`/sites/${siteId}/publish`, { domains });
|
|
136
138
|
}
|
|
@@ -138,118 +140,203 @@ export default class Webflow {
|
|
|
138
140
|
// Domains
|
|
139
141
|
|
|
140
142
|
domains({ siteId }) {
|
|
141
|
-
if (!siteId) return Promise.reject(buildRequiredArgError(
|
|
143
|
+
if (!siteId) return Promise.reject(buildRequiredArgError("siteId"));
|
|
142
144
|
|
|
143
|
-
return this.get(`/sites/${siteId}/domains`).then(
|
|
144
|
-
domains
|
|
145
|
+
return this.get(`/sites/${siteId}/domains`).then((domains) =>
|
|
146
|
+
domains.map((domain) => this.responseWrapper.domain(domain, siteId))
|
|
145
147
|
);
|
|
146
148
|
}
|
|
147
149
|
|
|
148
150
|
// Collections
|
|
149
151
|
|
|
150
152
|
collections({ siteId }, query = {}) {
|
|
151
|
-
if (!siteId) return Promise.reject(buildRequiredArgError(
|
|
153
|
+
if (!siteId) return Promise.reject(buildRequiredArgError("siteId"));
|
|
152
154
|
|
|
153
|
-
return this.get(`/sites/${siteId}/collections`, query).then(
|
|
154
|
-
collections
|
|
155
|
+
return this.get(`/sites/${siteId}/collections`, query).then((collections) =>
|
|
156
|
+
collections.map((collection) =>
|
|
157
|
+
this.responseWrapper.collection(collection)
|
|
158
|
+
)
|
|
155
159
|
);
|
|
156
160
|
}
|
|
157
161
|
|
|
158
162
|
collection({ collectionId }, query = {}) {
|
|
159
|
-
if (!collectionId)
|
|
163
|
+
if (!collectionId)
|
|
164
|
+
return Promise.reject(buildRequiredArgError("collectionId"));
|
|
160
165
|
|
|
161
|
-
return this.get(`/collections/${collectionId}`, query).then(
|
|
162
|
-
|
|
166
|
+
return this.get(`/collections/${collectionId}`, query).then((collection) =>
|
|
167
|
+
this.responseWrapper.collection(collection)
|
|
163
168
|
);
|
|
164
169
|
}
|
|
165
170
|
|
|
166
171
|
// Items
|
|
167
172
|
|
|
168
173
|
items({ collectionId }, query = {}) {
|
|
169
|
-
if (!collectionId)
|
|
174
|
+
if (!collectionId)
|
|
175
|
+
return Promise.reject(buildRequiredArgError("collectionId"));
|
|
170
176
|
|
|
171
177
|
return this.get(`/collections/${collectionId}/items`, query).then(
|
|
172
|
-
res => ({
|
|
178
|
+
(res) => ({
|
|
173
179
|
...res,
|
|
174
180
|
|
|
175
|
-
items: res.items.map(item =>
|
|
176
|
-
|
|
181
|
+
items: res.items.map((item) =>
|
|
182
|
+
this.responseWrapper.item(item, collectionId)
|
|
183
|
+
),
|
|
184
|
+
})
|
|
177
185
|
);
|
|
178
186
|
}
|
|
179
187
|
|
|
180
188
|
item({ collectionId, itemId }, query = {}) {
|
|
181
|
-
if (!collectionId)
|
|
182
|
-
|
|
189
|
+
if (!collectionId)
|
|
190
|
+
return Promise.reject(buildRequiredArgError("collectionId"));
|
|
191
|
+
if (!itemId) return Promise.reject(buildRequiredArgError("itemId"));
|
|
183
192
|
|
|
184
193
|
return this.get(`/collections/${collectionId}/items/${itemId}`, query).then(
|
|
185
|
-
res => this.responseWrapper.item(res.items[0], collectionId)
|
|
194
|
+
(res) => this.responseWrapper.item(res.items[0], collectionId)
|
|
186
195
|
);
|
|
187
196
|
}
|
|
188
197
|
|
|
189
198
|
createItem({ collectionId, ...data }, query = {}) {
|
|
190
|
-
if (!collectionId)
|
|
199
|
+
if (!collectionId)
|
|
200
|
+
return Promise.reject(buildRequiredArgError("collectionId"));
|
|
191
201
|
|
|
192
202
|
return this.post(`/collections/${collectionId}/items`, data, query).then(
|
|
193
|
-
item => this.responseWrapper.item(item, collectionId)
|
|
203
|
+
(item) => this.responseWrapper.item(item, collectionId)
|
|
194
204
|
);
|
|
195
205
|
}
|
|
196
206
|
|
|
197
207
|
updateItem({ collectionId, itemId, ...data }, query = {}) {
|
|
198
|
-
if (!collectionId)
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
208
|
+
if (!collectionId)
|
|
209
|
+
return Promise.reject(buildRequiredArgError("collectionId"));
|
|
210
|
+
if (!itemId) return Promise.reject(buildRequiredArgError("itemId"));
|
|
211
|
+
|
|
212
|
+
return this.put(
|
|
213
|
+
`/collections/${collectionId}/items/${itemId}`,
|
|
214
|
+
data,
|
|
215
|
+
query
|
|
216
|
+
);
|
|
202
217
|
}
|
|
203
218
|
|
|
204
219
|
removeItem({ collectionId, itemId }, query = {}) {
|
|
205
|
-
if (!collectionId)
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
220
|
+
if (!collectionId)
|
|
221
|
+
return Promise.reject(buildRequiredArgError("collectionId"));
|
|
222
|
+
if (!itemId) return Promise.reject(buildRequiredArgError("itemId"));
|
|
223
|
+
|
|
224
|
+
return this.delete(
|
|
225
|
+
`/collections/${collectionId}/items/${itemId}`,
|
|
226
|
+
null,
|
|
227
|
+
query
|
|
228
|
+
);
|
|
209
229
|
}
|
|
210
230
|
|
|
211
231
|
patchItem({ collectionId, itemId, ...data }, query = {}) {
|
|
212
|
-
if (!collectionId)
|
|
213
|
-
|
|
232
|
+
if (!collectionId)
|
|
233
|
+
return Promise.reject(buildRequiredArgError("collectionId"));
|
|
234
|
+
if (!itemId) return Promise.reject(buildRequiredArgError("itemId"));
|
|
235
|
+
|
|
236
|
+
return this.patch(
|
|
237
|
+
`/collections/${collectionId}/items/${itemId}`,
|
|
238
|
+
data,
|
|
239
|
+
query
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
deleteItems({ collectionId, itemIds, ...data }, query = {}) {
|
|
244
|
+
if (!collectionId)
|
|
245
|
+
return Promise.reject(buildRequiredArgError("collectionId"));
|
|
246
|
+
if (!itemIds) return Promise.reject(buildRequiredArgError("itemIds"));
|
|
247
|
+
|
|
248
|
+
return this.delete(
|
|
249
|
+
`/collections/${collectionId}/items`,
|
|
250
|
+
{ ...data, itemIds },
|
|
251
|
+
query
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
publishItems({ collectionId, itemIds, ...data }, query = {}) {
|
|
256
|
+
if (!collectionId)
|
|
257
|
+
return Promise.reject(buildRequiredArgError("collectionId"));
|
|
258
|
+
if (!itemIds) return Promise.reject(buildRequiredArgError("itemIds"));
|
|
259
|
+
|
|
260
|
+
return this.put(
|
|
261
|
+
`/collections/${collectionId}/items/publish`,
|
|
262
|
+
{ ...data, itemIds },
|
|
263
|
+
query
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// Users
|
|
268
|
+
|
|
269
|
+
users({ siteId }, query = {}) {
|
|
270
|
+
if (!siteId) return Promise.reject(buildRequiredArgError("siteId"));
|
|
271
|
+
|
|
272
|
+
return this.get(`/sites/${siteId}/users`, query).then((res) =>
|
|
273
|
+
res.users.map((user) => this.responseWrapper.user(user))
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
user({ siteId, userId }, query = {}) {
|
|
278
|
+
if (!siteId) return Promise.reject(buildRequiredArgError("siteId"));
|
|
279
|
+
if (!userId) return Promise.reject(buildRequiredArgError("userId"));
|
|
280
|
+
|
|
281
|
+
return this.get(`/sites/${siteId}/users/${userId}`, query).then((user) =>
|
|
282
|
+
this.responseWrapper.user(user, siteId)
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
updateUser({ siteId, userId, ...data }, query = {}) {
|
|
287
|
+
if (!siteId) return Promise.reject(buildRequiredArgError("siteId"));
|
|
288
|
+
if (!userId) return Promise.reject(buildRequiredArgError("userId"));
|
|
289
|
+
|
|
290
|
+
return this.patch(`/sites/${siteId}/users/${userId}`, data, query);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
inviteUser({ siteId, email }, query = {}) {
|
|
294
|
+
if (!siteId) return Promise.reject(buildRequiredArgError("siteId"));
|
|
295
|
+
if (!email) return Promise.reject(buildRequiredArgError("email"));
|
|
214
296
|
|
|
215
|
-
return this.
|
|
297
|
+
return this.post(`/sites/${siteId}/users/invite`, { email }, query).then(
|
|
298
|
+
(user) => this.responseWrapper.user(user, siteId)
|
|
299
|
+
);
|
|
216
300
|
}
|
|
217
301
|
|
|
218
|
-
|
|
302
|
+
removeUser({ siteId, userId }, query = {}) {
|
|
303
|
+
if (!siteId) return Promise.reject(buildRequiredArgError("siteId"));
|
|
304
|
+
if (!userId) return Promise.reject(buildRequiredArgError("userId"));
|
|
219
305
|
|
|
220
|
-
|
|
306
|
+
return this.delete(`/sites/${siteId}/users/${userId}`, null, query);
|
|
307
|
+
}
|
|
221
308
|
|
|
222
309
|
// Webhooks
|
|
223
310
|
|
|
224
311
|
webhooks({ siteId }, query = {}) {
|
|
225
|
-
if (!siteId) return Promise.reject(buildRequiredArgError(
|
|
312
|
+
if (!siteId) return Promise.reject(buildRequiredArgError("siteId"));
|
|
226
313
|
|
|
227
|
-
return this.get(`/sites/${siteId}/webhooks`, query).then(
|
|
228
|
-
webhooks
|
|
314
|
+
return this.get(`/sites/${siteId}/webhooks`, query).then((webhooks) =>
|
|
315
|
+
webhooks.map((webhook) => this.responseWrapper.webhook(webhook, siteId))
|
|
229
316
|
);
|
|
230
317
|
}
|
|
231
318
|
|
|
232
319
|
webhook({ siteId, webhookId }, query = {}) {
|
|
233
|
-
if (!siteId) return Promise.reject(buildRequiredArgError(
|
|
234
|
-
if (!webhookId) return Promise.reject(buildRequiredArgError(
|
|
320
|
+
if (!siteId) return Promise.reject(buildRequiredArgError("siteId"));
|
|
321
|
+
if (!webhookId) return Promise.reject(buildRequiredArgError("webhookId"));
|
|
235
322
|
|
|
236
323
|
return this.get(`/sites/${siteId}/webhooks/${webhookId}`, query).then(
|
|
237
|
-
webhook => this.responseWrapper.webhook(webhook, siteId)
|
|
324
|
+
(webhook) => this.responseWrapper.webhook(webhook, siteId)
|
|
238
325
|
);
|
|
239
326
|
}
|
|
240
327
|
|
|
241
328
|
createWebhook({ siteId, ...data }, query = {}) {
|
|
242
|
-
if (!siteId) return Promise.reject(buildRequiredArgError(
|
|
329
|
+
if (!siteId) return Promise.reject(buildRequiredArgError("siteId"));
|
|
243
330
|
|
|
244
|
-
return this.post(`/sites/${siteId}/webhooks`, data, query).then(
|
|
245
|
-
|
|
331
|
+
return this.post(`/sites/${siteId}/webhooks`, data, query).then((webhook) =>
|
|
332
|
+
this.responseWrapper.webhook(webhook, siteId)
|
|
246
333
|
);
|
|
247
334
|
}
|
|
248
335
|
|
|
249
336
|
removeWebhook({ siteId, webhookId }, query = {}) {
|
|
250
|
-
if (!siteId) return Promise.reject(buildRequiredArgError(
|
|
251
|
-
if (!webhookId) return Promise.reject(buildRequiredArgError(
|
|
337
|
+
if (!siteId) return Promise.reject(buildRequiredArgError("siteId"));
|
|
338
|
+
if (!webhookId) return Promise.reject(buildRequiredArgError("webhookId"));
|
|
252
339
|
|
|
253
|
-
return this.delete(`/sites/${siteId}/webhooks/${webhookId}`, query);
|
|
340
|
+
return this.delete(`/sites/${siteId}/webhooks/${webhookId}`, null, query);
|
|
254
341
|
}
|
|
255
342
|
}
|
package/src/WebflowError.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import ExtendableError from
|
|
1
|
+
import ExtendableError from "es6-error";
|
|
2
2
|
|
|
3
3
|
export default class WebflowError extends ExtendableError {}
|
|
4
4
|
|
|
5
|
-
export const buildRequiredArgError = name =>
|
|
6
|
-
new WebflowError(`Argument '${name}' is required but was not present`);
|
|
5
|
+
export const buildRequiredArgError = (name) => new WebflowError(`Argument '${name}' is required but was not present`);
|
package/src/utils.js
CHANGED
package/yarn.lock
CHANGED
|
@@ -1789,6 +1789,11 @@
|
|
|
1789
1789
|
"object.entries" "^1.1.5"
|
|
1790
1790
|
"semver" "^6.3.0"
|
|
1791
1791
|
|
|
1792
|
+
"eslint-config-prettier@^8.5.0":
|
|
1793
|
+
"integrity" "sha512-obmWKLUNCnhtQRKc+tmnYuQl0pFU1ibYJQ5BGhTVB08bHe9wC8qUeG7c08dj9XX+AuPj1YSGSQIHl1pnDHZR0Q=="
|
|
1794
|
+
"resolved" "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-8.5.0.tgz"
|
|
1795
|
+
"version" "8.5.0"
|
|
1796
|
+
|
|
1792
1797
|
"eslint-import-resolver-node@^0.3.6":
|
|
1793
1798
|
"integrity" "sha512-0En0w03NRVMn9Uiyn8YRPDKvWjxCWkslUEhGNTdGx15RvPJYQ+lbOlqrlNI2vEAs4pDYK4f/HN2TbDmk5TP0iw=="
|
|
1794
1799
|
"resolved" "https://registry.npmjs.org/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.6.tgz"
|
|
@@ -1849,7 +1854,7 @@
|
|
|
1849
1854
|
"resolved" "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.3.0.tgz"
|
|
1850
1855
|
"version" "3.3.0"
|
|
1851
1856
|
|
|
1852
|
-
"eslint@^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8", "eslint@^7.32.0 || ^8.2.0", "eslint@^8.12.0", "eslint@>=5":
|
|
1857
|
+
"eslint@^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8", "eslint@^7.32.0 || ^8.2.0", "eslint@^8.12.0", "eslint@>=5", "eslint@>=7.0.0":
|
|
1853
1858
|
"integrity" "sha512-it1oBL9alZg1S8UycLm5YDMAkIhtH6FtAzuZs6YvoGVldWjbS08BkAdb/ymP9LlAyq8koANu32U7Ib/w+UNh8Q=="
|
|
1854
1859
|
"resolved" "https://registry.npmjs.org/eslint/-/eslint-8.12.0.tgz"
|
|
1855
1860
|
"version" "8.12.0"
|