webflow-api 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ResponseWrapper.js +28 -0
- package/dist/Webflow.js +126 -60
- package/index.d.ts +40 -1
- package/package.json +3 -2
- package/src/ResponseWrapper.js +41 -7
- package/src/Webflow.js +139 -80
- 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,8 @@ var _WebflowError = _interopRequireWildcard(require("./WebflowError"));
|
|
|
20
20
|
var _excluded = ["collectionId"],
|
|
21
21
|
_excluded2 = ["collectionId", "itemId"],
|
|
22
22
|
_excluded3 = ["collectionId", "itemId"],
|
|
23
|
-
_excluded4 = ["siteId"]
|
|
23
|
+
_excluded4 = ["siteId", "userId"],
|
|
24
|
+
_excluded5 = ["siteId"];
|
|
24
25
|
|
|
25
26
|
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
27
|
|
|
@@ -44,7 +45,7 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
|
|
|
44
45
|
|
|
45
46
|
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
47
|
|
|
47
|
-
var DEFAULT_ENDPOINT =
|
|
48
|
+
var DEFAULT_ENDPOINT = "https://api.webflow.com";
|
|
48
49
|
|
|
49
50
|
var buildMeta = function buildMeta(res) {
|
|
50
51
|
if (!res || !res.headers) {
|
|
@@ -53,8 +54,8 @@ var buildMeta = function buildMeta(res) {
|
|
|
53
54
|
|
|
54
55
|
return {
|
|
55
56
|
rateLimit: {
|
|
56
|
-
limit: parseInt(res.headers.get(
|
|
57
|
-
remaining: parseInt(res.headers.get(
|
|
57
|
+
limit: parseInt(res.headers.get("x-ratelimit-limit"), 10),
|
|
58
|
+
remaining: parseInt(res.headers.get("x-ratelimit-remaining"), 10)
|
|
58
59
|
}
|
|
59
60
|
};
|
|
60
61
|
};
|
|
@@ -77,7 +78,7 @@ var responseHandler = function responseHandler(res) {
|
|
|
77
78
|
errOpts.problems = body.problems;
|
|
78
79
|
}
|
|
79
80
|
|
|
80
|
-
var errMsg = body && body.err ? body.err :
|
|
81
|
+
var errMsg = body && body.err ? body.err : "Unknown error occured";
|
|
81
82
|
var err = new _WebflowError["default"](errMsg);
|
|
82
83
|
return Promise.reject(Object.assign(err, errOpts));
|
|
83
84
|
}
|
|
@@ -97,28 +98,28 @@ var Webflow = /*#__PURE__*/function () {
|
|
|
97
98
|
endpoint = _ref$endpoint === void 0 ? DEFAULT_ENDPOINT : _ref$endpoint,
|
|
98
99
|
token = _ref.token,
|
|
99
100
|
_ref$version = _ref.version,
|
|
100
|
-
version = _ref$version === void 0 ?
|
|
101
|
+
version = _ref$version === void 0 ? "1.0.0" : _ref$version;
|
|
101
102
|
|
|
102
103
|
_classCallCheck(this, Webflow);
|
|
103
104
|
|
|
104
|
-
if (!token) throw (0, _WebflowError.buildRequiredArgError)(
|
|
105
|
+
if (!token) throw (0, _WebflowError.buildRequiredArgError)("token");
|
|
105
106
|
this.responseWrapper = new _ResponseWrapper["default"](this);
|
|
106
107
|
this.endpoint = endpoint;
|
|
107
108
|
this.token = token;
|
|
108
109
|
this.headers = {
|
|
109
|
-
Accept:
|
|
110
|
+
Accept: "application/json",
|
|
110
111
|
Authorization: "Bearer ".concat(token),
|
|
111
|
-
|
|
112
|
-
|
|
112
|
+
"accept-version": version,
|
|
113
|
+
"Content-Type": "application/json"
|
|
113
114
|
};
|
|
114
115
|
|
|
115
116
|
this.authenticatedFetch = function (method, path, data, query) {
|
|
116
|
-
var queryString = query && !(0, _utils.isObjectEmpty)(query) ? "?".concat(_qs["default"].stringify(query)) :
|
|
117
|
+
var queryString = query && !(0, _utils.isObjectEmpty)(query) ? "?".concat(_qs["default"].stringify(query)) : "";
|
|
117
118
|
var uri = "".concat(_this.endpoint).concat(path).concat(queryString);
|
|
118
119
|
var opts = {
|
|
119
120
|
method: method,
|
|
120
121
|
headers: _this.headers,
|
|
121
|
-
mode:
|
|
122
|
+
mode: "cors"
|
|
122
123
|
};
|
|
123
124
|
|
|
124
125
|
if (data) {
|
|
@@ -134,38 +135,38 @@ var Webflow = /*#__PURE__*/function () {
|
|
|
134
135
|
key: "get",
|
|
135
136
|
value: function get(path) {
|
|
136
137
|
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
137
|
-
return this.authenticatedFetch(
|
|
138
|
+
return this.authenticatedFetch("GET", path, null, query);
|
|
138
139
|
}
|
|
139
140
|
}, {
|
|
140
141
|
key: "post",
|
|
141
142
|
value: function post(path, data) {
|
|
142
143
|
var query = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
143
|
-
return this.authenticatedFetch(
|
|
144
|
+
return this.authenticatedFetch("POST", path, data, query);
|
|
144
145
|
}
|
|
145
146
|
}, {
|
|
146
147
|
key: "put",
|
|
147
148
|
value: function put(path, data) {
|
|
148
149
|
var query = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
149
|
-
return this.authenticatedFetch(
|
|
150
|
+
return this.authenticatedFetch("PUT", path, data, query);
|
|
150
151
|
}
|
|
151
152
|
}, {
|
|
152
153
|
key: "patch",
|
|
153
154
|
value: function patch(path, data) {
|
|
154
155
|
var query = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
155
|
-
return this.authenticatedFetch(
|
|
156
|
+
return this.authenticatedFetch("PATCH", path, data, query);
|
|
156
157
|
}
|
|
157
158
|
}, {
|
|
158
159
|
key: "delete",
|
|
159
160
|
value: function _delete(path) {
|
|
160
161
|
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
161
|
-
return this.authenticatedFetch(
|
|
162
|
+
return this.authenticatedFetch("DELETE", path, null, query);
|
|
162
163
|
} // Meta
|
|
163
164
|
|
|
164
165
|
}, {
|
|
165
166
|
key: "info",
|
|
166
167
|
value: function info() {
|
|
167
168
|
var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
168
|
-
return this.get(
|
|
169
|
+
return this.get("/info", query);
|
|
169
170
|
} // Sites
|
|
170
171
|
|
|
171
172
|
}, {
|
|
@@ -174,7 +175,7 @@ var Webflow = /*#__PURE__*/function () {
|
|
|
174
175
|
var _this2 = this;
|
|
175
176
|
|
|
176
177
|
var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
177
|
-
return this.get(
|
|
178
|
+
return this.get("/sites", query).then(function (sites) {
|
|
178
179
|
return sites.map(function (site) {
|
|
179
180
|
return _this2.responseWrapper.site(site);
|
|
180
181
|
});
|
|
@@ -187,7 +188,7 @@ var Webflow = /*#__PURE__*/function () {
|
|
|
187
188
|
|
|
188
189
|
var siteId = _ref2.siteId;
|
|
189
190
|
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
190
|
-
if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)(
|
|
191
|
+
if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("siteId"));
|
|
191
192
|
return this.get("/sites/".concat(siteId), query).then(function (site) {
|
|
192
193
|
return _this3.responseWrapper.site(site);
|
|
193
194
|
});
|
|
@@ -197,8 +198,8 @@ var Webflow = /*#__PURE__*/function () {
|
|
|
197
198
|
value: function publishSite(_ref3) {
|
|
198
199
|
var siteId = _ref3.siteId,
|
|
199
200
|
domains = _ref3.domains;
|
|
200
|
-
if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)(
|
|
201
|
-
if (!domains) return Promise.reject((0, _WebflowError.buildRequiredArgError)(
|
|
201
|
+
if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("siteId"));
|
|
202
|
+
if (!domains) return Promise.reject((0, _WebflowError.buildRequiredArgError)("domains"));
|
|
202
203
|
return this.post("/sites/".concat(siteId, "/publish"), {
|
|
203
204
|
domains: domains
|
|
204
205
|
});
|
|
@@ -210,7 +211,7 @@ var Webflow = /*#__PURE__*/function () {
|
|
|
210
211
|
var _this4 = this;
|
|
211
212
|
|
|
212
213
|
var siteId = _ref4.siteId;
|
|
213
|
-
if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)(
|
|
214
|
+
if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("siteId"));
|
|
214
215
|
return this.get("/sites/".concat(siteId, "/domains")).then(function (domains) {
|
|
215
216
|
return domains.map(function (domain) {
|
|
216
217
|
return _this4.responseWrapper.domain(domain, siteId);
|
|
@@ -225,7 +226,7 @@ var Webflow = /*#__PURE__*/function () {
|
|
|
225
226
|
|
|
226
227
|
var siteId = _ref5.siteId;
|
|
227
228
|
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
228
|
-
if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)(
|
|
229
|
+
if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("siteId"));
|
|
229
230
|
return this.get("/sites/".concat(siteId, "/collections"), query).then(function (collections) {
|
|
230
231
|
return collections.map(function (collection) {
|
|
231
232
|
return _this5.responseWrapper.collection(collection);
|
|
@@ -239,7 +240,7 @@ var Webflow = /*#__PURE__*/function () {
|
|
|
239
240
|
|
|
240
241
|
var collectionId = _ref6.collectionId;
|
|
241
242
|
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
242
|
-
if (!collectionId) return Promise.reject((0, _WebflowError.buildRequiredArgError)(
|
|
243
|
+
if (!collectionId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("collectionId"));
|
|
243
244
|
return this.get("/collections/".concat(collectionId), query).then(function (collection) {
|
|
244
245
|
return _this6.responseWrapper.collection(collection);
|
|
245
246
|
});
|
|
@@ -252,7 +253,7 @@ var Webflow = /*#__PURE__*/function () {
|
|
|
252
253
|
|
|
253
254
|
var collectionId = _ref7.collectionId;
|
|
254
255
|
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
255
|
-
if (!collectionId) return Promise.reject((0, _WebflowError.buildRequiredArgError)(
|
|
256
|
+
if (!collectionId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("collectionId"));
|
|
256
257
|
return this.get("/collections/".concat(collectionId, "/items"), query).then(function (res) {
|
|
257
258
|
return _objectSpread(_objectSpread({}, res), {}, {
|
|
258
259
|
items: res.items.map(function (item) {
|
|
@@ -269,8 +270,8 @@ var Webflow = /*#__PURE__*/function () {
|
|
|
269
270
|
var collectionId = _ref8.collectionId,
|
|
270
271
|
itemId = _ref8.itemId;
|
|
271
272
|
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)(
|
|
273
|
+
if (!collectionId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("collectionId"));
|
|
274
|
+
if (!itemId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("itemId"));
|
|
274
275
|
return this.get("/collections/".concat(collectionId, "/items/").concat(itemId), query).then(function (res) {
|
|
275
276
|
return _this8.responseWrapper.item(res.items[0], collectionId);
|
|
276
277
|
});
|
|
@@ -284,7 +285,7 @@ var Webflow = /*#__PURE__*/function () {
|
|
|
284
285
|
data = _objectWithoutProperties(_ref9, _excluded);
|
|
285
286
|
|
|
286
287
|
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
287
|
-
if (!collectionId) return Promise.reject((0, _WebflowError.buildRequiredArgError)(
|
|
288
|
+
if (!collectionId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("collectionId"));
|
|
288
289
|
return this.post("/collections/".concat(collectionId, "/items"), data, query).then(function (item) {
|
|
289
290
|
return _this9.responseWrapper.item(item, collectionId);
|
|
290
291
|
});
|
|
@@ -297,8 +298,8 @@ var Webflow = /*#__PURE__*/function () {
|
|
|
297
298
|
data = _objectWithoutProperties(_ref10, _excluded2);
|
|
298
299
|
|
|
299
300
|
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)(
|
|
301
|
+
if (!collectionId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("collectionId"));
|
|
302
|
+
if (!itemId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("itemId"));
|
|
302
303
|
return this.put("/collections/".concat(collectionId, "/items/").concat(itemId), data, query);
|
|
303
304
|
}
|
|
304
305
|
}, {
|
|
@@ -307,8 +308,8 @@ var Webflow = /*#__PURE__*/function () {
|
|
|
307
308
|
var collectionId = _ref11.collectionId,
|
|
308
309
|
itemId = _ref11.itemId;
|
|
309
310
|
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)(
|
|
311
|
+
if (!collectionId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("collectionId"));
|
|
312
|
+
if (!itemId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("itemId"));
|
|
312
313
|
return this["delete"]("/collections/".concat(collectionId, "/items/").concat(itemId), query);
|
|
313
314
|
}
|
|
314
315
|
}, {
|
|
@@ -319,63 +320,128 @@ var Webflow = /*#__PURE__*/function () {
|
|
|
319
320
|
data = _objectWithoutProperties(_ref12, _excluded3);
|
|
320
321
|
|
|
321
322
|
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)(
|
|
323
|
+
if (!collectionId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("collectionId"));
|
|
324
|
+
if (!itemId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("itemId"));
|
|
324
325
|
return this.patch("/collections/".concat(collectionId, "/items/").concat(itemId), data, query);
|
|
325
|
-
} //
|
|
326
|
-
// TODO
|
|
327
|
-
// Webhooks
|
|
326
|
+
} // Users
|
|
328
327
|
|
|
329
328
|
}, {
|
|
330
|
-
key: "
|
|
331
|
-
value: function
|
|
329
|
+
key: "users",
|
|
330
|
+
value: function users(_ref13) {
|
|
332
331
|
var _this10 = this;
|
|
333
332
|
|
|
334
333
|
var siteId = _ref13.siteId;
|
|
335
334
|
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
336
|
-
if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)(
|
|
335
|
+
if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("siteId"));
|
|
336
|
+
return this.get("/sites/".concat(siteId, "/users"), query).then(function (res) {
|
|
337
|
+
return res.users.map(function (user) {
|
|
338
|
+
return _this10.responseWrapper.user(user);
|
|
339
|
+
});
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
}, {
|
|
343
|
+
key: "user",
|
|
344
|
+
value: function user(_ref14) {
|
|
345
|
+
var _this11 = this;
|
|
346
|
+
|
|
347
|
+
var siteId = _ref14.siteId,
|
|
348
|
+
userId = _ref14.userId;
|
|
349
|
+
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
350
|
+
if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("siteId"));
|
|
351
|
+
if (!userId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("userId"));
|
|
352
|
+
return this.get("/sites/".concat(siteId, "/users/").concat(userId), query).then(function (user) {
|
|
353
|
+
return _this11.responseWrapper.user(user, siteId);
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
}, {
|
|
357
|
+
key: "updateUser",
|
|
358
|
+
value: function updateUser(_ref15) {
|
|
359
|
+
var siteId = _ref15.siteId,
|
|
360
|
+
userId = _ref15.userId,
|
|
361
|
+
data = _objectWithoutProperties(_ref15, _excluded4);
|
|
362
|
+
|
|
363
|
+
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
364
|
+
if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("siteId"));
|
|
365
|
+
if (!userId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("userId"));
|
|
366
|
+
return this.patch("/sites/".concat(siteId, "/users/").concat(userId), data, query);
|
|
367
|
+
}
|
|
368
|
+
}, {
|
|
369
|
+
key: "inviteUser",
|
|
370
|
+
value: function inviteUser(_ref16) {
|
|
371
|
+
var _this12 = this;
|
|
372
|
+
|
|
373
|
+
var siteId = _ref16.siteId,
|
|
374
|
+
email = _ref16.email;
|
|
375
|
+
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
376
|
+
if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("siteId"));
|
|
377
|
+
if (!email) return Promise.reject((0, _WebflowError.buildRequiredArgError)("email"));
|
|
378
|
+
return this.post("/sites/".concat(siteId, "/users/invite"), {
|
|
379
|
+
email: email
|
|
380
|
+
}, query).then(function (user) {
|
|
381
|
+
return _this12.responseWrapper.user(user, siteId);
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
}, {
|
|
385
|
+
key: "removeUser",
|
|
386
|
+
value: function removeUser(_ref17) {
|
|
387
|
+
var siteId = _ref17.siteId,
|
|
388
|
+
userId = _ref17.userId;
|
|
389
|
+
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
390
|
+
if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("siteId"));
|
|
391
|
+
if (!userId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("userId"));
|
|
392
|
+
return this["delete"]("/sites/".concat(siteId, "/users/").concat(userId), query);
|
|
393
|
+
} // Webhooks
|
|
394
|
+
|
|
395
|
+
}, {
|
|
396
|
+
key: "webhooks",
|
|
397
|
+
value: function webhooks(_ref18) {
|
|
398
|
+
var _this13 = this;
|
|
399
|
+
|
|
400
|
+
var siteId = _ref18.siteId;
|
|
401
|
+
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
402
|
+
if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("siteId"));
|
|
337
403
|
return this.get("/sites/".concat(siteId, "/webhooks"), query).then(function (webhooks) {
|
|
338
404
|
return webhooks.map(function (webhook) {
|
|
339
|
-
return
|
|
405
|
+
return _this13.responseWrapper.webhook(webhook, siteId);
|
|
340
406
|
});
|
|
341
407
|
});
|
|
342
408
|
}
|
|
343
409
|
}, {
|
|
344
410
|
key: "webhook",
|
|
345
|
-
value: function webhook(
|
|
346
|
-
var
|
|
411
|
+
value: function webhook(_ref19) {
|
|
412
|
+
var _this14 = this;
|
|
347
413
|
|
|
348
|
-
var siteId =
|
|
349
|
-
webhookId =
|
|
414
|
+
var siteId = _ref19.siteId,
|
|
415
|
+
webhookId = _ref19.webhookId;
|
|
350
416
|
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)(
|
|
417
|
+
if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("siteId"));
|
|
418
|
+
if (!webhookId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("webhookId"));
|
|
353
419
|
return this.get("/sites/".concat(siteId, "/webhooks/").concat(webhookId), query).then(function (webhook) {
|
|
354
|
-
return
|
|
420
|
+
return _this14.responseWrapper.webhook(webhook, siteId);
|
|
355
421
|
});
|
|
356
422
|
}
|
|
357
423
|
}, {
|
|
358
424
|
key: "createWebhook",
|
|
359
|
-
value: function createWebhook(
|
|
360
|
-
var
|
|
425
|
+
value: function createWebhook(_ref20) {
|
|
426
|
+
var _this15 = this;
|
|
361
427
|
|
|
362
|
-
var siteId =
|
|
363
|
-
data = _objectWithoutProperties(
|
|
428
|
+
var siteId = _ref20.siteId,
|
|
429
|
+
data = _objectWithoutProperties(_ref20, _excluded5);
|
|
364
430
|
|
|
365
431
|
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
366
|
-
if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)(
|
|
432
|
+
if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("siteId"));
|
|
367
433
|
return this.post("/sites/".concat(siteId, "/webhooks"), data, query).then(function (webhook) {
|
|
368
|
-
return
|
|
434
|
+
return _this15.responseWrapper.webhook(webhook, siteId);
|
|
369
435
|
});
|
|
370
436
|
}
|
|
371
437
|
}, {
|
|
372
438
|
key: "removeWebhook",
|
|
373
|
-
value: function removeWebhook(
|
|
374
|
-
var siteId =
|
|
375
|
-
webhookId =
|
|
439
|
+
value: function removeWebhook(_ref21) {
|
|
440
|
+
var siteId = _ref21.siteId,
|
|
441
|
+
webhookId = _ref21.webhookId;
|
|
376
442
|
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)(
|
|
443
|
+
if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("siteId"));
|
|
444
|
+
if (!webhookId) return Promise.reject((0, _WebflowError.buildRequiredArgError)("webhookId"));
|
|
379
445
|
return this["delete"]("/sites/".concat(siteId, "/webhooks/").concat(webhookId), query);
|
|
380
446
|
}
|
|
381
447
|
}]);
|
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.0",
|
|
4
4
|
"description": "SDK for the Webflow CMS API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"jsnext:main": "src/index.js",
|
|
@@ -32,14 +32,15 @@
|
|
|
32
32
|
"@babel/preset-env": "^7.16.11",
|
|
33
33
|
"@babel/register": "^7.17.7",
|
|
34
34
|
"ava": "^4.1.0",
|
|
35
|
-
"es6-error": "^4.0.0",
|
|
36
35
|
"eslint": "^8.12.0",
|
|
37
36
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
37
|
+
"eslint-config-prettier": "^8.5.0",
|
|
38
38
|
"eslint-plugin-import": "^2.25.2",
|
|
39
39
|
"nock": "^13.0.7",
|
|
40
40
|
"nyc": "^15.1.0"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
+
"es6-error": "^4.0.0",
|
|
43
44
|
"isomorphic-fetch": "^3.0.0",
|
|
44
45
|
"qs": "^6.3.0"
|
|
45
46
|
},
|
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
107
|
delete(path, query = {}) {
|
|
110
|
-
return this.authenticatedFetch(
|
|
108
|
+
return this.authenticatedFetch("DELETE", path, null, 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,117 +140,174 @@ 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
|
-
|
|
220
|
+
if (!collectionId)
|
|
221
|
+
return Promise.reject(buildRequiredArgError("collectionId"));
|
|
222
|
+
if (!itemId) return Promise.reject(buildRequiredArgError("itemId"));
|
|
207
223
|
|
|
208
224
|
return this.delete(`/collections/${collectionId}/items/${itemId}`, query);
|
|
209
225
|
}
|
|
210
226
|
|
|
211
227
|
patchItem({ collectionId, itemId, ...data }, query = {}) {
|
|
212
|
-
if (!collectionId)
|
|
213
|
-
|
|
228
|
+
if (!collectionId)
|
|
229
|
+
return Promise.reject(buildRequiredArgError("collectionId"));
|
|
230
|
+
if (!itemId) return Promise.reject(buildRequiredArgError("itemId"));
|
|
231
|
+
|
|
232
|
+
return this.patch(
|
|
233
|
+
`/collections/${collectionId}/items/${itemId}`,
|
|
234
|
+
data,
|
|
235
|
+
query
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// Users
|
|
240
|
+
|
|
241
|
+
users({ siteId }, query = {}) {
|
|
242
|
+
if (!siteId) return Promise.reject(buildRequiredArgError("siteId"));
|
|
243
|
+
|
|
244
|
+
return this.get(`/sites/${siteId}/users`, query).then((res) =>
|
|
245
|
+
res.users.map((user) => this.responseWrapper.user(user))
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
user({ siteId, userId }, query = {}) {
|
|
250
|
+
if (!siteId) return Promise.reject(buildRequiredArgError("siteId"));
|
|
251
|
+
if (!userId) return Promise.reject(buildRequiredArgError("userId"));
|
|
252
|
+
|
|
253
|
+
return this.get(`/sites/${siteId}/users/${userId}`, query).then((user) =>
|
|
254
|
+
this.responseWrapper.user(user, siteId)
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
updateUser({ siteId, userId, ...data }, query = {}) {
|
|
259
|
+
if (!siteId) return Promise.reject(buildRequiredArgError("siteId"));
|
|
260
|
+
if (!userId) return Promise.reject(buildRequiredArgError("userId"));
|
|
214
261
|
|
|
215
|
-
return this.patch(`/
|
|
262
|
+
return this.patch(`/sites/${siteId}/users/${userId}`, data, query);
|
|
216
263
|
}
|
|
217
264
|
|
|
218
|
-
|
|
265
|
+
inviteUser({ siteId, email }, query = {}) {
|
|
266
|
+
if (!siteId) return Promise.reject(buildRequiredArgError("siteId"));
|
|
267
|
+
if (!email) return Promise.reject(buildRequiredArgError("email"));
|
|
219
268
|
|
|
220
|
-
|
|
269
|
+
return this.post(`/sites/${siteId}/users/invite`, { email }, query).then(
|
|
270
|
+
(user) => this.responseWrapper.user(user, siteId)
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
removeUser({ siteId, userId }, query = {}) {
|
|
275
|
+
if (!siteId) return Promise.reject(buildRequiredArgError("siteId"));
|
|
276
|
+
if (!userId) return Promise.reject(buildRequiredArgError("userId"));
|
|
277
|
+
|
|
278
|
+
return this.delete(`/sites/${siteId}/users/${userId}`, query);
|
|
279
|
+
}
|
|
221
280
|
|
|
222
281
|
// Webhooks
|
|
223
282
|
|
|
224
283
|
webhooks({ siteId }, query = {}) {
|
|
225
|
-
if (!siteId) return Promise.reject(buildRequiredArgError(
|
|
284
|
+
if (!siteId) return Promise.reject(buildRequiredArgError("siteId"));
|
|
226
285
|
|
|
227
|
-
return this.get(`/sites/${siteId}/webhooks`, query).then(
|
|
228
|
-
webhooks
|
|
286
|
+
return this.get(`/sites/${siteId}/webhooks`, query).then((webhooks) =>
|
|
287
|
+
webhooks.map((webhook) => this.responseWrapper.webhook(webhook, siteId))
|
|
229
288
|
);
|
|
230
289
|
}
|
|
231
290
|
|
|
232
291
|
webhook({ siteId, webhookId }, query = {}) {
|
|
233
|
-
if (!siteId) return Promise.reject(buildRequiredArgError(
|
|
234
|
-
if (!webhookId) return Promise.reject(buildRequiredArgError(
|
|
292
|
+
if (!siteId) return Promise.reject(buildRequiredArgError("siteId"));
|
|
293
|
+
if (!webhookId) return Promise.reject(buildRequiredArgError("webhookId"));
|
|
235
294
|
|
|
236
295
|
return this.get(`/sites/${siteId}/webhooks/${webhookId}`, query).then(
|
|
237
|
-
webhook => this.responseWrapper.webhook(webhook, siteId)
|
|
296
|
+
(webhook) => this.responseWrapper.webhook(webhook, siteId)
|
|
238
297
|
);
|
|
239
298
|
}
|
|
240
299
|
|
|
241
300
|
createWebhook({ siteId, ...data }, query = {}) {
|
|
242
|
-
if (!siteId) return Promise.reject(buildRequiredArgError(
|
|
301
|
+
if (!siteId) return Promise.reject(buildRequiredArgError("siteId"));
|
|
243
302
|
|
|
244
|
-
return this.post(`/sites/${siteId}/webhooks`, data, query).then(
|
|
245
|
-
|
|
303
|
+
return this.post(`/sites/${siteId}/webhooks`, data, query).then((webhook) =>
|
|
304
|
+
this.responseWrapper.webhook(webhook, siteId)
|
|
246
305
|
);
|
|
247
306
|
}
|
|
248
307
|
|
|
249
308
|
removeWebhook({ siteId, webhookId }, query = {}) {
|
|
250
|
-
if (!siteId) return Promise.reject(buildRequiredArgError(
|
|
251
|
-
if (!webhookId) return Promise.reject(buildRequiredArgError(
|
|
309
|
+
if (!siteId) return Promise.reject(buildRequiredArgError("siteId"));
|
|
310
|
+
if (!webhookId) return Promise.reject(buildRequiredArgError("webhookId"));
|
|
252
311
|
|
|
253
312
|
return this.delete(`/sites/${siteId}/webhooks/${webhookId}`, query);
|
|
254
313
|
}
|
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"
|