webflow-api 0.5.4
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/LICENSE +21 -0
- package/README.md +44 -0
- package/dist/ResponseWrapper.js +140 -0
- package/dist/Webflow.js +432 -0
- package/dist/WebflowError.js +35 -0
- package/dist/index.js +4 -0
- package/dist/utils.js +24 -0
- package/package.json +54 -0
- package/src/ResponseWrapper.js +72 -0
- package/src/Webflow.js +255 -0
- package/src/WebflowError.js +6 -0
- package/src/index.js +2 -0
- package/src/utils.js +13 -0
- package/yarn.lock +3669 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Copyright (c) 2016 Webflow, Inc
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person ob-
|
|
4
|
+
taining a copy of this software and associated documentation
|
|
5
|
+
files (the "Software"), to deal in the Software without restric-
|
|
6
|
+
tion, including without limitation the rights to use, copy, modi-
|
|
7
|
+
fy, merge, publish, distribute, sublicense, and/or sell copies of
|
|
8
|
+
the Software, and to permit persons to whom the Software is fur-
|
|
9
|
+
nished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
16
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONIN-
|
|
17
|
+
FRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
19
|
+
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Webflow CMS API Client
|
|
2
|
+
|
|
3
|
+
## Requirements
|
|
4
|
+
|
|
5
|
+
* Node.js 4+
|
|
6
|
+
* NPM / YARN
|
|
7
|
+
* Webpack / Browserify (optional)
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
Install the package via NPM or YARN:
|
|
12
|
+
|
|
13
|
+
```shell
|
|
14
|
+
$ npm install --save webflow-api
|
|
15
|
+
|
|
16
|
+
$ yarn add webflow-api
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```javascript
|
|
22
|
+
const Webflow = require('webflow-api');
|
|
23
|
+
|
|
24
|
+
// Initialize the API
|
|
25
|
+
const api = new Webflow({ token: 'api-token' });
|
|
26
|
+
|
|
27
|
+
// Fetch a site
|
|
28
|
+
api.site({ siteId: '580e63e98c9a982ac9b8b741' }).then(site => console.log(site));
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
The `Webflow` constructor takes several options to initialize the API client:
|
|
32
|
+
|
|
33
|
+
* `token` - the API token **(required)**
|
|
34
|
+
* `version` - the version of the API you wish to use (optional)
|
|
35
|
+
|
|
36
|
+
All of the API methods are documented in the [API documentation](https://developers.webflow.com).
|
|
37
|
+
|
|
38
|
+
## Contributing
|
|
39
|
+
|
|
40
|
+
Contributions are welcome - feel free to open an issue or pull request.
|
|
41
|
+
|
|
42
|
+
## License
|
|
43
|
+
|
|
44
|
+
The MIT license - see `LICENSE`.
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
|
8
|
+
|
|
9
|
+
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
10
|
+
|
|
11
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
12
|
+
|
|
13
|
+
var ResponseWrapper = function () {
|
|
14
|
+
function ResponseWrapper(api) {
|
|
15
|
+
_classCallCheck(this, ResponseWrapper);
|
|
16
|
+
|
|
17
|
+
this.api = api;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
_createClass(ResponseWrapper, [{
|
|
21
|
+
key: "site",
|
|
22
|
+
value: function site(_site) {
|
|
23
|
+
return _extends({}, _site, {
|
|
24
|
+
|
|
25
|
+
collections: this.api.collections.bind(this.api, { siteId: _site._id }),
|
|
26
|
+
webhooks: this.api.webhooks.bind(this.api, { siteId: _site._id }),
|
|
27
|
+
domains: this.api.domains.bind(this.api, { siteId: _site._id }),
|
|
28
|
+
webhook: function webhook(first) {
|
|
29
|
+
var _api;
|
|
30
|
+
|
|
31
|
+
for (var _len = arguments.length, rest = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
32
|
+
rest[_key - 1] = arguments[_key];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return (_api = this.api).webhook.apply(_api, [_extends({}, first, { siteId: _site._id })].concat(rest));
|
|
36
|
+
},
|
|
37
|
+
createWebhook: function createWebhook(first) {
|
|
38
|
+
var _api2;
|
|
39
|
+
|
|
40
|
+
for (var _len2 = arguments.length, rest = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
41
|
+
rest[_key2 - 1] = arguments[_key2];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return (_api2 = this.api).createWebhook.apply(_api2, [_extends({}, first, { siteId: _site._id })].concat(rest));
|
|
45
|
+
},
|
|
46
|
+
removeWebhook: function removeWebhook(first) {
|
|
47
|
+
var _api3;
|
|
48
|
+
|
|
49
|
+
for (var _len3 = arguments.length, rest = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
|
50
|
+
rest[_key3 - 1] = arguments[_key3];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return (_api3 = this.api).removeWebhook.apply(_api3, [_extends({}, first, { siteId: _site._id })].concat(rest));
|
|
54
|
+
},
|
|
55
|
+
publishSite: function publishSite(domains) {
|
|
56
|
+
return this.api.publishSite({ siteId: _site._id, domains: domains });
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}, {
|
|
61
|
+
key: "domain",
|
|
62
|
+
value: function domain(_domain) {
|
|
63
|
+
return _extends({}, _domain);
|
|
64
|
+
}
|
|
65
|
+
}, {
|
|
66
|
+
key: "collection",
|
|
67
|
+
value: function collection(_collection) {
|
|
68
|
+
return _extends({}, _collection, {
|
|
69
|
+
|
|
70
|
+
items: this.api.items.bind(this.api, { collectionId: _collection._id }),
|
|
71
|
+
item: function item(first) {
|
|
72
|
+
var _api4;
|
|
73
|
+
|
|
74
|
+
for (var _len4 = arguments.length, rest = Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
|
|
75
|
+
rest[_key4 - 1] = arguments[_key4];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return (_api4 = this.api).item.apply(_api4, [_extends({}, first, { collectionId: _collection._id })].concat(rest));
|
|
79
|
+
},
|
|
80
|
+
createItem: function createItem(first) {
|
|
81
|
+
var _api5;
|
|
82
|
+
|
|
83
|
+
for (var _len5 = arguments.length, rest = Array(_len5 > 1 ? _len5 - 1 : 0), _key5 = 1; _key5 < _len5; _key5++) {
|
|
84
|
+
rest[_key5 - 1] = arguments[_key5];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return (_api5 = this.api).createItem.apply(_api5, [_extends({}, first, { collectionId: _collection._id })].concat(rest));
|
|
88
|
+
},
|
|
89
|
+
updateItem: function updateItem(first) {
|
|
90
|
+
var _api6;
|
|
91
|
+
|
|
92
|
+
for (var _len6 = arguments.length, rest = Array(_len6 > 1 ? _len6 - 1 : 0), _key6 = 1; _key6 < _len6; _key6++) {
|
|
93
|
+
rest[_key6 - 1] = arguments[_key6];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return (_api6 = this.api).updateItem.apply(_api6, [_extends({}, first, { collectionId: _collection._id })].concat(rest));
|
|
97
|
+
},
|
|
98
|
+
removeItem: function removeItem(first) {
|
|
99
|
+
var _api7;
|
|
100
|
+
|
|
101
|
+
for (var _len7 = arguments.length, rest = Array(_len7 > 1 ? _len7 - 1 : 0), _key7 = 1; _key7 < _len7; _key7++) {
|
|
102
|
+
rest[_key7 - 1] = arguments[_key7];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return (_api7 = this.api).removeItem.apply(_api7, [_extends({}, first, { collectionId: _collection._id })].concat(rest));
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}, {
|
|
110
|
+
key: "item",
|
|
111
|
+
value: function item(_item, collectionId) {
|
|
112
|
+
return _extends({}, _item, {
|
|
113
|
+
update: function update(first) {
|
|
114
|
+
var _api8;
|
|
115
|
+
|
|
116
|
+
for (var _len8 = arguments.length, rest = Array(_len8 > 1 ? _len8 - 1 : 0), _key8 = 1; _key8 < _len8; _key8++) {
|
|
117
|
+
rest[_key8 - 1] = arguments[_key8];
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return (_api8 = this.api).updateItem.apply(_api8, [_extends({}, first, { collectionId: collectionId, itemId: _item._id })].concat(rest));
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
remove: this.api.updateItem.bind(this.api, { collectionId: collectionId, itemId: _item._id })
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}, {
|
|
127
|
+
key: "webhook",
|
|
128
|
+
value: function webhook(_webhook, siteId) {
|
|
129
|
+
return _extends({}, _webhook, {
|
|
130
|
+
|
|
131
|
+
remove: this.api.removeWebhook.bind(this.api, { siteId: siteId, webhookId: _webhook._id })
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}]);
|
|
135
|
+
|
|
136
|
+
return ResponseWrapper;
|
|
137
|
+
}();
|
|
138
|
+
|
|
139
|
+
exports.default = ResponseWrapper;
|
|
140
|
+
module.exports = exports["default"];
|
package/dist/Webflow.js
ADDED
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
|
8
|
+
|
|
9
|
+
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
10
|
+
|
|
11
|
+
var _isomorphicFetch = require('isomorphic-fetch');
|
|
12
|
+
|
|
13
|
+
var _isomorphicFetch2 = _interopRequireDefault(_isomorphicFetch);
|
|
14
|
+
|
|
15
|
+
var _qs = require('qs');
|
|
16
|
+
|
|
17
|
+
var _qs2 = _interopRequireDefault(_qs);
|
|
18
|
+
|
|
19
|
+
var _utils = require('./utils');
|
|
20
|
+
|
|
21
|
+
var _ResponseWrapper = require('./ResponseWrapper');
|
|
22
|
+
|
|
23
|
+
var _ResponseWrapper2 = _interopRequireDefault(_ResponseWrapper);
|
|
24
|
+
|
|
25
|
+
var _WebflowError = require('./WebflowError');
|
|
26
|
+
|
|
27
|
+
var _WebflowError2 = _interopRequireDefault(_WebflowError);
|
|
28
|
+
|
|
29
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
30
|
+
|
|
31
|
+
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
|
|
32
|
+
|
|
33
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
34
|
+
|
|
35
|
+
var DEFAULT_ENDPOINT = 'https://api.webflow.com';
|
|
36
|
+
|
|
37
|
+
var buildMeta = function buildMeta(res) {
|
|
38
|
+
if (!res || !res.headers) {
|
|
39
|
+
return {};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
rateLimit: {
|
|
44
|
+
limit: parseInt(res.headers.get('x-ratelimit-limit'), 10),
|
|
45
|
+
remaining: parseInt(res.headers.get('x-ratelimit-remaining'), 10)
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
var responseHandler = function responseHandler(res) {
|
|
51
|
+
return res.json().catch(function (err) {
|
|
52
|
+
return (
|
|
53
|
+
// Catch unexpected server errors where json isn't sent and rewrite
|
|
54
|
+
// with proper class (WebflowError)
|
|
55
|
+
Promise.reject(new _WebflowError2.default(err))
|
|
56
|
+
);
|
|
57
|
+
}).then(function (body) {
|
|
58
|
+
if (res.status >= 400) {
|
|
59
|
+
var errOpts = {
|
|
60
|
+
code: body.code,
|
|
61
|
+
msg: body.msg,
|
|
62
|
+
_meta: buildMeta(res)
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
if (body.problems && body.problems.length > 0) {
|
|
66
|
+
errOpts.problems = body.problems;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
var errMsg = body && body.err ? body.err : 'Unknown error occured';
|
|
70
|
+
var err = new _WebflowError2.default(errMsg);
|
|
71
|
+
|
|
72
|
+
return Promise.reject(Object.assign(err, errOpts));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
body._meta = buildMeta(res); // eslint-disable-line no-param-reassign
|
|
76
|
+
|
|
77
|
+
return body;
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
var Webflow = function () {
|
|
82
|
+
function Webflow() {
|
|
83
|
+
var _this = this;
|
|
84
|
+
|
|
85
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
86
|
+
_ref$endpoint = _ref.endpoint,
|
|
87
|
+
endpoint = _ref$endpoint === undefined ? DEFAULT_ENDPOINT : _ref$endpoint,
|
|
88
|
+
token = _ref.token,
|
|
89
|
+
_ref$version = _ref.version,
|
|
90
|
+
version = _ref$version === undefined ? '1.0.0' : _ref$version;
|
|
91
|
+
|
|
92
|
+
_classCallCheck(this, Webflow);
|
|
93
|
+
|
|
94
|
+
if (!token) throw (0, _WebflowError.buildRequiredArgError)('token');
|
|
95
|
+
|
|
96
|
+
this.responseWrapper = new _ResponseWrapper2.default(this);
|
|
97
|
+
|
|
98
|
+
this.endpoint = endpoint;
|
|
99
|
+
this.token = token;
|
|
100
|
+
|
|
101
|
+
this.headers = {
|
|
102
|
+
Accept: 'application/json',
|
|
103
|
+
Authorization: 'Bearer ' + token,
|
|
104
|
+
'accept-version': version,
|
|
105
|
+
'Content-Type': 'application/json'
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
this.authenticatedFetch = function (method, path, data, query) {
|
|
109
|
+
var queryString = query && !(0, _utils.isObjectEmpty)(query) ? '?' + _qs2.default.stringify(query) : '';
|
|
110
|
+
|
|
111
|
+
var uri = '' + _this.endpoint + path + queryString;
|
|
112
|
+
var opts = {
|
|
113
|
+
method: method,
|
|
114
|
+
headers: _this.headers,
|
|
115
|
+
mode: 'cors'
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
if (data) {
|
|
119
|
+
opts.body = JSON.stringify(data);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return (0, _isomorphicFetch2.default)(uri, opts).then(responseHandler);
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Generic HTTP request handlers
|
|
127
|
+
|
|
128
|
+
_createClass(Webflow, [{
|
|
129
|
+
key: 'get',
|
|
130
|
+
value: function get(path) {
|
|
131
|
+
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
132
|
+
|
|
133
|
+
return this.authenticatedFetch('GET', path, false, query);
|
|
134
|
+
}
|
|
135
|
+
}, {
|
|
136
|
+
key: 'post',
|
|
137
|
+
value: function post(path, data) {
|
|
138
|
+
var query = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
139
|
+
|
|
140
|
+
return this.authenticatedFetch('POST', path, data, query);
|
|
141
|
+
}
|
|
142
|
+
}, {
|
|
143
|
+
key: 'put',
|
|
144
|
+
value: function put(path, data) {
|
|
145
|
+
var query = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
146
|
+
|
|
147
|
+
return this.authenticatedFetch('PUT', path, data, query);
|
|
148
|
+
}
|
|
149
|
+
}, {
|
|
150
|
+
key: 'patch',
|
|
151
|
+
value: function patch(path, data) {
|
|
152
|
+
var query = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
153
|
+
|
|
154
|
+
return this.authenticatedFetch('PATCH', path, data, query);
|
|
155
|
+
}
|
|
156
|
+
}, {
|
|
157
|
+
key: 'delete',
|
|
158
|
+
value: function _delete(path) {
|
|
159
|
+
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
160
|
+
|
|
161
|
+
return this.authenticatedFetch('DELETE', path, query);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Meta
|
|
165
|
+
|
|
166
|
+
}, {
|
|
167
|
+
key: 'info',
|
|
168
|
+
value: function info() {
|
|
169
|
+
var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
170
|
+
|
|
171
|
+
return this.get('/info', query);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Sites
|
|
175
|
+
|
|
176
|
+
}, {
|
|
177
|
+
key: 'sites',
|
|
178
|
+
value: function sites() {
|
|
179
|
+
var _this2 = this;
|
|
180
|
+
|
|
181
|
+
var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
182
|
+
|
|
183
|
+
return this.get('/sites', query).then(function (sites) {
|
|
184
|
+
return sites.map(function (site) {
|
|
185
|
+
return _this2.responseWrapper.site(site);
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}, {
|
|
190
|
+
key: 'site',
|
|
191
|
+
value: function site(_ref2) {
|
|
192
|
+
var _this3 = this;
|
|
193
|
+
|
|
194
|
+
var siteId = _ref2.siteId;
|
|
195
|
+
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
196
|
+
|
|
197
|
+
if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)('siteId'));
|
|
198
|
+
|
|
199
|
+
return this.get('/sites/' + siteId, query).then(function (site) {
|
|
200
|
+
return _this3.responseWrapper.site(site);
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}, {
|
|
204
|
+
key: 'publishSite',
|
|
205
|
+
value: function publishSite(_ref3) {
|
|
206
|
+
var siteId = _ref3.siteId,
|
|
207
|
+
domains = _ref3.domains;
|
|
208
|
+
|
|
209
|
+
if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)('siteId'));
|
|
210
|
+
if (!domains) return Promise.reject((0, _WebflowError.buildRequiredArgError)('domains'));
|
|
211
|
+
|
|
212
|
+
return this.post('/sites/' + siteId + '/publish', { domains: domains });
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// Domains
|
|
216
|
+
|
|
217
|
+
}, {
|
|
218
|
+
key: 'domains',
|
|
219
|
+
value: function domains(_ref4) {
|
|
220
|
+
var _this4 = this;
|
|
221
|
+
|
|
222
|
+
var siteId = _ref4.siteId;
|
|
223
|
+
|
|
224
|
+
if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)('siteId'));
|
|
225
|
+
|
|
226
|
+
return this.get('/sites/' + siteId + '/domains').then(function (domains) {
|
|
227
|
+
return domains.map(function (domain) {
|
|
228
|
+
return _this4.responseWrapper.domain(domain, siteId);
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Collections
|
|
234
|
+
|
|
235
|
+
}, {
|
|
236
|
+
key: 'collections',
|
|
237
|
+
value: function collections(_ref5) {
|
|
238
|
+
var _this5 = this;
|
|
239
|
+
|
|
240
|
+
var siteId = _ref5.siteId;
|
|
241
|
+
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
242
|
+
|
|
243
|
+
if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)('siteId'));
|
|
244
|
+
|
|
245
|
+
return this.get('/sites/' + siteId + '/collections', query).then(function (collections) {
|
|
246
|
+
return collections.map(function (collection) {
|
|
247
|
+
return _this5.responseWrapper.collection(collection);
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
}, {
|
|
252
|
+
key: 'collection',
|
|
253
|
+
value: function collection(_ref6) {
|
|
254
|
+
var _this6 = this;
|
|
255
|
+
|
|
256
|
+
var collectionId = _ref6.collectionId;
|
|
257
|
+
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
258
|
+
|
|
259
|
+
if (!collectionId) return Promise.reject((0, _WebflowError.buildRequiredArgError)('collectionId'));
|
|
260
|
+
|
|
261
|
+
return this.get('/collections/' + collectionId, query).then(function (collection) {
|
|
262
|
+
return _this6.responseWrapper.collection(collection);
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// Items
|
|
267
|
+
|
|
268
|
+
}, {
|
|
269
|
+
key: 'items',
|
|
270
|
+
value: function items(_ref7) {
|
|
271
|
+
var _this7 = this;
|
|
272
|
+
|
|
273
|
+
var collectionId = _ref7.collectionId;
|
|
274
|
+
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
275
|
+
|
|
276
|
+
if (!collectionId) return Promise.reject((0, _WebflowError.buildRequiredArgError)('collectionId'));
|
|
277
|
+
|
|
278
|
+
return this.get('/collections/' + collectionId + '/items', query).then(function (res) {
|
|
279
|
+
return _extends({}, res, {
|
|
280
|
+
|
|
281
|
+
items: res.items.map(function (item) {
|
|
282
|
+
return _this7.responseWrapper.item(item, collectionId);
|
|
283
|
+
})
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
}, {
|
|
288
|
+
key: 'item',
|
|
289
|
+
value: function item(_ref8) {
|
|
290
|
+
var _this8 = this;
|
|
291
|
+
|
|
292
|
+
var collectionId = _ref8.collectionId,
|
|
293
|
+
itemId = _ref8.itemId;
|
|
294
|
+
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
295
|
+
|
|
296
|
+
if (!collectionId) return Promise.reject((0, _WebflowError.buildRequiredArgError)('collectionId'));
|
|
297
|
+
if (!itemId) return Promise.reject((0, _WebflowError.buildRequiredArgError)('siteId'));
|
|
298
|
+
|
|
299
|
+
return this.get('/collections/' + collectionId + '/items/' + itemId, query).then(function (res) {
|
|
300
|
+
return _this8.responseWrapper.item(res.items[0], collectionId);
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
}, {
|
|
304
|
+
key: 'createItem',
|
|
305
|
+
value: function createItem(_ref9) {
|
|
306
|
+
var _this9 = this;
|
|
307
|
+
|
|
308
|
+
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
309
|
+
|
|
310
|
+
var collectionId = _ref9.collectionId,
|
|
311
|
+
data = _objectWithoutProperties(_ref9, ['collectionId']);
|
|
312
|
+
|
|
313
|
+
if (!collectionId) return Promise.reject((0, _WebflowError.buildRequiredArgError)('collectionId'));
|
|
314
|
+
|
|
315
|
+
return this.post('/collections/' + collectionId + '/items', data, query).then(function (item) {
|
|
316
|
+
return _this9.responseWrapper.item(item, collectionId);
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
}, {
|
|
320
|
+
key: 'updateItem',
|
|
321
|
+
value: function updateItem(_ref10) {
|
|
322
|
+
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
323
|
+
|
|
324
|
+
var collectionId = _ref10.collectionId,
|
|
325
|
+
itemId = _ref10.itemId,
|
|
326
|
+
data = _objectWithoutProperties(_ref10, ['collectionId', 'itemId']);
|
|
327
|
+
|
|
328
|
+
if (!collectionId) return Promise.reject((0, _WebflowError.buildRequiredArgError)('collectionId'));
|
|
329
|
+
if (!itemId) return Promise.reject((0, _WebflowError.buildRequiredArgError)('itemId'));
|
|
330
|
+
|
|
331
|
+
return this.put('/collections/' + collectionId + '/items/' + itemId, data, query);
|
|
332
|
+
}
|
|
333
|
+
}, {
|
|
334
|
+
key: 'removeItem',
|
|
335
|
+
value: function removeItem(_ref11) {
|
|
336
|
+
var collectionId = _ref11.collectionId,
|
|
337
|
+
itemId = _ref11.itemId;
|
|
338
|
+
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
339
|
+
|
|
340
|
+
if (!collectionId) return Promise.reject((0, _WebflowError.buildRequiredArgError)('collectionId'));
|
|
341
|
+
if (!itemId) return Promise.reject((0, _WebflowError.buildRequiredArgError)('itemId'));
|
|
342
|
+
|
|
343
|
+
return this.delete('/collections/' + collectionId + '/items/' + itemId, query);
|
|
344
|
+
}
|
|
345
|
+
}, {
|
|
346
|
+
key: 'patchItem',
|
|
347
|
+
value: function patchItem(_ref12) {
|
|
348
|
+
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
349
|
+
|
|
350
|
+
var collectionId = _ref12.collectionId,
|
|
351
|
+
itemId = _ref12.itemId,
|
|
352
|
+
data = _objectWithoutProperties(_ref12, ['collectionId', 'itemId']);
|
|
353
|
+
|
|
354
|
+
if (!collectionId) return Promise.reject((0, _WebflowError.buildRequiredArgError)('collectionId'));
|
|
355
|
+
if (!itemId) return Promise.reject((0, _WebflowError.buildRequiredArgError)('itemId'));
|
|
356
|
+
|
|
357
|
+
return this.patch('/collections/' + collectionId + '/items/' + itemId, data, query);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// Images
|
|
361
|
+
|
|
362
|
+
// TODO
|
|
363
|
+
|
|
364
|
+
// Webhooks
|
|
365
|
+
|
|
366
|
+
}, {
|
|
367
|
+
key: 'webhooks',
|
|
368
|
+
value: function webhooks(_ref13) {
|
|
369
|
+
var _this10 = this;
|
|
370
|
+
|
|
371
|
+
var siteId = _ref13.siteId;
|
|
372
|
+
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
373
|
+
|
|
374
|
+
if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)('siteId'));
|
|
375
|
+
|
|
376
|
+
return this.get('/sites/' + siteId + '/webhooks', query).then(function (webhooks) {
|
|
377
|
+
return webhooks.map(function (webhook) {
|
|
378
|
+
return _this10.responseWrapper.webhook(webhook, siteId);
|
|
379
|
+
});
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
}, {
|
|
383
|
+
key: 'webhook',
|
|
384
|
+
value: function webhook(_ref14) {
|
|
385
|
+
var _this11 = this;
|
|
386
|
+
|
|
387
|
+
var siteId = _ref14.siteId,
|
|
388
|
+
webhookId = _ref14.webhookId;
|
|
389
|
+
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
390
|
+
|
|
391
|
+
if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)('siteId'));
|
|
392
|
+
if (!webhookId) return Promise.reject((0, _WebflowError.buildRequiredArgError)('webhookId'));
|
|
393
|
+
|
|
394
|
+
return this.get('/sites/' + siteId + '/webhooks/' + webhookId, query).then(function (webhook) {
|
|
395
|
+
return _this11.responseWrapper.webhook(webhook, siteId);
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
}, {
|
|
399
|
+
key: 'createWebhook',
|
|
400
|
+
value: function createWebhook(_ref15) {
|
|
401
|
+
var _this12 = this;
|
|
402
|
+
|
|
403
|
+
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
404
|
+
|
|
405
|
+
var siteId = _ref15.siteId,
|
|
406
|
+
data = _objectWithoutProperties(_ref15, ['siteId']);
|
|
407
|
+
|
|
408
|
+
if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)('siteId'));
|
|
409
|
+
|
|
410
|
+
return this.post('/sites/' + siteId + '/webhooks', data, query).then(function (webhook) {
|
|
411
|
+
return _this12.responseWrapper.webhook(webhook, siteId);
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
}, {
|
|
415
|
+
key: 'removeWebhook',
|
|
416
|
+
value: function removeWebhook(_ref16) {
|
|
417
|
+
var siteId = _ref16.siteId,
|
|
418
|
+
webhookId = _ref16.webhookId;
|
|
419
|
+
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
420
|
+
|
|
421
|
+
if (!siteId) return Promise.reject((0, _WebflowError.buildRequiredArgError)('siteId'));
|
|
422
|
+
if (!webhookId) return Promise.reject((0, _WebflowError.buildRequiredArgError)('webhookId'));
|
|
423
|
+
|
|
424
|
+
return this.delete('/sites/' + siteId + '/webhooks/' + webhookId, query);
|
|
425
|
+
}
|
|
426
|
+
}]);
|
|
427
|
+
|
|
428
|
+
return Webflow;
|
|
429
|
+
}();
|
|
430
|
+
|
|
431
|
+
exports.default = Webflow;
|
|
432
|
+
module.exports = exports['default'];
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.buildRequiredArgError = undefined;
|
|
7
|
+
|
|
8
|
+
var _es6Error = require('es6-error');
|
|
9
|
+
|
|
10
|
+
var _es6Error2 = _interopRequireDefault(_es6Error);
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
15
|
+
|
|
16
|
+
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
|
17
|
+
|
|
18
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
|
19
|
+
|
|
20
|
+
var WebflowError = function (_ExtendableError) {
|
|
21
|
+
_inherits(WebflowError, _ExtendableError);
|
|
22
|
+
|
|
23
|
+
function WebflowError() {
|
|
24
|
+
_classCallCheck(this, WebflowError);
|
|
25
|
+
|
|
26
|
+
return _possibleConstructorReturn(this, (WebflowError.__proto__ || Object.getPrototypeOf(WebflowError)).apply(this, arguments));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return WebflowError;
|
|
30
|
+
}(_es6Error2.default);
|
|
31
|
+
|
|
32
|
+
exports.default = WebflowError;
|
|
33
|
+
var buildRequiredArgError = exports.buildRequiredArgError = function buildRequiredArgError(name) {
|
|
34
|
+
return new WebflowError('Argument \'' + name + '\' is required but was not present');
|
|
35
|
+
};
|
package/dist/index.js
ADDED