forked from contentstack/gatsby-source-contentstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode-helper.js
More file actions
76 lines (60 loc) · 2.46 KB
/
Copy pathnode-helper.js
File metadata and controls
76 lines (60 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
'use strict';
/** NPM dependencies */
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var fetch = require('node-fetch');
var deleteContentstackNodes = function deleteContentstackNodes(item, type, createNodeId, getNode, deleteNode, typePrefix) {
var nodeId = '';
var node = null;
if (type === 'entry') {
nodeId = createNodeId("".concat(typePrefix.toLowerCase(), "-entry-").concat(item.uid, "-").concat(item.locale));
}
if (type === 'asset') {
nodeId = createNodeId("".concat(typePrefix.toLowerCase(), "-assets-").concat(item.uid, "-").concat(item.locale));
}
node = getNode(nodeId);
if (node) {
deleteNode(node);
}
};
var validateContentstackAccess = /*#__PURE__*/function () {
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(pluginOptions) {
var host;
return _regenerator["default"].wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
if (!(process.env.NODE_ENV === "test")) {
_context.next = 2;
break;
}
return _context.abrupt("return", undefined);
case 2:
host = pluginOptions.cdn ? pluginOptions.cdn : 'https://cdn.contentstack.io/v3';
_context.next = 5;
return fetch("".concat(host, "/content_types?include_count=false"), {
headers: {
api_key: "".concat(pluginOptions.api_key),
access_token: "".concat(pluginOptions.delivery_token)
}
}).then(function (res) {
return res.ok;
}).then(function (ok) {
if (!ok) throw new Error("Cannot access Contentstack with api_key=".concat(pluginOptions.api_key, " & delivery_token=").concat(pluginOptions.delivery_token, "."));
});
case 5:
return _context.abrupt("return", undefined);
case 6:
case "end":
return _context.stop();
}
}
}, _callee);
}));
return function validateContentstackAccess(_x) {
return _ref.apply(this, arguments);
};
}();
exports.deleteContentstackNodes = deleteContentstackNodes;
exports.validateContentstackAccess = validateContentstackAccess;