@bright.global/arboretum-sdk 0.0.7 → 0.0.8
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/clients/contentful-client/impl/constants.js +8 -0
- package/dist/clients/contentful-client/impl/contentful-client-impl.js +21 -11
- package/dist/clients/contentful-client/impl/methods/contentful-fetch.js +116 -0
- package/dist/clients/contentful-client/impl/methods/get-content-types.js +27 -0
- package/dist/clients/contentful-client/impl/methods/get-entries.js +34 -0
- package/dist/clients/contentful-client/impl/methods/get-locales.js +20 -0
- package/dist/clients/contentful-client/impl/methods/get-tags.js +20 -0
- package/dist/es6/clients/contentful-client/impl/constants.js +5 -0
- package/dist/es6/clients/contentful-client/impl/contentful-client-impl.js +19 -10
- package/dist/es6/clients/contentful-client/impl/methods/contentful-fetch.js +112 -0
- package/dist/es6/clients/contentful-client/impl/methods/get-content-types.js +23 -0
- package/dist/es6/clients/contentful-client/impl/methods/get-entries.js +30 -0
- package/dist/es6/clients/contentful-client/impl/methods/get-locales.js +16 -0
- package/dist/es6/clients/contentful-client/impl/methods/get-tags.js +16 -0
- package/dist/es6/impl/arboretum-client.impl.js +3 -1
- package/dist/es6/impl/data/helpers/get-all-entries-recursively.js +5 -3
- package/dist/es6/impl/data/helpers/get-all-entries-recursively.test.js +3 -3
- package/dist/es6/impl/data/page-entries.js +1 -1
- package/dist/es6/impl/data/redirect-entries.js +1 -1
- package/dist/es6/utils/get-rendom-number.js +3 -0
- package/dist/impl/arboretum-client.impl.js +3 -1
- package/dist/impl/data/helpers/get-all-entries-recursively.js +5 -3
- package/dist/impl/data/helpers/get-all-entries-recursively.test.js +3 -3
- package/dist/impl/data/page-entries.js +1 -1
- package/dist/impl/data/redirect-entries.js +1 -1
- package/dist/types/arboretum-client.d.ts +31 -4
- package/dist/types/clients/contentful-client/contentful-client.d.ts +37 -27
- package/dist/types/clients/contentful-client/impl/constants.d.ts +5 -0
- package/dist/types/clients/contentful-client/impl/contentful-client-impl.d.ts +2 -1
- package/dist/types/clients/contentful-client/impl/methods/contentful-fetch.d.ts +2 -0
- package/dist/types/clients/contentful-client/impl/methods/get-content-types.d.ts +3 -0
- package/dist/types/clients/contentful-client/impl/methods/get-entries.d.ts +3 -0
- package/dist/types/clients/contentful-client/impl/methods/get-locales.d.ts +3 -0
- package/dist/types/clients/contentful-client/impl/methods/get-tags.d.ts +3 -0
- package/dist/types/impl/arboretum-client.impl.d.ts +1 -1
- package/dist/types/impl/data/helpers/get-all-entries-recursively.d.ts +1 -1
- package/dist/types/utils/get-rendom-number.d.ts +1 -0
- package/dist/utils/get-rendom-number.js +7 -0
- package/package.json +2 -5
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_RETRY_LIMIT = exports.DEFAULT_RETRY_ON_ERROR = exports.DEFAULT_TIMEOUT = exports.DEFAULT_HOST = exports.DEFAULT_ENVIRONMENT = void 0;
|
|
4
|
+
exports.DEFAULT_ENVIRONMENT = "master";
|
|
5
|
+
exports.DEFAULT_HOST = "cdn.contentful.com";
|
|
6
|
+
exports.DEFAULT_TIMEOUT = 30000;
|
|
7
|
+
exports.DEFAULT_RETRY_ON_ERROR = true;
|
|
8
|
+
exports.DEFAULT_RETRY_LIMIT = 5;
|
|
@@ -11,26 +11,29 @@ var __assign = (this && this.__assign) || function () {
|
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.createContentfulClient = void 0;
|
|
15
|
-
var
|
|
14
|
+
exports.createCdaRestApiContentfulClient = exports.createContentfulClient = void 0;
|
|
15
|
+
var get_locales_1 = require("./methods/get-locales");
|
|
16
|
+
var get_content_types_1 = require("./methods/get-content-types");
|
|
17
|
+
var get_tags_1 = require("./methods/get-tags");
|
|
18
|
+
var get_entries_1 = require("./methods/get-entries");
|
|
16
19
|
var createContentfulClient = function (config) {
|
|
17
20
|
var configType = config.type;
|
|
18
|
-
var clientFromCda = function (client) { return ({
|
|
19
|
-
getEntries: client.getEntries,
|
|
20
|
-
getLocales: client.getLocales,
|
|
21
|
-
getContentTypes: client.getContentTypes,
|
|
22
|
-
getTags: client.getTags,
|
|
23
|
-
}); };
|
|
24
21
|
switch (config.type) {
|
|
25
22
|
case "cda-client": {
|
|
26
|
-
|
|
23
|
+
var c = config.contentful.client;
|
|
24
|
+
var client = c.withAllLocales ? c.withAllLocales : c;
|
|
25
|
+
return {
|
|
26
|
+
getEntries: client.getEntries,
|
|
27
|
+
getLocales: client.getLocales,
|
|
28
|
+
getContentTypes: client.getContentTypes,
|
|
29
|
+
getTags: client.getTags,
|
|
30
|
+
};
|
|
27
31
|
}
|
|
28
32
|
case "cda-client-params": {
|
|
29
33
|
var previewHostOrUndefined = config.preview
|
|
30
34
|
? "preview.contentful.com"
|
|
31
35
|
: undefined;
|
|
32
|
-
|
|
33
|
-
return clientFromCda(clientApi);
|
|
36
|
+
return (0, exports.createCdaRestApiContentfulClient)(__assign(__assign({}, config.contentful), { host: previewHostOrUndefined }));
|
|
34
37
|
}
|
|
35
38
|
case "cma-client": {
|
|
36
39
|
var client_1 = config.contentful.client;
|
|
@@ -52,3 +55,10 @@ var createContentfulClient = function (config) {
|
|
|
52
55
|
}
|
|
53
56
|
};
|
|
54
57
|
exports.createContentfulClient = createContentfulClient;
|
|
58
|
+
var createCdaRestApiContentfulClient = function (config) { return ({
|
|
59
|
+
getLocales: (0, get_locales_1.getLocales)(config),
|
|
60
|
+
getContentTypes: (0, get_content_types_1.getContentTypes)(config),
|
|
61
|
+
getTags: (0, get_tags_1.getTags)(config),
|
|
62
|
+
getEntries: (0, get_entries_1.getEntries)(config),
|
|
63
|
+
}); };
|
|
64
|
+
exports.createCdaRestApiContentfulClient = createCdaRestApiContentfulClient;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
39
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
40
|
+
if (!m) return o;
|
|
41
|
+
var i = m.call(o), r, ar = [], e;
|
|
42
|
+
try {
|
|
43
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
44
|
+
}
|
|
45
|
+
catch (error) { e = { error: error }; }
|
|
46
|
+
finally {
|
|
47
|
+
try {
|
|
48
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
49
|
+
}
|
|
50
|
+
finally { if (e) throw e.error; }
|
|
51
|
+
}
|
|
52
|
+
return ar;
|
|
53
|
+
};
|
|
54
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
55
|
+
exports.contentfulFetch = void 0;
|
|
56
|
+
var get_rendom_number_1 = require("../../../../utils/get-rendom-number");
|
|
57
|
+
var constants_1 = require("../constants");
|
|
58
|
+
var sleep = function (ms) { return new Promise(function (r) { return setTimeout(r, ms); }); };
|
|
59
|
+
var getRetryDelay = function (retry) {
|
|
60
|
+
return Math.ceil(Math.pow((0, get_rendom_number_1.getRandomNumber)(1.2, 1.4), retry) * 1000);
|
|
61
|
+
};
|
|
62
|
+
var contentfulFetchWithRetires = function (p, retryLimit, retry) {
|
|
63
|
+
if (retry === void 0) { retry = 0; }
|
|
64
|
+
return p().then(function (res) { return __awaiter(void 0, void 0, void 0, function () {
|
|
65
|
+
var delay, msg;
|
|
66
|
+
return __generator(this, function (_a) {
|
|
67
|
+
switch (_a.label) {
|
|
68
|
+
case 0:
|
|
69
|
+
if (!res.ok) return [3 /*break*/, 1];
|
|
70
|
+
return [2 /*return*/, res.json()];
|
|
71
|
+
case 1:
|
|
72
|
+
if (!(retry < retryLimit &&
|
|
73
|
+
(res.status === 429 || res.status === 500))) return [3 /*break*/, 3];
|
|
74
|
+
delay = getRetryDelay(retry);
|
|
75
|
+
msg = "Waiting for ".concat(delay, "ms before retrying... (retry: ").concat(delay, "/").concat(retryLimit, ")");
|
|
76
|
+
if (res.status === 500) {
|
|
77
|
+
console.log("[warning] Internal server error occurred. ".concat(msg));
|
|
78
|
+
}
|
|
79
|
+
else if (res.status === 429) {
|
|
80
|
+
console.log("[warning] Rate limit occurred. ".concat(msg));
|
|
81
|
+
}
|
|
82
|
+
return [4 /*yield*/, sleep(delay)];
|
|
83
|
+
case 2:
|
|
84
|
+
_a.sent();
|
|
85
|
+
return [2 /*return*/, contentfulFetchWithRetires(p, retryLimit, retry + 1)];
|
|
86
|
+
case 3: return [2 /*return*/, res
|
|
87
|
+
.json()
|
|
88
|
+
.then(function (res) {
|
|
89
|
+
throw res;
|
|
90
|
+
})
|
|
91
|
+
.catch(function (_) {
|
|
92
|
+
throw res;
|
|
93
|
+
})];
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}); });
|
|
97
|
+
};
|
|
98
|
+
var contentfulFetch = function (config) {
|
|
99
|
+
return function (endpoint, query) {
|
|
100
|
+
var space = config.space, accessToken = config.accessToken;
|
|
101
|
+
var host = config.host || constants_1.DEFAULT_HOST;
|
|
102
|
+
var environment = config.environment || constants_1.DEFAULT_ENVIRONMENT;
|
|
103
|
+
var params = new URLSearchParams();
|
|
104
|
+
params.append("access_token", accessToken);
|
|
105
|
+
Object.entries(query).forEach(function (_a) {
|
|
106
|
+
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
107
|
+
params.append(key, value.toString());
|
|
108
|
+
});
|
|
109
|
+
var retryLimit = config.retryLimit || constants_1.DEFAULT_RETRY_LIMIT;
|
|
110
|
+
var retryOnError = config.retryOnError || constants_1.DEFAULT_RETRY_ON_ERROR;
|
|
111
|
+
return contentfulFetchWithRetires(function () {
|
|
112
|
+
return fetch("https://".concat(host, "/spaces/").concat(space, "/environments/").concat(environment).concat(endpoint, "?").concat(params.toString()), { method: "GET" });
|
|
113
|
+
}, retryOnError ? retryLimit : 0);
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
exports.contentfulFetch = contentfulFetch;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getContentTypes = void 0;
|
|
4
|
+
var contentful_fetch_1 = require("./contentful-fetch");
|
|
5
|
+
var getContentTypes = function (config) {
|
|
6
|
+
return function (query) {
|
|
7
|
+
return (0, contentful_fetch_1.contentfulFetch)(config)("/content_types", query || {}).then(function (res) { return ({
|
|
8
|
+
total: res.total,
|
|
9
|
+
skip: res.skip,
|
|
10
|
+
limit: res.limit,
|
|
11
|
+
items: res.items.map(function (i) { return ({
|
|
12
|
+
sys: { id: i.sys.id },
|
|
13
|
+
fields: i.fields.map(function (f) { return ({
|
|
14
|
+
id: f.id,
|
|
15
|
+
name: f.name,
|
|
16
|
+
localized: f.localized,
|
|
17
|
+
type: f.type,
|
|
18
|
+
linkType: f.linkType,
|
|
19
|
+
items: f.items
|
|
20
|
+
? { type: f.items.type, linkType: f.items.linkType }
|
|
21
|
+
: undefined,
|
|
22
|
+
}); }),
|
|
23
|
+
}); }),
|
|
24
|
+
}); });
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
exports.getContentTypes = getContentTypes;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getEntries = void 0;
|
|
4
|
+
var contentful_fetch_1 = require("./contentful-fetch");
|
|
5
|
+
var getEntries = function (config) {
|
|
6
|
+
return function (query) {
|
|
7
|
+
return (0, contentful_fetch_1.contentfulFetch)(config)("/entries", query || {}).then(function (res) {
|
|
8
|
+
var _a;
|
|
9
|
+
return ({
|
|
10
|
+
total: res.total,
|
|
11
|
+
skip: res.skip,
|
|
12
|
+
limit: res.limit,
|
|
13
|
+
items: (_a = res.items) === null || _a === void 0 ? void 0 : _a.map(function (i) {
|
|
14
|
+
var _a, _b;
|
|
15
|
+
return ({
|
|
16
|
+
metadata: i.metadata
|
|
17
|
+
? { tags: i.metadata.tags.map(function (t) { return ({ sys: { id: t.sys.id } }); }) }
|
|
18
|
+
: undefined,
|
|
19
|
+
fields: i.fields,
|
|
20
|
+
sys: {
|
|
21
|
+
id: i.sys.id,
|
|
22
|
+
archivedVersion: i.sys.archivedVersion,
|
|
23
|
+
version: i.sys.version,
|
|
24
|
+
publishedVersion: i.sys.publishedVersion,
|
|
25
|
+
contentType: { sys: { id: (_b = (_a = i.sys.contentType) === null || _a === void 0 ? void 0 : _a.sys) === null || _b === void 0 ? void 0 : _b.id } },
|
|
26
|
+
cmaOnlyStatus: undefined,
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
}),
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
exports.getEntries = getEntries;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLocales = void 0;
|
|
4
|
+
var contentful_fetch_1 = require("./contentful-fetch");
|
|
5
|
+
var getLocales = function (config) {
|
|
6
|
+
return function () {
|
|
7
|
+
return (0, contentful_fetch_1.contentfulFetch)(config)("/locales", {}).then(function (res) { return ({
|
|
8
|
+
total: res.total,
|
|
9
|
+
skip: res.skip,
|
|
10
|
+
limit: res.limit,
|
|
11
|
+
items: res.items.map(function (i) { return ({
|
|
12
|
+
code: i.code,
|
|
13
|
+
name: i.name,
|
|
14
|
+
default: i.default,
|
|
15
|
+
fallbackCode: i.fallbackCode,
|
|
16
|
+
}); }),
|
|
17
|
+
}); });
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
exports.getLocales = getLocales;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTags = void 0;
|
|
4
|
+
var contentful_fetch_1 = require("./contentful-fetch");
|
|
5
|
+
var getTags = function (config) {
|
|
6
|
+
return function (query) {
|
|
7
|
+
return (0, contentful_fetch_1.contentfulFetch)(config)("/tags", query || {}).then(function (res) { return ({
|
|
8
|
+
total: res.total,
|
|
9
|
+
skip: res.skip,
|
|
10
|
+
limit: res.limit,
|
|
11
|
+
items: res.items.map(function (i) { return ({
|
|
12
|
+
name: i.name,
|
|
13
|
+
sys: {
|
|
14
|
+
id: i.sys.id,
|
|
15
|
+
},
|
|
16
|
+
}); }),
|
|
17
|
+
}); });
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
exports.getTags = getTags;
|
|
@@ -9,25 +9,28 @@ var __assign = (this && this.__assign) || function () {
|
|
|
9
9
|
};
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
|
-
import {
|
|
12
|
+
import { getLocales } from "./methods/get-locales";
|
|
13
|
+
import { getContentTypes } from "./methods/get-content-types";
|
|
14
|
+
import { getTags } from "./methods/get-tags";
|
|
15
|
+
import { getEntries } from "./methods/get-entries";
|
|
13
16
|
export var createContentfulClient = function (config) {
|
|
14
17
|
var configType = config.type;
|
|
15
|
-
var clientFromCda = function (client) { return ({
|
|
16
|
-
getEntries: client.getEntries,
|
|
17
|
-
getLocales: client.getLocales,
|
|
18
|
-
getContentTypes: client.getContentTypes,
|
|
19
|
-
getTags: client.getTags,
|
|
20
|
-
}); };
|
|
21
18
|
switch (config.type) {
|
|
22
19
|
case "cda-client": {
|
|
23
|
-
|
|
20
|
+
var c = config.contentful.client;
|
|
21
|
+
var client = c.withAllLocales ? c.withAllLocales : c;
|
|
22
|
+
return {
|
|
23
|
+
getEntries: client.getEntries,
|
|
24
|
+
getLocales: client.getLocales,
|
|
25
|
+
getContentTypes: client.getContentTypes,
|
|
26
|
+
getTags: client.getTags,
|
|
27
|
+
};
|
|
24
28
|
}
|
|
25
29
|
case "cda-client-params": {
|
|
26
30
|
var previewHostOrUndefined = config.preview
|
|
27
31
|
? "preview.contentful.com"
|
|
28
32
|
: undefined;
|
|
29
|
-
|
|
30
|
-
return clientFromCda(clientApi);
|
|
33
|
+
return createCdaRestApiContentfulClient(__assign(__assign({}, config.contentful), { host: previewHostOrUndefined }));
|
|
31
34
|
}
|
|
32
35
|
case "cma-client": {
|
|
33
36
|
var client_1 = config.contentful.client;
|
|
@@ -48,3 +51,9 @@ export var createContentfulClient = function (config) {
|
|
|
48
51
|
}
|
|
49
52
|
}
|
|
50
53
|
};
|
|
54
|
+
export var createCdaRestApiContentfulClient = function (config) { return ({
|
|
55
|
+
getLocales: getLocales(config),
|
|
56
|
+
getContentTypes: getContentTypes(config),
|
|
57
|
+
getTags: getTags(config),
|
|
58
|
+
getEntries: getEntries(config),
|
|
59
|
+
}); };
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
38
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
39
|
+
if (!m) return o;
|
|
40
|
+
var i = m.call(o), r, ar = [], e;
|
|
41
|
+
try {
|
|
42
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
43
|
+
}
|
|
44
|
+
catch (error) { e = { error: error }; }
|
|
45
|
+
finally {
|
|
46
|
+
try {
|
|
47
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
48
|
+
}
|
|
49
|
+
finally { if (e) throw e.error; }
|
|
50
|
+
}
|
|
51
|
+
return ar;
|
|
52
|
+
};
|
|
53
|
+
import { getRandomNumber } from "../../../../utils/get-rendom-number";
|
|
54
|
+
import { DEFAULT_ENVIRONMENT, DEFAULT_HOST, DEFAULT_RETRY_LIMIT, DEFAULT_RETRY_ON_ERROR, } from "../constants";
|
|
55
|
+
var sleep = function (ms) { return new Promise(function (r) { return setTimeout(r, ms); }); };
|
|
56
|
+
var getRetryDelay = function (retry) {
|
|
57
|
+
return Math.ceil(Math.pow(getRandomNumber(1.2, 1.4), retry) * 1000);
|
|
58
|
+
};
|
|
59
|
+
var contentfulFetchWithRetires = function (p, retryLimit, retry) {
|
|
60
|
+
if (retry === void 0) { retry = 0; }
|
|
61
|
+
return p().then(function (res) { return __awaiter(void 0, void 0, void 0, function () {
|
|
62
|
+
var delay, msg;
|
|
63
|
+
return __generator(this, function (_a) {
|
|
64
|
+
switch (_a.label) {
|
|
65
|
+
case 0:
|
|
66
|
+
if (!res.ok) return [3 /*break*/, 1];
|
|
67
|
+
return [2 /*return*/, res.json()];
|
|
68
|
+
case 1:
|
|
69
|
+
if (!(retry < retryLimit &&
|
|
70
|
+
(res.status === 429 || res.status === 500))) return [3 /*break*/, 3];
|
|
71
|
+
delay = getRetryDelay(retry);
|
|
72
|
+
msg = "Waiting for ".concat(delay, "ms before retrying... (retry: ").concat(delay, "/").concat(retryLimit, ")");
|
|
73
|
+
if (res.status === 500) {
|
|
74
|
+
console.log("[warning] Internal server error occurred. ".concat(msg));
|
|
75
|
+
}
|
|
76
|
+
else if (res.status === 429) {
|
|
77
|
+
console.log("[warning] Rate limit occurred. ".concat(msg));
|
|
78
|
+
}
|
|
79
|
+
return [4 /*yield*/, sleep(delay)];
|
|
80
|
+
case 2:
|
|
81
|
+
_a.sent();
|
|
82
|
+
return [2 /*return*/, contentfulFetchWithRetires(p, retryLimit, retry + 1)];
|
|
83
|
+
case 3: return [2 /*return*/, res
|
|
84
|
+
.json()
|
|
85
|
+
.then(function (res) {
|
|
86
|
+
throw res;
|
|
87
|
+
})
|
|
88
|
+
.catch(function (_) {
|
|
89
|
+
throw res;
|
|
90
|
+
})];
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}); });
|
|
94
|
+
};
|
|
95
|
+
export var contentfulFetch = function (config) {
|
|
96
|
+
return function (endpoint, query) {
|
|
97
|
+
var space = config.space, accessToken = config.accessToken;
|
|
98
|
+
var host = config.host || DEFAULT_HOST;
|
|
99
|
+
var environment = config.environment || DEFAULT_ENVIRONMENT;
|
|
100
|
+
var params = new URLSearchParams();
|
|
101
|
+
params.append("access_token", accessToken);
|
|
102
|
+
Object.entries(query).forEach(function (_a) {
|
|
103
|
+
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
104
|
+
params.append(key, value.toString());
|
|
105
|
+
});
|
|
106
|
+
var retryLimit = config.retryLimit || DEFAULT_RETRY_LIMIT;
|
|
107
|
+
var retryOnError = config.retryOnError || DEFAULT_RETRY_ON_ERROR;
|
|
108
|
+
return contentfulFetchWithRetires(function () {
|
|
109
|
+
return fetch("https://".concat(host, "/spaces/").concat(space, "/environments/").concat(environment).concat(endpoint, "?").concat(params.toString()), { method: "GET" });
|
|
110
|
+
}, retryOnError ? retryLimit : 0);
|
|
111
|
+
};
|
|
112
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { contentfulFetch } from "./contentful-fetch";
|
|
2
|
+
export var getContentTypes = function (config) {
|
|
3
|
+
return function (query) {
|
|
4
|
+
return contentfulFetch(config)("/content_types", query || {}).then(function (res) { return ({
|
|
5
|
+
total: res.total,
|
|
6
|
+
skip: res.skip,
|
|
7
|
+
limit: res.limit,
|
|
8
|
+
items: res.items.map(function (i) { return ({
|
|
9
|
+
sys: { id: i.sys.id },
|
|
10
|
+
fields: i.fields.map(function (f) { return ({
|
|
11
|
+
id: f.id,
|
|
12
|
+
name: f.name,
|
|
13
|
+
localized: f.localized,
|
|
14
|
+
type: f.type,
|
|
15
|
+
linkType: f.linkType,
|
|
16
|
+
items: f.items
|
|
17
|
+
? { type: f.items.type, linkType: f.items.linkType }
|
|
18
|
+
: undefined,
|
|
19
|
+
}); }),
|
|
20
|
+
}); }),
|
|
21
|
+
}); });
|
|
22
|
+
};
|
|
23
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { contentfulFetch } from "./contentful-fetch";
|
|
2
|
+
export var getEntries = function (config) {
|
|
3
|
+
return function (query) {
|
|
4
|
+
return contentfulFetch(config)("/entries", query || {}).then(function (res) {
|
|
5
|
+
var _a;
|
|
6
|
+
return ({
|
|
7
|
+
total: res.total,
|
|
8
|
+
skip: res.skip,
|
|
9
|
+
limit: res.limit,
|
|
10
|
+
items: (_a = res.items) === null || _a === void 0 ? void 0 : _a.map(function (i) {
|
|
11
|
+
var _a, _b;
|
|
12
|
+
return ({
|
|
13
|
+
metadata: i.metadata
|
|
14
|
+
? { tags: i.metadata.tags.map(function (t) { return ({ sys: { id: t.sys.id } }); }) }
|
|
15
|
+
: undefined,
|
|
16
|
+
fields: i.fields,
|
|
17
|
+
sys: {
|
|
18
|
+
id: i.sys.id,
|
|
19
|
+
archivedVersion: i.sys.archivedVersion,
|
|
20
|
+
version: i.sys.version,
|
|
21
|
+
publishedVersion: i.sys.publishedVersion,
|
|
22
|
+
contentType: { sys: { id: (_b = (_a = i.sys.contentType) === null || _a === void 0 ? void 0 : _a.sys) === null || _b === void 0 ? void 0 : _b.id } },
|
|
23
|
+
cmaOnlyStatus: undefined,
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
}),
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { contentfulFetch } from "./contentful-fetch";
|
|
2
|
+
export var getLocales = function (config) {
|
|
3
|
+
return function () {
|
|
4
|
+
return contentfulFetch(config)("/locales", {}).then(function (res) { return ({
|
|
5
|
+
total: res.total,
|
|
6
|
+
skip: res.skip,
|
|
7
|
+
limit: res.limit,
|
|
8
|
+
items: res.items.map(function (i) { return ({
|
|
9
|
+
code: i.code,
|
|
10
|
+
name: i.name,
|
|
11
|
+
default: i.default,
|
|
12
|
+
fallbackCode: i.fallbackCode,
|
|
13
|
+
}); }),
|
|
14
|
+
}); });
|
|
15
|
+
};
|
|
16
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { contentfulFetch } from "./contentful-fetch";
|
|
2
|
+
export var getTags = function (config) {
|
|
3
|
+
return function (query) {
|
|
4
|
+
return contentfulFetch(config)("/tags", query || {}).then(function (res) { return ({
|
|
5
|
+
total: res.total,
|
|
6
|
+
skip: res.skip,
|
|
7
|
+
limit: res.limit,
|
|
8
|
+
items: res.items.map(function (i) { return ({
|
|
9
|
+
name: i.name,
|
|
10
|
+
sys: {
|
|
11
|
+
id: i.sys.id,
|
|
12
|
+
},
|
|
13
|
+
}); }),
|
|
14
|
+
}); });
|
|
15
|
+
};
|
|
16
|
+
};
|
|
@@ -126,7 +126,9 @@ export var createArboretumClient = function (config) { return __awaiter(void 0,
|
|
|
126
126
|
options: __assign(__assign({}, options), { includeEntryStatus: includeEntryStatus }),
|
|
127
127
|
localeTagIdPrefix: localeTagIdPrefix,
|
|
128
128
|
pageHomeTagId: options.homePageTagId || pageHomeTagId,
|
|
129
|
-
contentfulClientType: config.type
|
|
129
|
+
contentfulClientType: config.type === "cda-client" && config.contentful.client.withAllLocales
|
|
130
|
+
? "cda-client-with-all-locales"
|
|
131
|
+
: config.type,
|
|
130
132
|
pageTagIdPrefix: pageTagIdPrefix,
|
|
131
133
|
cmaPreviewClientApi: cmaPreviewClientApi,
|
|
132
134
|
};
|
|
@@ -80,7 +80,7 @@ var filterOutNestedEntriesFieldsOtherThanSysEff = function (entry) {
|
|
|
80
80
|
return entry;
|
|
81
81
|
};
|
|
82
82
|
};
|
|
83
|
-
export var getAllEntriesRecursively = function (_a, contentType, skip, acc, select, refFieldsToFilterOut, limit) {
|
|
83
|
+
export var getAllEntriesRecursively = function (_a, contentfulClientType, contentType, skip, acc, select, refFieldsToFilterOut, limit) {
|
|
84
84
|
var getEntries = _a.getEntries;
|
|
85
85
|
if (refFieldsToFilterOut === void 0) { refFieldsToFilterOut = []; }
|
|
86
86
|
if (limit === void 0) { limit = 1000; }
|
|
@@ -94,7 +94,9 @@ export var getAllEntriesRecursively = function (_a, contentType, skip, acc, sele
|
|
|
94
94
|
content_type: contentType,
|
|
95
95
|
include: 0,
|
|
96
96
|
select: select,
|
|
97
|
-
locale: "
|
|
97
|
+
locale: contentfulClientType === "cda-client-with-all-locales"
|
|
98
|
+
? undefined
|
|
99
|
+
: "*",
|
|
98
100
|
})];
|
|
99
101
|
case 1:
|
|
100
102
|
items = (_b.sent()).items;
|
|
@@ -105,7 +107,7 @@ export var getAllEntriesRecursively = function (_a, contentType, skip, acc, sele
|
|
|
105
107
|
});
|
|
106
108
|
acc.push.apply(acc, __spreadArray([], __read(items), false));
|
|
107
109
|
return [2 /*return*/, items.length >= limit
|
|
108
|
-
? getAllEntriesRecursively({ getEntries: getEntries }, contentType, skip + limit, acc, select)
|
|
110
|
+
? getAllEntriesRecursively({ getEntries: getEntries }, contentfulClientType, contentType, skip + limit, acc, select)
|
|
109
111
|
: acc];
|
|
110
112
|
}
|
|
111
113
|
});
|
|
@@ -67,7 +67,7 @@ describe(getAllEntriesRecursively, function () {
|
|
|
67
67
|
var entries;
|
|
68
68
|
return __generator(this, function (_a) {
|
|
69
69
|
switch (_a.label) {
|
|
70
|
-
case 0: return [4 /*yield*/, getAllEntriesRecursively(mockedContentfulEntriesClientApi(testContentTypeId, 0), testContentTypeId, 0, [], undefined, [], 10)];
|
|
70
|
+
case 0: return [4 /*yield*/, getAllEntriesRecursively(mockedContentfulEntriesClientApi(testContentTypeId, 0), "cda-client", testContentTypeId, 0, [], undefined, [], 10)];
|
|
71
71
|
case 1:
|
|
72
72
|
entries = _a.sent();
|
|
73
73
|
expect(entries.length).toBe(0);
|
|
@@ -81,7 +81,7 @@ describe(getAllEntriesRecursively, function () {
|
|
|
81
81
|
switch (_a.label) {
|
|
82
82
|
case 0:
|
|
83
83
|
total = 10;
|
|
84
|
-
return [4 /*yield*/, getAllEntriesRecursively(mockedContentfulEntriesClientApi(testContentTypeId, total), testContentTypeId, 0, [], undefined, [], 10)];
|
|
84
|
+
return [4 /*yield*/, getAllEntriesRecursively(mockedContentfulEntriesClientApi(testContentTypeId, total), "cda-client", testContentTypeId, 0, [], undefined, [], 10)];
|
|
85
85
|
case 1:
|
|
86
86
|
entries = _a.sent();
|
|
87
87
|
entriesIds = entries.map(function (e) { return e.sys.id; });
|
|
@@ -99,7 +99,7 @@ describe(getAllEntriesRecursively, function () {
|
|
|
99
99
|
switch (_a.label) {
|
|
100
100
|
case 0:
|
|
101
101
|
total = 101;
|
|
102
|
-
return [4 /*yield*/, getAllEntriesRecursively(mockedContentfulEntriesClientApi(testContentTypeId, total), testContentTypeId, 0, [], undefined, [], 10)];
|
|
102
|
+
return [4 /*yield*/, getAllEntriesRecursively(mockedContentfulEntriesClientApi(testContentTypeId, total), "cda-client", testContentTypeId, 0, [], undefined, [], 10)];
|
|
103
103
|
case 1:
|
|
104
104
|
entries = _a.sent();
|
|
105
105
|
entriesIds = entries.map(function (e) { return e.sys.id; });
|
|
@@ -83,7 +83,7 @@ var getAllPageEntriesRecursively = function (_a, contentfulClientType, pageConte
|
|
|
83
83
|
pageContentTypeOpt.childPagesFieldId,
|
|
84
84
|
pageContentTypeOpt.titleFieldId,
|
|
85
85
|
].flatMap(function (id) { return (id ? ["fields.".concat(id)] : []); });
|
|
86
|
-
return [2 /*return*/, getAllEntriesRecursively({ getEntries: getEntries }, pageContentTypeOpt.id, skip, acc,
|
|
86
|
+
return [2 /*return*/, getAllEntriesRecursively({ getEntries: getEntries }, contentfulClientType, pageContentTypeOpt.id, skip, acc,
|
|
87
87
|
/* For some reason select param causes errors in CMA. I'm getting the following response:
|
|
88
88
|
{
|
|
89
89
|
"status": 400,
|
|
@@ -82,7 +82,7 @@ var getAllRedirectEntriesRecursively = function (ctx, redirectContentType, skip,
|
|
|
82
82
|
redirectContentType.typeFieldId,
|
|
83
83
|
redirectContentType.pathFieldId,
|
|
84
84
|
].flatMap(function (id) { return (id ? ["fields.".concat(id)] : []); });
|
|
85
|
-
return [2 /*return*/, getAllEntriesRecursively(ctx.clientApi, redirectContentType.id, skip, acc,
|
|
85
|
+
return [2 /*return*/, getAllEntriesRecursively(ctx.clientApi, ctx.contentfulClientType, redirectContentType.id, skip, acc,
|
|
86
86
|
/* For some reason select param causes errors in CMA. I'm getting the following response:
|
|
87
87
|
{
|
|
88
88
|
"status": 400,
|
|
@@ -129,7 +129,9 @@ var createArboretumClient = function (config) { return __awaiter(void 0, void 0,
|
|
|
129
129
|
options: __assign(__assign({}, options), { includeEntryStatus: includeEntryStatus }),
|
|
130
130
|
localeTagIdPrefix: localeTagIdPrefix,
|
|
131
131
|
pageHomeTagId: options.homePageTagId || pageHomeTagId,
|
|
132
|
-
contentfulClientType: config.type
|
|
132
|
+
contentfulClientType: config.type === "cda-client" && config.contentful.client.withAllLocales
|
|
133
|
+
? "cda-client-with-all-locales"
|
|
134
|
+
: config.type,
|
|
133
135
|
pageTagIdPrefix: pageTagIdPrefix,
|
|
134
136
|
cmaPreviewClientApi: cmaPreviewClientApi,
|
|
135
137
|
};
|
|
@@ -83,7 +83,7 @@ var filterOutNestedEntriesFieldsOtherThanSysEff = function (entry) {
|
|
|
83
83
|
return entry;
|
|
84
84
|
};
|
|
85
85
|
};
|
|
86
|
-
var getAllEntriesRecursively = function (_a, contentType, skip, acc, select, refFieldsToFilterOut, limit) {
|
|
86
|
+
var getAllEntriesRecursively = function (_a, contentfulClientType, contentType, skip, acc, select, refFieldsToFilterOut, limit) {
|
|
87
87
|
var getEntries = _a.getEntries;
|
|
88
88
|
if (refFieldsToFilterOut === void 0) { refFieldsToFilterOut = []; }
|
|
89
89
|
if (limit === void 0) { limit = 1000; }
|
|
@@ -97,7 +97,9 @@ var getAllEntriesRecursively = function (_a, contentType, skip, acc, select, ref
|
|
|
97
97
|
content_type: contentType,
|
|
98
98
|
include: 0,
|
|
99
99
|
select: select,
|
|
100
|
-
locale: "
|
|
100
|
+
locale: contentfulClientType === "cda-client-with-all-locales"
|
|
101
|
+
? undefined
|
|
102
|
+
: "*",
|
|
101
103
|
})];
|
|
102
104
|
case 1:
|
|
103
105
|
items = (_b.sent()).items;
|
|
@@ -108,7 +110,7 @@ var getAllEntriesRecursively = function (_a, contentType, skip, acc, select, ref
|
|
|
108
110
|
});
|
|
109
111
|
acc.push.apply(acc, __spreadArray([], __read(items), false));
|
|
110
112
|
return [2 /*return*/, items.length >= limit
|
|
111
|
-
? (0, exports.getAllEntriesRecursively)({ getEntries: getEntries }, contentType, skip + limit, acc, select)
|
|
113
|
+
? (0, exports.getAllEntriesRecursively)({ getEntries: getEntries }, contentfulClientType, contentType, skip + limit, acc, select)
|
|
112
114
|
: acc];
|
|
113
115
|
}
|
|
114
116
|
});
|
|
@@ -69,7 +69,7 @@ describe(get_all_entries_recursively_1.getAllEntriesRecursively, function () {
|
|
|
69
69
|
var entries;
|
|
70
70
|
return __generator(this, function (_a) {
|
|
71
71
|
switch (_a.label) {
|
|
72
|
-
case 0: return [4 /*yield*/, (0, get_all_entries_recursively_1.getAllEntriesRecursively)((0, mocked_contentful_entries_client_api_1.mockedContentfulEntriesClientApi)(testContentTypeId, 0), testContentTypeId, 0, [], undefined, [], 10)];
|
|
72
|
+
case 0: return [4 /*yield*/, (0, get_all_entries_recursively_1.getAllEntriesRecursively)((0, mocked_contentful_entries_client_api_1.mockedContentfulEntriesClientApi)(testContentTypeId, 0), "cda-client", testContentTypeId, 0, [], undefined, [], 10)];
|
|
73
73
|
case 1:
|
|
74
74
|
entries = _a.sent();
|
|
75
75
|
expect(entries.length).toBe(0);
|
|
@@ -83,7 +83,7 @@ describe(get_all_entries_recursively_1.getAllEntriesRecursively, function () {
|
|
|
83
83
|
switch (_a.label) {
|
|
84
84
|
case 0:
|
|
85
85
|
total = 10;
|
|
86
|
-
return [4 /*yield*/, (0, get_all_entries_recursively_1.getAllEntriesRecursively)((0, mocked_contentful_entries_client_api_1.mockedContentfulEntriesClientApi)(testContentTypeId, total), testContentTypeId, 0, [], undefined, [], 10)];
|
|
86
|
+
return [4 /*yield*/, (0, get_all_entries_recursively_1.getAllEntriesRecursively)((0, mocked_contentful_entries_client_api_1.mockedContentfulEntriesClientApi)(testContentTypeId, total), "cda-client", testContentTypeId, 0, [], undefined, [], 10)];
|
|
87
87
|
case 1:
|
|
88
88
|
entries = _a.sent();
|
|
89
89
|
entriesIds = entries.map(function (e) { return e.sys.id; });
|
|
@@ -101,7 +101,7 @@ describe(get_all_entries_recursively_1.getAllEntriesRecursively, function () {
|
|
|
101
101
|
switch (_a.label) {
|
|
102
102
|
case 0:
|
|
103
103
|
total = 101;
|
|
104
|
-
return [4 /*yield*/, (0, get_all_entries_recursively_1.getAllEntriesRecursively)((0, mocked_contentful_entries_client_api_1.mockedContentfulEntriesClientApi)(testContentTypeId, total), testContentTypeId, 0, [], undefined, [], 10)];
|
|
104
|
+
return [4 /*yield*/, (0, get_all_entries_recursively_1.getAllEntriesRecursively)((0, mocked_contentful_entries_client_api_1.mockedContentfulEntriesClientApi)(testContentTypeId, total), "cda-client", testContentTypeId, 0, [], undefined, [], 10)];
|
|
105
105
|
case 1:
|
|
106
106
|
entries = _a.sent();
|
|
107
107
|
entriesIds = entries.map(function (e) { return e.sys.id; });
|
|
@@ -86,7 +86,7 @@ var getAllPageEntriesRecursively = function (_a, contentfulClientType, pageConte
|
|
|
86
86
|
pageContentTypeOpt.childPagesFieldId,
|
|
87
87
|
pageContentTypeOpt.titleFieldId,
|
|
88
88
|
].flatMap(function (id) { return (id ? ["fields.".concat(id)] : []); });
|
|
89
|
-
return [2 /*return*/, (0, get_all_entries_recursively_1.getAllEntriesRecursively)({ getEntries: getEntries }, pageContentTypeOpt.id, skip, acc,
|
|
89
|
+
return [2 /*return*/, (0, get_all_entries_recursively_1.getAllEntriesRecursively)({ getEntries: getEntries }, contentfulClientType, pageContentTypeOpt.id, skip, acc,
|
|
90
90
|
/* For some reason select param causes errors in CMA. I'm getting the following response:
|
|
91
91
|
{
|
|
92
92
|
"status": 400,
|
|
@@ -85,7 +85,7 @@ var getAllRedirectEntriesRecursively = function (ctx, redirectContentType, skip,
|
|
|
85
85
|
redirectContentType.typeFieldId,
|
|
86
86
|
redirectContentType.pathFieldId,
|
|
87
87
|
].flatMap(function (id) { return (id ? ["fields.".concat(id)] : []); });
|
|
88
|
-
return [2 /*return*/, (0, get_all_entries_recursively_1.getAllEntriesRecursively)(ctx.clientApi, redirectContentType.id, skip, acc,
|
|
88
|
+
return [2 /*return*/, (0, get_all_entries_recursively_1.getAllEntriesRecursively)(ctx.clientApi, ctx.contentfulClientType, redirectContentType.id, skip, acc,
|
|
89
89
|
/* For some reason select param causes errors in CMA. I'm getting the following response:
|
|
90
90
|
{
|
|
91
91
|
"status": 400,
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { ContentfulClientApi, CreateClientParams } from "contentful";
|
|
2
1
|
import { CachedDataT, SysIdT } from "./impl/arboretum-client.impl";
|
|
3
2
|
import { Either } from "./utils/fp-utils";
|
|
4
|
-
import {
|
|
5
|
-
import { LocaleT, StatusT } from "./clients/contentful-client/contentful-client";
|
|
3
|
+
import { ContentTypeT, EntryT, LocaleT, StatusT, TagT } from "./clients/contentful-client/contentful-client";
|
|
6
4
|
export type ArboretumClientOptions = {
|
|
7
5
|
data?: CachedDataT;
|
|
8
6
|
eagerly?: boolean;
|
|
@@ -25,6 +23,13 @@ export type ArboretumClientContentfulConfigOptionsT = {
|
|
|
25
23
|
};
|
|
26
24
|
homePageTagId?: string;
|
|
27
25
|
};
|
|
26
|
+
export type ContentfulEnvironmentAPI = {
|
|
27
|
+
getEntries: (query?: any) => Promise<ContentfulCollection<EntryT>>;
|
|
28
|
+
getPublishedEntries: (query?: any) => Promise<ContentfulCollection<EntryT>>;
|
|
29
|
+
getLocales: () => Promise<ContentfulCollection<LocaleT>>;
|
|
30
|
+
getContentTypes: (query?: any) => Promise<ContentfulCollection<ContentTypeT>>;
|
|
31
|
+
getTags: (query?: any) => Promise<ContentfulCollection<TagT>>;
|
|
32
|
+
};
|
|
28
33
|
export type ArboretumClientConfigFromCmaT = {
|
|
29
34
|
type: "cma-client";
|
|
30
35
|
preview: boolean;
|
|
@@ -34,6 +39,19 @@ export type ArboretumClientConfigFromCmaT = {
|
|
|
34
39
|
};
|
|
35
40
|
options?: ArboretumClientOptions;
|
|
36
41
|
};
|
|
42
|
+
type ContentfulCollection<T> = {
|
|
43
|
+
total: number;
|
|
44
|
+
skip: number;
|
|
45
|
+
limit: number;
|
|
46
|
+
items: Array<T>;
|
|
47
|
+
};
|
|
48
|
+
export type ContentfulClientApi = {
|
|
49
|
+
withAllLocales?: ContentfulClientApi;
|
|
50
|
+
getEntries: (query?: any) => Promise<ContentfulCollection<EntryT>>;
|
|
51
|
+
getLocales: () => Promise<ContentfulCollection<LocaleT>>;
|
|
52
|
+
getContentTypes: (query?: any) => Promise<ContentfulCollection<ContentTypeT>>;
|
|
53
|
+
getTags: (query?: any) => Promise<ContentfulCollection<TagT>>;
|
|
54
|
+
};
|
|
37
55
|
export type ArboretumClientConfigFromCdaT = {
|
|
38
56
|
type: "cda-client";
|
|
39
57
|
preview: boolean;
|
|
@@ -43,10 +61,19 @@ export type ArboretumClientConfigFromCdaT = {
|
|
|
43
61
|
};
|
|
44
62
|
options?: Pick<ArboretumClientOptions, "data" | "eagerly">;
|
|
45
63
|
};
|
|
64
|
+
export type CreateClientParams = {
|
|
65
|
+
space: string;
|
|
66
|
+
accessToken: string;
|
|
67
|
+
environment?: string;
|
|
68
|
+
host?: string;
|
|
69
|
+
retryOnError?: boolean;
|
|
70
|
+
timeout?: number;
|
|
71
|
+
retryLimit?: number;
|
|
72
|
+
};
|
|
46
73
|
export type ArboretumClientConfigFromCdaParamsT = {
|
|
47
74
|
type: "cda-client-params";
|
|
48
75
|
preview: boolean;
|
|
49
|
-
contentful: CreateClientParams & {
|
|
76
|
+
contentful: Omit<CreateClientParams, "host"> & {
|
|
50
77
|
options: ArboretumClientContentfulConfigOptionsT;
|
|
51
78
|
};
|
|
52
79
|
options?: Pick<ArboretumClientOptions, "data" | "eagerly">;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Entry, Locale } from "contentful";
|
|
2
1
|
type EntriesQueryT = {
|
|
3
2
|
limit?: number;
|
|
4
3
|
skip?: number;
|
|
@@ -23,7 +22,9 @@ export type EntryT = {
|
|
|
23
22
|
};
|
|
24
23
|
}>;
|
|
25
24
|
};
|
|
26
|
-
fields:
|
|
25
|
+
fields: {
|
|
26
|
+
[localeCode: string]: any;
|
|
27
|
+
};
|
|
27
28
|
sys: {
|
|
28
29
|
id: string;
|
|
29
30
|
archivedVersion?: number;
|
|
@@ -49,7 +50,12 @@ export type TagT = {
|
|
|
49
50
|
id: string;
|
|
50
51
|
};
|
|
51
52
|
};
|
|
52
|
-
export type LocaleT =
|
|
53
|
+
export type LocaleT = {
|
|
54
|
+
code: string;
|
|
55
|
+
name: string;
|
|
56
|
+
default: boolean;
|
|
57
|
+
fallbackCode: string | null;
|
|
58
|
+
};
|
|
53
59
|
export type ContentTypeT = {
|
|
54
60
|
sys: {
|
|
55
61
|
id: string;
|
|
@@ -66,30 +72,34 @@ export type ContentTypeT = {
|
|
|
66
72
|
};
|
|
67
73
|
}>;
|
|
68
74
|
};
|
|
75
|
+
export type GetLocalesResponseT = {
|
|
76
|
+
skip: number;
|
|
77
|
+
limit: number;
|
|
78
|
+
total: number;
|
|
79
|
+
items: Array<LocaleT>;
|
|
80
|
+
};
|
|
81
|
+
export type GetContentTypesResponseT = {
|
|
82
|
+
skip: number;
|
|
83
|
+
limit: number;
|
|
84
|
+
total: number;
|
|
85
|
+
items: Array<ContentTypeT>;
|
|
86
|
+
};
|
|
87
|
+
export type GetTagsResponseT = {
|
|
88
|
+
skip: number;
|
|
89
|
+
limit: number;
|
|
90
|
+
total: number;
|
|
91
|
+
items: Array<TagT>;
|
|
92
|
+
};
|
|
93
|
+
export type GetEntriesResponseT = {
|
|
94
|
+
skip: number;
|
|
95
|
+
limit: number;
|
|
96
|
+
total: number;
|
|
97
|
+
items: Array<EntryT>;
|
|
98
|
+
};
|
|
69
99
|
export type ContentfulClientT = {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
items: Array<EntryT>;
|
|
75
|
-
}>;
|
|
76
|
-
getLocales: () => Promise<{
|
|
77
|
-
skip: number;
|
|
78
|
-
limit: number;
|
|
79
|
-
total: number;
|
|
80
|
-
items: Array<LocaleT>;
|
|
81
|
-
}>;
|
|
82
|
-
getContentTypes: (query?: ContentTypesQueryT) => Promise<{
|
|
83
|
-
skip: number;
|
|
84
|
-
limit: number;
|
|
85
|
-
total: number;
|
|
86
|
-
items: Array<ContentTypeT>;
|
|
87
|
-
}>;
|
|
88
|
-
getTags: (query?: TagsQueryT) => Promise<{
|
|
89
|
-
skip: number;
|
|
90
|
-
limit: number;
|
|
91
|
-
total: number;
|
|
92
|
-
items: Array<TagT>;
|
|
93
|
-
}>;
|
|
100
|
+
getLocales: () => Promise<GetLocalesResponseT>;
|
|
101
|
+
getContentTypes: (query?: ContentTypesQueryT) => Promise<GetContentTypesResponseT>;
|
|
102
|
+
getTags: (query?: TagsQueryT) => Promise<GetTagsResponseT>;
|
|
103
|
+
getEntries: (query?: EntriesQueryT) => Promise<GetEntriesResponseT>;
|
|
94
104
|
};
|
|
95
105
|
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import { ArboretumClientConfigT } from "../../../arboretum-client";
|
|
1
|
+
import { ArboretumClientConfigT, CreateClientParams } from "../../../arboretum-client";
|
|
2
2
|
import { ContentfulClientT } from "../contentful-client";
|
|
3
3
|
export declare const createContentfulClient: (config: ArboretumClientConfigT) => ContentfulClientT;
|
|
4
|
+
export declare const createCdaRestApiContentfulClient: (config: CreateClientParams) => ContentfulClientT;
|
|
@@ -76,7 +76,7 @@ export type PagesByTagIdT = Map<LocaleCodeT, PagesByTagIdV>;
|
|
|
76
76
|
export type CachedDataT = Pick<ArboretumClientCtx, "data" | "pagesByTagId" | "sitemap">;
|
|
77
77
|
export type ArboretumClientCtx = {
|
|
78
78
|
preview: boolean;
|
|
79
|
-
contentfulClientType: ArboretumClientConfigT["type"];
|
|
79
|
+
contentfulClientType: ArboretumClientConfigT["type"] | "cda-client-with-all-locales";
|
|
80
80
|
lastUpdatedAt: string;
|
|
81
81
|
clientApi: ContentfulClientT;
|
|
82
82
|
cmaPreviewClientApi?: ContentfulClientT;
|
|
@@ -3,4 +3,4 @@ import { ArboretumClientCtx, SysIdT } from "../../arboretum-client.impl";
|
|
|
3
3
|
export type PagesT = {
|
|
4
4
|
[sys: SysIdT]: EntryT;
|
|
5
5
|
};
|
|
6
|
-
export declare const getAllEntriesRecursively: ({ getEntries }: Pick<ArboretumClientCtx["clientApi"], "getEntries">, contentType: string, skip: number, acc: Array<EntryT>, select?: string, refFieldsToFilterOut?: Array<string>, limit?: number) => Promise<Array<EntryT>>;
|
|
6
|
+
export declare const getAllEntriesRecursively: ({ getEntries }: Pick<ArboretumClientCtx["clientApi"], "getEntries">, contentfulClientType: ArboretumClientCtx["contentfulClientType"], contentType: string, skip: number, acc: Array<EntryT>, select?: string, refFieldsToFilterOut?: Array<string>, limit?: number) => Promise<Array<EntryT>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getRandomNumber(min: number, max: number): number;
|
package/package.json
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bright.global/arboretum-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "The sitemap for contentful",
|
|
6
|
-
"dependencies": {
|
|
7
|
-
"contentful": "^9.2.5",
|
|
8
|
-
"contentful-management": "10.29.1"
|
|
9
|
-
},
|
|
6
|
+
"dependencies": {},
|
|
10
7
|
"sideEffects": false,
|
|
11
8
|
"devDependencies": {
|
|
12
9
|
"@babel/preset-env": "^7.22.6",
|