@bright.global/arboretum-sdk 0.1.0-rc.6 → 0.1.0-rc.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.
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
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;
3
+ exports.DEFAULT_RETRY_LIMIT = exports.DEFAULT_RETRY_ON_ERROR = exports.DEFAULT_TIMEOUT = exports.DEFAULT_ENVIRONMENT = void 0;
4
4
  exports.DEFAULT_ENVIRONMENT = "master";
5
- exports.DEFAULT_HOST = "cdn.contentful.com";
6
5
  exports.DEFAULT_TIMEOUT = 30000;
7
6
  exports.DEFAULT_RETRY_ON_ERROR = true;
8
7
  exports.DEFAULT_RETRY_LIMIT = 5;
@@ -12,11 +12,12 @@ var __assign = (this && this.__assign) || function () {
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.createCdaRestApiContentfulClient = exports.createContentfulClient = void 0;
15
- var get_locales_1 = require("./methods/get-locales");
16
15
  var get_content_types_1 = require("./methods/get-content-types");
17
- var get_tags_1 = require("./methods/get-tags");
18
16
  var get_entries_1 = require("./methods/get-entries");
17
+ var get_locales_1 = require("./methods/get-locales");
18
+ var get_tags_1 = require("./methods/get-tags");
19
19
  var createContentfulClient = function (config) {
20
+ var _a, _b, _c, _d;
20
21
  var configType = config.type;
21
22
  switch (config.type) {
22
23
  case "cda-client": {
@@ -30,10 +31,10 @@ var createContentfulClient = function (config) {
30
31
  };
31
32
  }
32
33
  case "cda-client-params": {
33
- var previewHostOrUndefined = config.preview
34
- ? "preview.contentful.com"
35
- : undefined;
36
- return (0, exports.createCdaRestApiContentfulClient)(__assign(__assign({}, config.contentful), { host: previewHostOrUndefined }));
34
+ var PREVIEW_HOST = (_b = (_a = config.hosts) === null || _a === void 0 ? void 0 : _a.preview) !== null && _b !== void 0 ? _b : "preview.contentful.com";
35
+ var PUBLISHED_HOST = (_d = (_c = config.hosts) === null || _c === void 0 ? void 0 : _c.published) !== null && _d !== void 0 ? _d : "cdn.contentful.com";
36
+ var host = config.preview ? PREVIEW_HOST : PUBLISHED_HOST;
37
+ return (0, exports.createCdaRestApiContentfulClient)(__assign(__assign({}, config.contentful), { host: host }));
37
38
  }
38
39
  case "cma-client": {
39
40
  var client_1 = config.contentful.client;
@@ -97,8 +97,7 @@ var contentfulFetchWithRetires = function (p, retryLimit, retry) {
97
97
  };
98
98
  var contentfulFetch = function (config) {
99
99
  return function (endpoint, query) {
100
- var space = config.space, accessToken = config.accessToken;
101
- var host = config.host || constants_1.DEFAULT_HOST;
100
+ var space = config.space, accessToken = config.accessToken, host = config.host;
102
101
  var environment = config.environment || constants_1.DEFAULT_ENVIRONMENT;
103
102
  var params = new URLSearchParams();
104
103
  params.append("access_token", accessToken);
@@ -1,5 +1,4 @@
1
1
  export var DEFAULT_ENVIRONMENT = "master";
2
- export var DEFAULT_HOST = "cdn.contentful.com";
3
2
  export var DEFAULT_TIMEOUT = 30000;
4
3
  export var DEFAULT_RETRY_ON_ERROR = true;
5
4
  export var DEFAULT_RETRY_LIMIT = 5;
@@ -9,11 +9,12 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
- import { getLocales } from "./methods/get-locales";
13
12
  import { getContentTypes } from "./methods/get-content-types";
14
- import { getTags } from "./methods/get-tags";
15
13
  import { getEntries } from "./methods/get-entries";
14
+ import { getLocales } from "./methods/get-locales";
15
+ import { getTags } from "./methods/get-tags";
16
16
  export var createContentfulClient = function (config) {
17
+ var _a, _b, _c, _d;
17
18
  var configType = config.type;
18
19
  switch (config.type) {
19
20
  case "cda-client": {
@@ -27,10 +28,10 @@ export var createContentfulClient = function (config) {
27
28
  };
28
29
  }
29
30
  case "cda-client-params": {
30
- var previewHostOrUndefined = config.preview
31
- ? "preview.contentful.com"
32
- : undefined;
33
- return createCdaRestApiContentfulClient(__assign(__assign({}, config.contentful), { host: previewHostOrUndefined }));
31
+ var PREVIEW_HOST = (_b = (_a = config.hosts) === null || _a === void 0 ? void 0 : _a.preview) !== null && _b !== void 0 ? _b : "preview.contentful.com";
32
+ var PUBLISHED_HOST = (_d = (_c = config.hosts) === null || _c === void 0 ? void 0 : _c.published) !== null && _d !== void 0 ? _d : "cdn.contentful.com";
33
+ var host = config.preview ? PREVIEW_HOST : PUBLISHED_HOST;
34
+ return createCdaRestApiContentfulClient(__assign(__assign({}, config.contentful), { host: host }));
34
35
  }
35
36
  case "cma-client": {
36
37
  var client_1 = config.contentful.client;
@@ -51,7 +51,7 @@ var __read = (this && this.__read) || function (o, n) {
51
51
  return ar;
52
52
  };
53
53
  import { getRandomNumber } from "../../../../utils/get-rendom-number";
54
- import { DEFAULT_ENVIRONMENT, DEFAULT_HOST, DEFAULT_RETRY_LIMIT, DEFAULT_RETRY_ON_ERROR, } from "../constants";
54
+ import { DEFAULT_ENVIRONMENT, DEFAULT_RETRY_LIMIT, DEFAULT_RETRY_ON_ERROR, } from "../constants";
55
55
  var sleep = function (ms) { return new Promise(function (r) { return setTimeout(r, ms); }); };
56
56
  var getRetryDelay = function (retry) {
57
57
  return Math.ceil(Math.pow(getRandomNumber(1.2, 1.4), retry) * 1000);
@@ -94,8 +94,7 @@ var contentfulFetchWithRetires = function (p, retryLimit, retry) {
94
94
  };
95
95
  export var contentfulFetch = function (config) {
96
96
  return function (endpoint, query) {
97
- var space = config.space, accessToken = config.accessToken;
98
- var host = config.host || DEFAULT_HOST;
97
+ var space = config.space, accessToken = config.accessToken, host = config.host;
99
98
  var environment = config.environment || DEFAULT_ENVIRONMENT;
100
99
  var params = new URLSearchParams();
101
100
  params.append("access_token", accessToken);
@@ -12,7 +12,7 @@ export var redirectEntryAdapter = function (data, pageField, pathField, typeFiel
12
12
  return pageSysId && path && (type === "redirect" || type === "alias")
13
13
  ? {
14
14
  page: { sys: { id: pageSysId } },
15
- path: parent.path + path,
15
+ path: parent.path + (path.startsWith("/") ? path : "/".concat(path)),
16
16
  title: title || undefined,
17
17
  metadata: entry.metadata,
18
18
  type: type,
@@ -15,7 +15,7 @@ var redirectEntryAdapter = function (data, pageField, pathField, typeField, titl
15
15
  return pageSysId && path && (type === "redirect" || type === "alias")
16
16
  ? {
17
17
  page: { sys: { id: pageSysId } },
18
- path: parent.path + path,
18
+ path: parent.path + (path.startsWith("/") ? path : "/".concat(path)),
19
19
  title: title || undefined,
20
20
  metadata: entry.metadata,
21
21
  type: type,
@@ -1,6 +1,6 @@
1
+ import { ContentTypeT, EntryT, LocaleT, StatusT, TagT } from "./clients/contentful-client/contentful-client";
1
2
  import { CachedDataT, MetadataT, SysIdT } from "./impl/arboretum-client.impl";
2
3
  import { Either } from "./utils/fp-utils";
3
- import { ContentTypeT, EntryT, LocaleT, StatusT, TagT } from "./clients/contentful-client/contentful-client";
4
4
  export type ArboretumClientOptions = {
5
5
  data?: CachedDataT;
6
6
  eagerly?: boolean;
@@ -68,7 +68,7 @@ export type CreateClientParams = {
68
68
  space: string;
69
69
  accessToken: string;
70
70
  environment?: string;
71
- host?: string;
71
+ host: string;
72
72
  retryOnError?: boolean;
73
73
  timeout?: number;
74
74
  retryLimit?: number;
@@ -79,6 +79,10 @@ export type ArboretumClientConfigFromCdaParamsT = {
79
79
  contentful: Omit<CreateClientParams, "host"> & {
80
80
  options: ArboretumClientContentfulConfigOptionsT;
81
81
  };
82
+ hosts?: {
83
+ preview: string;
84
+ published: string;
85
+ } | undefined;
82
86
  options?: Pick<ArboretumClientOptions, "data" | "eagerly" | "pageRelations">;
83
87
  };
84
88
  export type ArboretumClientConfigT = ArboretumClientConfigFromCmaT | ArboretumClientConfigFromCdaT | ArboretumClientConfigFromCdaParamsT;
@@ -1,5 +1,4 @@
1
1
  export declare const DEFAULT_ENVIRONMENT = "master";
2
- export declare const DEFAULT_HOST = "cdn.contentful.com";
3
2
  export declare const DEFAULT_TIMEOUT = 30000;
4
3
  export declare const DEFAULT_RETRY_ON_ERROR: boolean;
5
4
  export declare const DEFAULT_RETRY_LIMIT = 5;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bright.global/arboretum-sdk",
3
- "version": "0.1.0-rc.6",
3
+ "version": "0.1.0-rc.8",
4
4
  "license": "MIT",
5
5
  "description": "The sitemap for contentful",
6
6
  "dependencies": {},